Overview
Chess-bot is a chess engine built entirely from scratch in Python. It implements bitboard-based board representation, legal move generation, alpha-beta search with a transposition table, and a classical evaluator with tapered piece-square tables. It also includes an optional trained value network (a PyTorch MLP) that can replace the classical evaluator at search time, trained through self-play.
Architecture
The codebase is organized into four modules:
- gameCore/ — The rules engine. Bitboard representation, precomputed attack tables (magic-free sliding attacks), legal move generation, position state, and a minimal CLI for sanity-checking
- gameEngine/ — Search and evaluation. Zobrist hashing (compute and incremental update), transposition table (depth-preferred replacement), classical evaluator with tapered PST, negamax + alpha-beta + quiescence search, driven by iterative deepening
- training/ — Self-play data generation and a value network. Position → flat feature vector (773 floats) → MLP (773 → 128 → 32 → 1), trained with Adam on MSE against game outcomes. Auto-training loop runs selfplay → train → update PST indefinitely
- playEngine.py — CLI to play a game against the engine, using either the classical evaluator or a trained network
Features
- Bitboard board representation (12 piece bitboards)
- Magic-free sliding attacks for bishops, rooks, and queens
- Legal move generation with castling, en passant, and promotion
- Alpha-beta search with transposition table and quiescence search
- Zobrist hashing: compute from scratch or incrementally on move application
- Classical evaluator: material + tapered piece-square tables
- Optional value network: replace the classical eval with a trained neural network
Technologies
Python
Bitboards
Transposition Table
Zobrist Hashing
PyTorch
partially vibe coded
Interesting Details
- The classical evaluator uses tapered eval: separate piece-square tables for opening and endgame phases, blended by game state
- PST auto-update: after training a value network, a script derives new piece-square tables from the learned network weights
- Continuous training loop (
autoTrain.py): self-play → train → update PST — runs indefinitely, generating and consuming .npz datasets - Depth-preferred transposition table replacement: entries are replaced by depth, not by recency
- No external chess libraries — everything from bit twiddling to search is hand-written