A chess engine built from scratch in Python, with a Django backend and a vanilla JS/HTML/CSS frontend. Move generation, rules enforcement, and game state are handled entirely server-side; the frontend is a thin rendering layer with no game logic of its own.
- Full move generation from scratch (no chess libraries) — all piece types, castling, en passant, promotion (including underpromotion)
- Check, checkmate, and stalemate detection
- Draw detection: threefold repetition, fifty-move rule, insufficient material
- FEN parsing and serialization
- Perft-validated move generator (starting position to depth 5, Kiwipete to depth 4)
- Session-based game state — no database required
- Click-to-move web UI with legal move highlighting and captured-piece tracking
- Bot opponent (see below)
The bot selects moves using minimax search with alpha-beta pruning, searched to depth 3.
- Evaluation: material count only (standard piece values, signed by color)
- Move ordering: MVV-LVA (Most Valuable Victim, Least Valuable Attacker) — captures are searched before quiet moves, ordered by the value of the piece being captured relative to the capturing piece, so that pruning cuts off more of the tree
- Quiescence search: at the end of the main search, capture sequences are extended (depth-limited) until the position is "quiet," to avoid misjudging positions mid-exchange
- Ties in evaluated score are broken randomly among the tied moves, rather than always picking the first one found
The bot reconstructs game state from session data on every request rather than persisting a live object in memory, consistent with how the rest of the app handles state.
- Engine: Python
- Backend: Django
- Frontend: Vanilla JavaScript, HTML, CSS
- Testing: pytest
chess-engine/
├── engine/ # Core chess engine (board, moves, rules, FEN)
├── engine/bot.py # Move evaluation and search (minimax, alpha-beta, quiescence)
├── chess_app/ # Django app (views, urls)
├── webapp/ # Django project settings
├── frontend/
│ ├── templates/ # HTML
│ └── static/ # CSS, JS
├── tests/ # pytest test suite
├── perft.py # Standalone perft script (not part of pytest suite)
└── manage.py
git clone https://github.com/<your-username>/chess-engine.git
cd chess-engine
pip install django pytest
python manage.py migrate
python manage.py runserverVisit http://127.0.0.1:8000/ to play.
pytestFor perft verification:
python perft.py <depth>
python perft.py <depth> -k # Kiwipete positionCore engine, playable web UI, and a working bot opponent are complete.