RAVEN NEIL [05] JAVA CHESS
LAUNCH APP

Java Chess: Where I Learned OOP

My second-year project: a two-player chess game I wrote from scratch in Java to learn object-oriented programming and parsing. It now runs in the browser through CheerpJ.

Category Java · OOP
Model / Runtime JavaFX · CheerpJ (WebAssembly)
Host chess.ravenneil.com
Status
ONLINE
SYSTEM DIAGRAM · /apps/chess PIPELINE STAGE [01] Java and JavaFX Packaged as a jar STAGE [02] CheerpJ A JVM in WebAssembly STAGE [03] Browser Board drawn on the page STRUCTURE Board · GameManager · Piece subclasses · Player · Move · Position
FIGURE 5 · JAVA CHESS PIPELINE

[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.

Goal

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.