Skip to content
NerzouillePublic

About

Gomoku AI bot developed in Rust

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

gomoku

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.

Features

  • 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.

Build & Installation

Prerequisites

  • Rust (latest stable version recommended)
  • Make (optional, for convenience)

Compiling

You can build the project using the provided Makefile or directly with cargo.

Using Make:

make

This generates the pbrain-gomoku-ai executable in the root directory.

Using Cargo:

cargo build --release
cp target/release/pbrain-gomoku-ai .

Cleaning

make clean    # Removes the binary
make fclean   # Removes the binary and target directory

Usage

The 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). Returns OK or ERROR if 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.

Strategy & Algorithms

1. Search Engine

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.

2. Evaluation

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 x3 multiplier penalty for opponent threats. This makes the bot "paranoid" and very reactive to blocking winning lines.

3. Optimizations

  • 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.

Testing

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:

  1. Download Liskvork.
  2. 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.

About

Gomoku AI bot developed in Rust

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages