A C++20 chess game with text-based display and modern graphical mode using SDL2.
Supports human vs human, human vs AI, and AI vs AI with four difficulty levels.
Note: This project has been migrated from X11 to SDL2 for better cross-platform support and modern graphics capabilities.
chess-engine/
├── src/
│ ├── core/ # Game logic, board, and main entry point
│ ├── pieces/ # Chess piece implementations
│ ├── players/ # Human and computer player classes
│ ├── ai/ # AI difficulty levels (1-4)
│ ├── display/ # Text, graphics, and log displays
│ ├── patterns/ # Observer/Subject design patterns
│ └── utils/ # Utility classes (PRNG, window)
├── Makefile
└── README.md
- C++20 compiler (tested with g++)
- Make
- SDL2 and SDL2_ttf libraries (for graphics)
Ubuntu/Debian:
sudo apt-get install libsdl2-dev libsdl2-ttf-devFedora/RHEL:
sudo dnf install SDL2-devel SDL2_ttf-develmacOS (Homebrew):
brew install sdl2 sdl2_ttfWindows (MSYS2):
pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_ttfImportant: Make sure SDL2 libraries are installed first (see Installing SDL2 above).
Build the game:
makeThis produces: ./chess
Clean build artifacts:
make cleanText-only mode:
./chessWith graphics:
./chess -gWith logging:
./chess -lWith both:
./chess -g -l-
Start a game
game white-player black-playerExample:
game human computer1where
computer1–computer5are AI difficulty levels. -
Make a move
move e2 e4or just
movefor AI moves. -
Resign
resign -
Setup mode
setupThen use
+ K e1,- e1, etc. -
Quit
PressCtrl+Dor typequit.
- TextDisplay: ASCII chessboard
- GraphicsDisplay: Modern SDL2-based GUI with hardware acceleration
- LogDisplay: optional file-based move log
Multiple displays can be attached simultaneously. The graphics display features:
- Cross-platform support (Windows, Linux, macOS)
- Smooth rendering with hardware acceleration
- Modern, clean interface
computer1: random movescomputer2: simple heuristicscomputer3: improved heuristicscomputer4: 2-ply lookaheadcomputer5: strongest AI (4-ply alpha-beta, static eval, piece-square tables, quiescence)
The engine can be compiled to WebAssembly for the browser. See web/README.md for build instructions. A minimal web UI is included; deploy the web folder to GitHub Pages or any static host.
$ ./chess
Welcome to Chess!
Commands:
game white-player black-player
move e2 e4
autoplay
resign
setup
Ctrl+D to quit.
> game human computer1
> move e2 e4