A fully interactive, command-line Chess game built in Java 17 with clean code formatting powered by Spotless and Google Java Format.
This project offers an engaging text-based chess experience, allowing players to move pieces using standard chess notation (e.g., move e2 e4) and interact through simple typed commands.
- ♔ Full two-player chess (local)
- 💬 Typed command interface (no GUI)
- 🧠 Hint system to list commands and guide play
- ⏪ Undo and ⏩ Redo functionality
- 💾 Game state management via Gson for easy serialization
- 🧹 Automatic code formatting using Spotless and Google Java Format
- 🏗️ Clean modular architecture with separate classes for pieces, board, and logic
Chess/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── org.chess/
│ │ │ ├── Main.java
│ │ │ └──Color
│ │ │ ├── Color.java
│ │ │ └──game
│ │ │ ├── BoardGame.java
│ │ │ └──Pieces
│ │ │ ├── Bishop.java
│ │ │ └──Rook.java
│ │ │ └──King.java
│ │ │ └──Queen.java
│ │ │ └──Knight.java
│ │ │ └──Pawn.java
│ │ └── resources/
│ └── test/
│ └── java/
│ └──org.chess/
│ └──Color
│ ├── ColorTest.java
│ └──game
│ ├── BoardGameTest.java
│ └──Pieces
│ ├── BishopTest.java
│ └──RookTest.java
│ └──KingTest.java
│ └──QueenTest.java
│ └──KnightTest.java
│ └──PawnTest.java
| └── MainTest.java
├── build.gradle
└── README.md
| Class | Description |
|---|---|
| Main.java | Entry point of the application. Initializes the game and CLI loop. |
| Game.java | Core game logic — manages turns, piece movement, game state, and win conditions. |
| Board.java | Represents the 8×8 chessboard and tracks positions of all pieces. |
| Piece.java | Abstract base class for all chess pieces (King, Queen, Rook, Bishop, Knight, Pawn). Contains movement validation logic. |
| Move.java | Models a single move, including origin, destination, and piece captured. |
| Player.java | Represents each player (White/Black), their pieces, and turn order. |
| CommandHandler.java | Parses user input commands like move, undo, hint, etc. |
| GsonHelper.java | Utility for saving/loading game state using Gson. |
- Java 17
- Gradle 8+
- Internet access for dependency downloads (first run)
git clone https://github.com/DEV-AB-03/Chess.git
cd Chess
./gradlew build
🧹 Format Code with Spotless Automatically formats code using Google Java Format:
./gradlew spotlessApply
./gradlew clean build
Then run jar file
java -jar build/libs/Chess-1.0-SNAPSHOT.jar
🎮 Gameplay & Commands Once running, you’ll see a board and prompt like: Enter command: 🕹️ Available Commands
| Commands | Description |
|---|---|
| load | Load game from a saved text file. |
| save | Save game to a text file. |
| fromto | To make a move, enter the move in the format 'e2e4' (from square to square). |
| pip | To see all possible moves for your pieces, enter 'pip'. |
| resign | To resign from the game, enter 'resign' or 'r' |
| hint | Display all available commands. |
Initialization: The game creates a fresh Board and initializes both players with their respective pieces. Gameplay Loop: The Game class continuously reads input, validates moves, and updates the board.
Move Validation: Each Piece subclass overrides isValidMove() to enforce its own movement rules.
Code Formatting: Spotless plugin ensures consistent, Google-style formatting with every build.
| Category | Technology |
|---|---|
| Language | Java 17 |
| Build Tool | Gradle |
| Libraries | Gson |
| Code Style | Google Java Format via Spotless Plugin |
Example Spotless configuration snippet (from build.gradle):
plugins {
id 'java'
id 'com.diffplug.spotless' version '6.12.0'
}
spotless {
java {
googleJavaFormat('1.17.0')
target 'src/**/*.java'
}
}
🧪 Testing Run unit tests using Gradle:
./gradlew test
Test results appear under:
htmlReport/index.html
Aniket Baidya Software Engineer | Java & Distributed Systems Enthusiast 📧 aniketbaidya03@gmail.com