MiniChessAI is an artificial intelligence agent designed to play MiniChess (6x5 board). The AI’s strength and play style are determined by its evaluation criteria and implementation choices. This report details the evaluation metrics used to assess board positions, the algorithms powering the AI, and other relevant implementation details.
The AI evaluates each board state using a weighted sum of several chess-specific features. The main criteria are:
- Definition: The total value of all pieces for both sides.
- Implementation: Each piece type is assigned a standard value (Pawn: 1, Knight/Bishop: 3, Rook: 5, Queen: 9, King: very high value to prevent loss).
- Purpose: Encourages the AI to capture opponent pieces and avoid losing its own.
- Definition: The number of legal moves available to each side.
- Implementation: The AI counts all possible moves for its pieces and subtracts the opponent’s mobility.
- Purpose: Favors positions where the AI has more options and flexibility.
- Definition: The arrangement and support of pawns.
- Implementation: Penalties for doubled, isolated, or backward pawns; bonuses for connected and advanced pawns.
- Purpose: Promotes strong, cohesive pawn formations and discourages weaknesses.
- Definition: The vulnerability of the king to attack.
- Implementation: Penalties if the king is exposed (few surrounding pawns/pieces) or under direct threat.
- Purpose: Encourages castling and keeping the king protected.
- Definition: Occupation and influence over central squares.
- Implementation: Bonuses for pieces controlling or occupying the central 2x2 or 3x3 area.
- Purpose: Central control increases piece effectiveness and flexibility.
- Definition: Immediate threats such as checks, forks, pins, and discovered attacks.
- Implementation: Small bonuses for giving check, attacking high-value pieces, or creating tactical threats.
- Purpose: Encourages the AI to create and exploit tactical opportunities.
- Checkmate: Returns a large positive/negative value depending on the winner.
- Stalemate: Returns zero, indicating a draw.
- Draw by Insufficient Material or Repetition: Returns zero.
- Minimax with Alpha-Beta Pruning: The AI simulates possible move sequences for both sides up to a fixed depth, using alpha-beta pruning to skip unpromising branches and improve efficiency.
- Iterative Deepening: The AI increases search depth incrementally, allowing it to return the best move found within a time limit.
- Move Ordering: Captures, checks, and threats are searched first to maximize pruning effectiveness.
- The evaluation function is called at each leaf node of the search tree and combines all criteria above into a single score.
- Weights for each criterion are tuned through testing and self-play.
- Transposition Table: Caches previously evaluated positions to avoid redundant calculations.
- Move Generation: Efficient move generation routines minimize computation time.
- Backend: Python (FastAPI) handles game logic, move validation, and AI computation.
- Frontend: Next.js (React) provides an interactive chessboard and user controls.
- Game Modes: Supports Human vs AI, AI vs AI, and Human vs Human.
- The AI is tested against known MiniChess puzzles and through self-play to ensure it makes reasonable decisions and avoids blunders.
- Unit tests cover move generation, evaluation, and endgame detection.
MiniChessAI combines classic chess AI techniques with optimizations for the 6x5 board. Its evaluation function balances material, mobility, king safety, pawn structure, and tactical awareness, resulting in a challenging and adaptable opponent. The implementation is modular, efficient, and supports multiple play modes for both casual and competitive use.