m.MAHESH
DEVELOPER & THINKER

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

Chess game GUI screenshot when opponent is checked
Black's king is in check, with the game displaying a warning banner and highlighting the threat during Black's turn.
Chess game GUI screenshot when opponent is checkmate
Checkmate scenario with Black winning the game, showing the victory banner and the final board position.

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.

Every good thing starts somewhere.

Let's start with hello.

An opportunity, a project, or a good backend question. Put a few words together below.

Your email app will open a draft addressed to maheshgudooru@gmail.com. You choose when to send it.