/ projects · 05
Connect 4 — beat my bot
Built as a break between dissertation chapters. Then the bot got minimax, and the breaks got longer. It looks five moves ahead. Win a game and coffee's on me. Seriously, email me a screenshot.
How the bot thinks
Classic minimax with alpha-beta pruning, searching five plies deep with centre-first move ordering (centre columns win more board games and prune more branches). At the leaves, a heuristic scores every four-cell window on the board: three-in-a-row with an open end is good, letting you have three-in-a-row is much worse, and holding the centre column earns a steady bonus. There's no opening book and no lookup table, just about 200 lines of vanilla JavaScript.
Five plies is deliberately beatable. It plays sharp tactics (it will never miss a win or hang one) but it can't see deep traps coming. Set one up.
Origins
The first version (win detection, drop animations, a last-move ring) shipped as a standalone page and still lives on Vercel. This embedded version adds the bot, the win-line highlight, and a board that fits anywhere on the site (it also guards the 404 page →).