Skip to content

RAILGUN1124/chess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

♟️ Engine Overview

This Python-based chess AI engine implements an advanced move evaluation system using a combination of traditional techniques and optimization heuristics such as Zobrist hashing, transposition tables, aspiration windows, Late Move Reductions, and Quiescence Search. Below is a breakdown of its main components:

🔢 Evaluation Components

  • pieceScore: Defines base material values for each piece.

  • Positional Score Tables (knightScores, bishopScores, etc.): Provide bonuses/penalties based on piece positions to guide piece activity and board control.

  • piecePositionScores: Maps piece types to their respective position tables.

♻️ Zobrist Hashing & Transposition Table

  • ZOBRIST_TABLE: Generates unique 64-bit hashes for board positions to enable fast position recognition.

  • initializeZobrist(): Initializes the hash keys for all piece-square combinations and the current side to move.

  • computeZobristHash(board, whiteToMove): Produces the Zobrist hash for a given board state.

  • transpositionTable / TTEntry: Caches previously evaluated positions to avoid redundant computation and improve search speed.

🧠 Search Algorithms

  • findBestMove(): Entry point for finding the optimal move using iterative deepening and aspiration windows to efficiently narrow the alpha-beta bounds.

  • findMoveNegaScout(): Core NegaScout/PVS (Principal Variation Search) algorithm enhanced with:

    • Late Move Reduction (LMR)

    • Move ordering

    • History heuristic

    • Transposition table lookup and storage

  • quiescenceSearch(): Prevents horizon effects by extending the search only through capture sequences.

  • see() (Static Exchange Evaluation): Fast estimation of capture profitability without full search.

📋 Move Ordering

  • orderMoves(): Scores moves based on captures, promotions, and historical success to guide search toward promising branches early.

  • orderMovesWithBestFirst(): Keeps previously best move at the front for more stable iterative deepening.

📈 Evaluation Function

  • evaluateBoard(): Combines material, positional, structural, and strategic factors:

    • Material balance

    • Positional tables

    • King safety

    • Pawn structure (isolated, doubled, passed pawns)

    • Promotion threats

    • Open files for rooks

    • Bishop pair bonus

  • Supporting functions:

    • evaluateKingSafety(gs, color)

    • evaluatePawnStructure(gs, color)

    • evaluatePromotionThreats(gs)

📦 Utilities

  • findRandomMoves(validMoves): Picks a random legal move (used as fallback or for testing).

  • canAttackSquare(): Checks if a piece can attack a target square (partial legality check).

  • isClearDiagonal() / isClearStraight(): Check if a piece’s path to a target square is clear.

🧪 Customization & Parameters

  • DEPTH: Controls the depth of the main search (default: 5)

  • CHECKMATE, STALEMATE: Constants used in scoring terminal game states.

  • QUIESCENCE_DEPTH_LIMIT: Limit for depth extension during quiescence search.

🚀 Highlights

  • Iterative Deepening for better time control and progressive deepening.

  • Aspiration Windows for focused alpha-beta pruning.

  • Zobrist Hashing enables fast state comparison.

  • Static Exchange Evaluation (SEE) for smarter capture pruning.

  • Quiescence Search for tactical stability near leaf nodes.

  • Heuristics like history tables, position scoring, and pawn structure to emulate human evaluation principles.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages