A fully functional, object-oriented Chess Engine built from scratch using Java 17 and JavaFX. This project features a robust MVC architecture, a custom Minimax AI opponent, and a polished medieval pixel-art interface
- Complete Chess Rules: Handles complex moves including Castling (King/Queen side), En Passant, and Pawn Promotion.
- Move Validation: Validates legal moves for all pieces, preventing illegal actions (e.g., moving a pinned piece, moving into check).
- Game States: Detects Check, Checkmate, and Stalemate conditions accurately.
- Minimax Algorithm: Implements a recursive tree-search algorithm to determine the best move.
- Heuristic Evaluation: Scores board states based on material weight, mobility, and positional safety.
- Concurrency: Runs AI calculations on a background thread (
JavaFX Task) to prevent UI freezing during deep searches.
- JavaFX Implementation: Built with a clean, responsive UI using
StackPane,BorderPane, andGridPanelayouts. - Asset Management: Features a "Medieval Pixel Art" theme with video backgrounds (
.mp4) and custom sound effects. - Quality of Life:
- Visual Feedback: Highlights legal moves and selected pieces.
- Game Timer: Functional countdown clock with "Flag Fall" logic.
- Menus: Interactive Main Menu, Game Setup (Mode/Difficulty/Time), and Pause/Game Over screens.
- Language: Java 17
- Framework: JavaFX 22.0.2 (Controls, FXML, Media, Graphics)
- Build Tool: Maven
- Testing: JUnit 5, Mockito
- Design Patterns:
- MVC: Separates
Board(Model),BoardPanel(View), andGameEngine(Controller). - Strategy Pattern: Used for AI Move selection (
MoveStrategy). - Factory Pattern: Used for creating Moves (
MoveFactory). - Builder Pattern: Used for constructing immutable
Boardstates. - Singleton/Static Utilities: Used for
SoundManagerandImageCache.
- MVC: Separates
- Java JDK 17 or higher.
- Maven installed.
-
Clone the repository
git clone [https://github.com/dat-nnguyen/java-chess-engine.git](https://github.com/dat-nnguyen/java-chess-engine.git) cd java-chess-engine -
Build the project (Downloads dependencies)
mvn clean install
-
Run the Application
mvn javafx:run
- Left Click: Select a piece / Move a piece.
- Esc / Menu Button: Pause the game and open the in-game menu.
- Drag Game Over Screen: You can click and drag the victory popup to view the final board state underneath.
The project follows strict Object-Oriented Principles:
entitiesPackage: Contains the core logic.Board: Immutable state container representing the 64 squares.Piece: Abstract class with subclasses (Rook,Pawn, etc.) defining movement vectors.Move: Represents a state transition. Subclasses handle special logic (CastleMove,PawnJump).
guiPackage: Handles the presentation layer.GameEngine: The central controller managing game loop, input handling, and AI triggers.BoardPanel&SquarePanel: Renders the grid and handles click events.
core.aiPackage:MiniMax: The decision-making algorithm.StandardBoardEvaluator: The scoring system for board states.
The project includes a JUnit test suite covering critical game mechanics.
To run tests:
mvn testAuthor: Nguyen Tuan Dat
License: MIT