Skip to content

Kaushikj-7/ChessEngine

Repository files navigation

Ethreal Chess Engine

A sophisticated chess engine written in C++ using Bitboards.

Features

Core Architecture

  • Board Representation: Bitboard-based representation (Little-Endian Rank-File Mapping).
  • Move Generation: Strictly legal move generator.
    • Specialized logic for Pins, Checks, and Check Evasions.
    • Full support for Castling and En Passant with safety verification.
    • Pre-calculated Ray and Attack tables (rays.cpp, attacks.cpp).

Search & Evaluation

  • Search Algorithm: Alpha-Beta Pruning with Move Ordering.
    • Move Ordering: MVV-LVA (Most Valuable Victim - Least Valuable Aggressor), Killer Heuristic, History Heuristic.
    • Quiescence Search: Solves horizon effects by extending search for non-quiet positions (captures).
  • Evaluation:
    • Piece-Square Tables (PST) for positional scoring.
    • Material imbalance calculation.

Interface

  • UCI Protocol: Fully compliant Universal Chess Interface (UCI).
    • Supports position, go, isready, uci, quit commands.
    • Compatible with standard GUIs (Arena, Fritz, Banksia, Lichess).

Building the Project

Using g++

g++ -std=c++17 main.cpp uci.cpp board.cpp move.cpp movegen.cpp search.cpp eval.cpp attacks.cpp rays.cpp -o chess.exe

Using CMake

mkdir build
cd build
cmake ..
make

Running

The engine runs in UCI mode by default.

On Windows:

.\chess.exe

Engineering Metrics & Benchmarks

Algorithmic Ablation Study (Depth 8)

Metric v2.0 (Alpha-Beta) v3.0 Exp (PVS + TT) Delta
Total Nodes 3,807,160 2,521,056 -33.8%
Time to Depth 14.81s 8.93s -39.7%
NPS (Throughput) 257,146 282,403 +9.8%
Branching Factor ~6.62 ~6.31 Superior Efficiency

Performance Analysis

  • Search Efficiency: The integration of Principal Variation Search (PVS) significantly reduced the effective branching factor by searching the first move with a full window and subsequent moves with a null window.
  • Cache Locality: The Transposition Table (Zobrist Hashing) provided a ~10% NPS boost by avoiding redundant evaluations of transposed positions, confirming that the hash table alignment is optimized for modern CPU L1/L2 caches.
  • Node Reduction: The 34% reduction in nodes proves that move ordering (aided by TT best-moves) is functioning correctly, allowing for deeper searches in the same time-slice.

File Structure

  • main.cpp: Entry point (connects UCI to Engine).
  • uci.cpp: UCI protocol loop and command parsing.
  • board.cpp: Bitboards, state tracking (castle rights, ep), make/unmake.
  • movegen.cpp: Legal move generation (Checks, Pins, Evasions).
  • search.cpp: Alpha-Beta, Ordering, Quiescence.
  • eval.cpp: Piece-Square Table evaluation.
  • attacks.cpp: Pre-calculated sliding attack tables (Magic-style logic).
  • rays.cpp: Pre-calculated directional rays.

Version

Version 2.0

Roadmap for v3.0

  • Transposition Tables (Zobrist Hashing)
  • Iterative Deepening & Time Management
  • Principal Variation Search (PVS)
  • Late Move Reduction (LMR)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors