A Java console-based chess game built with Maven, implementing complete chess rules including castling, en passant, pawn promotion, check/checkmate/stalemate detection, and game state persistence.
- Full chess rule implementation: castling, en passant, pawn promotion
- Check, checkmate, and stalemate detection
- Domain-driven design with layered architecture:
- Domain models (Board, Piece, GameState)
- Rules engine (MoveValidator, CheckDetector)
- Services (GameService, MoveService)
- Parser (AlgebraicParser)
- Persistence (SaveLoadService)
- Human-vs-human play with command-line input
- Legal move listing ("pip" command)
- Save/load game state to/from text files
- Comprehensive JUnit test suite
- Java 8 or higher
- Maven 3.x
-
Clone the repository:
git clone <repository-url> cd console-chess
-
Build the project:
mvn clean compile
-
Run the game:
mvn exec:java -Dexec.mainClass="com.chess.controller.GameController"
Alternatively, after building:
java -cp target/classes com.chess.controller.GameController- Enter player names when prompted.
- Enter moves in long algebraic notation (e.g.,
e2e4for pawn to e4,e7e8qfor promotion to queen). - Special commands:
pip: List all legal moves for the current player.save <filename>: Save the current game state.load <filename>: Load a saved game.hint: Show help.q: Quit the game.
graph TD
A[GameController] --> B[GameService]
A --> C[MoveService]
B --> D[RulesEngine]
C --> D
D --> E[MoveValidator]
D --> F[CheckDetector]
E --> G[GameState]
F --> G
G --> H[Board]
G --> I[Piece]
G --> J[Square]
G --> K[Move]
G --> L[CastlingRights]
A --> M[AlgebraicParser]
A --> N[SaveLoadService]
N --> G
src/main/java/com/chess/: Source codedomain/: Core domain modelsrules/: Chess rule validation and move generationservice/: Business logic servicesparser/: Input parsingpersist/: Game state serializationcontroller/: Main application controller
src/test/java/: Unit testspom.xml: Maven configuration
Run the test suite:
mvn testThis project is a learning exercise in chess algorithms and clean Java code. Feel free to fork and extend with features like AI opponents or a GUI.
[Add your license here, e.g., MIT]