8
7
6
5
4
3
2
1a
b
c
d
e
f
g
h
Waiting for connection...

How it works

A C++ chess engine I built with two teammates for CS 246 at the University of Waterloo, originally drawn in an X11 window. Here it runs on the server and streams every move to your browser in real time.

C++20
TypeScript
Next.js
Socket.IO
Docker
Design Patterns

Architecture

01

Browser

React board sends moves like “move e2 e4” over a WebSocket.

→

02

Socket.IO server

Node.js starts one engine process per game and relays its output.

→

03

C++ engine

Validates the move, lets the computer reply, and prints the board as JSON.

Full rules

Castling, en passant, promotion, check, checkmate, stalemate and insufficient material. Every move is checked against a standalone rules module, tested against python-chess over millions of positions.

Four computer levels

Level 1 plays random legal moves. Level 2 prefers captures and checks. Level 3 also escapes threats. Level 4 adds an opening book.

Observer pattern

Every square is observed by the pieces that attack it, so a move only notifies the pieces it affects instead of rescanning the board.

Decorator pattern

Pieces decorate the empty square beneath them. A capture stacks one piece on another, and removing it restores the square.

The original chess game drawn in an X11 window
The original X11 version on Ubuntu.
UML class diagram of the chess engine
Class diagram. Click to open full size.

The C++ source is private under University of Waterloo policy, and available on request. The website and this page are on GitHub.