Inspiration
Game night already happens in front of the TV, but most TV games treat the computer opponent as a black box. I wanted a family game where the AI shows its reasoning, so kids and adults can see why a move is good instead of just losing to it.
What it does
Connect Four AI is a Fire TV game played entirely with the remote. While the AI thinks, a bar above each column shows its live estimated chance of winning there, and you can watch it change its mind as the search runs. After every move it comments in plain words ("I played column 3. I give myself 48%."), and a Who's ahead bar shows which side the position favors. A Hint button runs the same search for you and points to your best column.
- 1 player against the AI (Easy, Medium, Hard, or Adaptive, which gets stronger when you win and easier when you lose) or 2 players on one remote
- The first move swaps after each finished game, and the score carries across games
- Everything works with the D-pad and Select: Down opens a button row for hint, difficulty, players and new game
How I built it
- Engine: pure Java with no dependencies. The board is stored as two 64-bit bitboards, so dropping a disc is one addition and checking four in a row is about a dozen bit operations. The AI is Monte Carlo tree search (UCT): it plays out thousands of random games from each candidate move and favors the ones that win, while always taking an immediate win or blocking an immediate threat. It runs about 1 million simulated games per second on a laptop.
- Built for a TV stick: the search runs on a background thread, is capped at 400,000 tree nodes (about 36 MB), and can be cancelled within 100 ms. It records about 18 snapshots of its own progress, which the screen replays as the moving bars, so you can watch the AI think even when the search itself takes only milliseconds.
- App: a native Fire OS (Android) app with no libraries. The whole screen is drawn on a Canvas: a toy-blue board with real holes, plastic-shaded discs that fall behind the frame with a small bounce, and the Fredoka typeface.
- Testing: a 37-test suite runs on every change. It replays 3,000 random games move by move against a deliberately simple reference board to prove the bitboard logic is correct, and checks tactics, timing, cancellation, speed and playing strength: the AI beats a random player 20 of 20 games, and the high-budget search beats the low-budget one 18 of 20.
- Process: I developed it with AI coding agents in a self-correcting loop: a script runs the tests, hands failures to a fixer agent, and sends passing code to an independent reviewer agent that checks for bugs and test-gaming. The tests are checksummed so the agents can't edit them.
Challenges
I don't own a Fire TV device, and the Vega simulator needs macOS or Ubuntu while I develop on Windows. So I targeted Fire OS and tested on the Android TV emulator, which the hackathon FAQ allows. Making the AI fast and memory-safe enough for a streaming stick shaped the whole engine design. The search also turned out to be so fast that the thinking bars never had time to appear, which led to the snapshot-replay design.
Accomplishments
An AI whose thinking is visible and understandable on a TV, and an engine with test coverage strong enough that I trust it.
What I learned
Bitboard game representations, Monte Carlo tree search, designing a 10-foot UI for a remote with five buttons, and how to run AI coding agents against tests they can't change.
What's next
Alexa voice commands ("Alexa, drop in column four"), online play between two Fire TVs, and a teaching mode that replays a finished game and shows where it was won or lost.
Built With
- android
- android-studio
- bitboards
- fire-os
- gradle
- java
- monte-carlo-tree-search
Log in or sign up for Devpost to join the conversation.