gomoku is a high-performance Gomoku (Five in a Row) AI bot developed in Rust. It is designed to comply with the Piskvork protocol and competes in the Gomocup tournaments. The bot focuses on efficiency, robust defensive play, and strategic move searching to outsmart opponents.
- Language: Written in pure Rust for performance and memory safety.
- Protocol: Fully compliant with the Piskvork protocol (supports
START,TURN,BEGIN,BOARD,INFO,ABOUT,END). - AI Core:
- Negamax with Alpha-Beta Pruning: Efficiently explores the game tree to find optimal moves.
- Iterative Deepening: Progressively searches deeper (up to 12 plies) within the time limit.
- Transposition Table: Uses Zobrist Hashing to cache board states and avoid re-evaluating identical positions (50MB cache size).
- Move Ordering: Prioritizes promising moves (heuristic scoring) to maximize alpha-beta cutoffs.
- Evaluation Function:
- Pattern-based evaluation detecting "Five in a Row", "Open Four", "Open Three", etc.
- Strong defensive heuristic (threats are weighted 3x compared to offensive potential) to block opponents effectively.
- Rust (latest stable version recommended)
- Make (optional, for convenience)
You can build the project using the provided Makefile or directly with cargo.
Using Make:
makeThis generates the pbrain-gomoku-ai executable in the root directory.
Using Cargo:
cargo build --release
cp target/release/pbrain-gomoku-ai .make clean # Removes the binary
make fclean # Removes the binary and target directoryThe bot is designed to run as a subprocess of a Gomoku manager (like Piskvork). It communicates via standard input/output.
Basic Commands:
START [size]: Initialize the board (e.g.,START 20). ReturnsOKorERRORif size < 5.BEGIN: Bot plays the first move (black).TURN [x],[y]: Opponent plays at (x,y), bot responds with its move coordinates.BOARD: Load a custom board state.INFO [key] [value]: Update game settings (e.g.,timeout_turn).END: Terminate the program.
The core of the AI is a Negamax algorithm enhanced with Alpha-Beta Pruning.
- Iterative Deepening ensures that the bot always has a "best move" ready if it runs out of time. It starts searching at depth 1 and increases depth incrementally.
- A time management system interrupts the search if the allocated time per turn (
timeout_turn, default ~4.7s) is nearly exhausted.
The board is evaluated based on stone patterns. We check 5-stone windows across all directions (horizontal, vertical, diagonal).
- Scores:
- Win (5 consecutive): 1,000,000
- Open Four: 100,000
- Open Three: 10,000
- Defensive Bias: The AI applies a
x3multiplier penalty for opponent threats. This makes the bot "paranoid" and very reactive to blocking winning lines.
- Zobrist Hashing: A checksum of the board is updated incrementally. This hash is used as a key for the Transposition Table.
- Transposition Table (TT): Stores evaluation results of previously visited positions. If a position is reached again (even via a different move order), the stored result is reused, vastly speeding up the search.
- Move Sorting: Before searching, legal moves are scored using a lightweight heuristic and sorted. Searching the best moves first allows Alpha-Beta pruning to cut off large branches of the tree early.
To test this AI against other programs or human players, you can use a Piskvork-compatible manager like Piskvork (Windows) or Liskvork (Linux/Mac).
Example with Liskvork:
- Download Liskvork.
- Run the match command:
./liskvork \
--player1 ./pbrain-gomoku-ai \
--player2 path/to/opponent \
-s 20 -m 5000 -r match_log.txt-s 20: Board size 20x20.-m 5000: Time limit (5 seconds/move).-r: Save replay to a file.