The ancient sowing game on a carved wooden board, played by minimax with alpha-beta.
Two AIs play Mancala by the Kalah rules: scoop a pit, sow the seeds counterclockwise, move again if the last one lands in your store, capture when it lands in an empty pit of your own. Each move is chosen by minimax with alpha-beta pruning and iterative deepening, written as plain minimax rather than negamax because extra turns let the same side move twice, and free moves do not use up depth. The bars beside the pits show what the search currently thinks of each move, and the beam below shows who it thinks is ahead. The board is a height field (a bevelled plank with bowls carved in) lit per pixel over procedural wood grain and built a few rows per frame, and the seeds are glass and stone sprites that ride a hopping hand from pit to pit, drop, bounce and settle under position-based physics.
Try it. Click one of your pits on the near row (or press 1 to 6) to take over the bottom side; on your turn the bars are the AI's opinion of your options. Choose a search depth from 2 to 12 (or + and -), and use the Play or Watch button (W) to switch modes. N starts a new game.
Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.
Build a Mancala game (Kalah rules) where I play against a minimax AI, with JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.
Start simple:
- Model the board as an array of 14 numbers: six pits for each player and one store each, four seeds in every pit to start. A move picks up all seeds in one of your pits and sows them one by one counterclockwise, skipping the opponent's store.
- Implement the rules: if the last seed lands in your store you move again; if it lands in an empty pit on your side, capture it and the seeds opposite; when one side is empty, the other side's seeds go to their owner's store and the bigger store wins.
- Draw circles for pits, dots for seeds and a count beside each pit. I click my pits on the bottom row to play.
- Write minimax with alpha-beta pruning for the top player, scored by the store difference, searching 6 plies. Because of extra turns, track whose turn it is explicitly instead of flipping sides every ply.
Once that works, make it beautiful:
- Paint a wooden board: generate a wood grain texture with a small noise function (stretched rings bent by noise), and shade the pits as carved bowls with a highlight on the lit rim.
- Draw the seeds as glossy glass beads in several colors with a radial gradient and a white highlight, and animate sowing: the seeds hop from pit to pit and settle with a little bounce.
- Show bars beside each pit with the search's score for that move, and let me pick the search depth.
Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as iterative deepening that runs a slice per frame, soft physics so seeds jostle inside each pit, or an AI versus AI mode at different depths.