[01] Overview
I built this in my second year while learning Java from scratch. Chess was a good way to practice object-oriented design: every piece shares the same rules of turn-taking but moves differently, and the board has state that must stay consistent after every move.
It was also practice in parsing: squares are written in chess notation such as e4, and the game turns that text into board positions.
Write a playable two-player chess game from first principles, with each concept in its own class.
[02] Design
The code is split into a model, players, and a controller for the interface.
| Class | Responsibility |
|---|---|
| Piece and subclasses | An abstract Piece with King, Queen, Rook, Bishop, Knight, and Pawn, each producing its own valid moves |
| Board | Holds the pieces, validates and applies moves, and tracks castling rights and en passant |
| GameManager | Runs turns between the two players and rejects moves made out of turn |
| Player | An abstract player with a human implementation |
| Move and Position | Small value classes; Position parses chess notation |
[03] Implementation
Special rules live in Board: castling checks whether the king and each rook have moved, en passant tracks pawns that just made a double step, and promotion opens a dialog to pick a queen, rook, bishop, or knight.
The interface is JavaFX, laid out in an FXML file with a button for every square. Clicking a piece highlights where it can go, and clicking a highlighted square makes the move.
[04] Deployment & Console
To run in the browser, the jar is loaded by CheerpJ, a Java runtime compiled to WebAssembly. The page starts CheerpJ, creates a display, and runs the jar, so no server is involved. It is hosted at ravenneil.com/chess as static files.
Service status comes from the Raven Neil Console.