A chess game played as blitz rounds, written entirely in Java Swing without any third-party libraries.
- +10 seconds added to the clock after each move
- Only the player whose turn it is can move
- Game ends immediately when any player runs out of time
- Pieces move according to chess rules – legal moves are highlighted
- A pawn reaching the last rank can promote to Queen, Rook, Bishop, or Knight
- When check is declared, only moves that resolve it are allowed
- Any move that would put your own king in check is canceled
- Statistics panel shows: whose turn, each player's remaining time, and total game time
- 60+ unit tests covering:
-
- move validation
-
- check/checkmate logic
-
- piece behavior
- Built with JUnit and Mockito
- Integrated CI pipeline (GitHub Actions):
-
- runs on every push to main
-
- executes full test suite
-
- prevents broken builds
Distributed under the MIT License. See LICENSE for more information.
- Java 25 or higher (due to the use of latest JVM features).
- Download the latest
.jarfrom the Releases page. - Run it via terminal:
Or simply double-click the file if your OS associations are set up.
java -jar hafn-chess-VERSION.jar
If you want to build the project yourself:
git clone https://github.com/hafn-g/chess.git
cd chess
mvn clean packageWhen a move is illegal (e.g., does not resolve check), a warning is shown.
If you don't choose a promotion piece, the pawn remains a pawn.
Click to expand
chess/
├── application/ # Application layer – connects domain and UI
│ ├── port/
│ │ ├── in/ # Input ports (user command interfaces)
│ │ │ └── BoardInputPort.java # Interface for processing user commands
│ │ └── out/ # Output ports (infrastructure interfaces)
│ │ ├── BoardRenderPort.java # Interface for rendering the board
│ │ ├── BoardStatePort.java # Interface for retrieving board state
│ │ └── SelectionPort.java # Interface for highlighting pieces/cells
│ └── usecase/ # Business case implementations (files not expanded)
├── bootstrap/ # Application startup and initialization
│ ├── BoardInitializer.java # Initializes the chessboard
│ └── Main.java # Application entry point
├── domain/ # Chess business logic
│ ├── model/ # Core business objects
│ │ ├── Cell.java # Board cell model
│ │ ├── HistoryMove.java # Move history
│ │ ├── PieceColor.java # Piece colors
│ │ └── PieceType.java # Piece types
│ ├── piece/ # Chess piece classes and moves
│ │ ├── Bishop.java, King.java, Knight.java, Pawn.java, Queen.java, Rook.java
│ │ ├── Move.java # Move description
│ │ └── Piece.java # Base piece class
│ ├── port/ # Interfaces for domain interaction
│ │ └── BoardPort.java # Main port for board operations
│ ├── service/ # Services and business rules
│ │ ├── CheckRule.java # Check detection
│ │ └── MoveHelperGenerator.java # Generates legal moves
│ └── state/ # Game state
│ └── BoardState.java # Current board state
└── ui/ # User interface
└── swing/ # Swing UI implementation
├── ChessFrame.java # Main application window
├── model/
│ └── BoardMetrics.java # Board display parameters
├── panel/
│ ├── BoardPanel.java # Chessboard panel
│ └── StatsPanel.java # Statistics panel
└── renderer/
├── BoardRenderer.java # Board rendering logic
└── ImageCache.java # Image caching