03 / Project case study
Two-Player Chess Game
A fully playable, two-player chess game with standard rules, built from scratch in Java with Swing and AWT.
Java / Swing / AWT / OOP / Multi-threading
Overview
The problem.
Building a complete chess game requires implementing complex rule logic including piece movement, check detection, castling, en passant, and pawn promotion—all while maintaining an interactive UI.
The approach.
A single-process Java desktop application with a Swing/AWT GUI, featuring a polymorphic piece engine, dedicated game loop thread, and 'simulate-then-commit' move validation pattern.
What the project focuses on.
- Two-player local turn alternation
- Full legal move validation for all 6 piece types
- Check, checkmate, and stalemate detection
- Advanced rules: castling, en passant, pawn promotion
- Interactive UI with move highlighting and visual feedback
- 60 FPS fixed-timestep render loop
- Sprite rendering with ImageIO
Screenshots


Engineering notes
A problem worth understanding.
- Challenge
- Preventing moves that would leave the king in check.
- Cause
- Validating moves directly on the live board risked corrupting game state.
- Solution
- Used a 'simulate-then-commit' pattern with temporary piece lists for validation before applying to the live board.
- Result
- Consistent board state with reliable move validation.
The takeaways.
- Designing a polymorphic piece hierarchy with shared state and specialized behavior.
- Managing game state and preventing corruption through validation patterns.
- Building interactive desktop applications with Java Swing/AWT and custom rendering.
- Implementing game-loop concurrency patterns for consistent frame rates.
- Using inheritance and method overriding for rule-specific logic.