Which version?

Marlon Kranz

Back

The King's Game: Modular Chess Platform

A chess platform in Java 17 and JavaFX 21 with three Maven modules: a desktop client, a game engine without dependencies, and a TCP server for online play with accounts and matchmaking. Standard chess and Chess 960.

  • 2023–Present
  • Java 17, JavaFX 21, Maven, TCP Networking, SQLite, JUnit 5, Mockito, Docker, CSS Theming, i18n
  • GitHub

Overview

The project has three Maven modules. application is the JavaFX desktop client, core is the game engine for standard chess and Chess 960, and server hosts online games over TCP, with accounts, matchmaking and persistence. core has no external dependencies, and client and server depend on core only. Neither knows about the other.

I started it in my second year at university. The client was rewritten from Swing to JavaFX in March 2026, and the server keeps user accounts, sessions and games in SQLite. I use the project to see how spec-driven and test-driven agent workflows hold up on a codebase where architecture rules and tests can check the result.

Main menu with the Midnight theme

Features

  • Local play for two players on the same machine
  • Online play with a TCP lobby, join codes and automatic matchmaking
  • Standard chess and Chess 960, selectable per game
  • Full rule enforcement: castling, en passant, promotion with a piece-selection dialog, stalemate, the 50-move rule, threefold repetition and insufficient material
  • Six themes: Midnight, Ember and Abyss (dark), Manuscript, Fjord and Sakura (light)
  • English and German through ResourceBundle
  • A headless mode for programmatic game control (nogui flag)
  • An animated main menu drawn in code, which a Reduced Motion setting turns off
Local game in the Ember theme, mid-game with move highlights

Architecture

Zero dependenciesDepends on core onlyapplicationJavaFX 21 UI, controllers, theming, i18n, networkingcoreGame engine, pieces, rules, observer, facade APIserverTCP, lobby, auth, matchmaking, SQLite persistence

Five rules hold across the modules:

  1. core has no dependency on application or server. Client and server depend on core only, never on each other.
  2. All access to the game engine goes through the Chess.java facade. Code outside core does not instantiate Game subclasses directly.
  3. UI components implement GameObserver and register with chess.addObserver(). Nothing polls.
  4. core is logic only: no UI imports, no JavaFX, no I/O.
  5. A new rule variant implements the Ruleset interface. Game does not branch on the variant.

Design patterns

PatternImplementationPurpose
FacadeChess.javaOne entry point for all access to the engine
ObserverGameObserver / ObservablePushes state changes to the UI and the network layer without coupling them to core
StrategyRuleset with StandardChessRuleset and Chess960RulesetRule variants without conditionals in the game logic
Factory MethodGame.createGame() / Game.createServerGame()Keeps constructors package-private, which enforces the module boundaries
Template MethodGame.executeMove()Fixes the order of a move, and OnlineGame overrides the step that relays it over the network

Multiplayer server

The server accepts TCP connections on a configurable port (default 54321) and speaks a line-based text protocol. Port, game limit, timeouts and expiry come from server.properties.

  • Up to 40 games at once by default, limited by a semaphore.
  • Join codes have 12 characters from A–Z and 0–9, shown as XXXX-XXXX-XXXX. They come from SecureRandom and expire after 10 minutes by default.
  • A matchmaking queue pairs opponents who do not use a join code.
  • Login, registration and token-based sessions, with SQLite storing users, sessions and games.
  • Every move is validated by the same engine before it is relayed, and illegal moves are rejected.
  • When a player disconnects, the game pauses. If the player has not returned after 300 seconds (the default), the opponent wins by timeout.
Online game setup with Chess 960 ruleset selection

Testing

The three modules together have 75 test classes.

ModuleTest classesFocus
core34Board state, move generation, all piece types, both rulesets, castling, observer notifications, game factory, online game protocol
application31Facade API, i18n, settings, theme manager, menu components, controller logic, CSS validation
server10Server lifecycle, configuration, game management, client handler, matchmaking, authentication, persistence
Checkmate: win screen with rematch option
Settings with six themes, language selection and server configuration

Tech stack

LayerTechnology
LanguageJava 17
UIJavaFX 21 (FXML and CSS theming)
BuildMaven (multi-module)
TestingJUnit 5, Mockito
NetworkingJava standard library (ServerSocket, ConcurrentHashMap, Semaphore)
PersistenceSQLite (user accounts, sessions and games on the server)
LocalizationResourceBundle (EN/DE)
ThemingCSS (three dark, three light)