Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
Xiangiqgame

intro figure

Overview

This project consists of a C++ Artificial Intelligence (AI) engine and a Python outer layer for the board game Xiangqi (also known as Chinese chess) and supports playing games in AI vs. AI, AI vs. Human, and Human vs. Human modes.

Core Algorithm

The AI utilizes the Minimax algorithm enhanced by Alpha-Beta pruning to select moves. A transposition table based on Zobrist hashing is implemented for storage / retrieval of board state evaulation results and prevents re-calculation of previously seen board states.

Architecture

The AI engine is designed around a plug-in architecture, enabling easy integration and swapping of components without affecting the core functionality. Major components are isolated from each other by interface classes that employ the Curiously Recurring Template Pattern (CRTP). This approach allows for compile time polymorphism and avoids the runtime overhead associated with more traditional virtual class interfaces.

Integration with Python

The C++ core is integrated with an outer Python layer using pybind11. The Python layer:

  • Provides a command-line interface (CLI) for running games and setting engine parameters.
  • Displays a text-based game board.
  • Saves detailed data generated by the core engine during move selection.
  • Uses scikit-build-core to connect the C++ CMake build system to pip, facilitating installation as a standard Python package.

Engine Settings and Data Collection

This project prioritizes the ability to explore inner-workings of the AI engine with flexible engine settings and in-game data collection.

AI engine parameters that can be modified via the command line interface:

  • Minimax search depth
  • Bit size of keys used for Zobrist hashing
  • Number of "backup" or "confirmation" states held in the transposition table (to detect hash collisions)

Data collected each time an AI player selectes a move include:

  • Total search time
  • Number of nodes explored in the game tree
  • Minimax algorithm termination mode at each node
  • Number of transposition table hash collisions
  • Minimax evaluation score of the selectedmove
Previous Next
Installing