All projects

AI · Game theory

Gomoku AI

AI · Game theory

Gomoku AI

Gomoku (five in a row) AI in Python: Minimax with Alpha-Beta pruning and a custom heuristic, under 5 seconds and 70 MB per move.

Gomoku, or five in a row, looks simple: two players take turns on a 20x20 board and the first to align five stones wins. For a computer it is hard, because the number of possible moves explodes after only a few turns. I built this Gomoku bot alone for Epitech's AI module. The bot searches ahead with the Minimax algorithm: it imagines its own moves and the opponent's best replies, several turns deep, and picks the move that leaves it in the best position. Exploring every branch would be far too slow, so I implemented Alpha-Beta pruning, which skips whole branches as soon as it is clear they cannot change the decision. The same search then goes much deeper in the same time. When the search stops, a custom heuristic evaluation function scores the board: open and closed lines, threats of four and five, and the opponent's dangers. Most of the bot's strength comes from this function, and most of my time went into tuning it. The rules were strict: the bot talks to the game manager through the Piskvork protocol, must answer within 5 seconds per move and stay under 70 MB of memory. Every optimisation had to respect both limits. The bot took part in the optional Brawl tournament, where bots play each other and are ranked with an Elo system. This project taught me game theory, search algorithms and how to trade depth against time under hard constraints.

Built with

PythonAlpha-Beta PruningMinimax AlgorithmHeuristic EvaluationPiskvork ProtocolGame Theory
See the other projects