This is a complete implementation of a Tic-Tac-Toe game with AI opponent using:
- Alpha-Beta Pruning search algorithm (custom implementation)
- Classical Heuristic Evaluation function
- Machine Learning-Based Evaluation function (manual implementation)
- JavaFX GUI with FXML-based design
- Multiple Difficulty Levels (Easy, Normal, Hard)
- Debug Mode showing AI evaluation scores
✅ Fully functional Tic-Tac-Toe game
✅ AI opponent using Alpha-Beta pruning (NO external AI libraries)
✅ Two evaluation functions: Classical and ML
✅ Three difficulty levels affecting search depth
✅ JavaFX GUI with clean FXML design
✅ Complete menu system (Main Menu → Settings → Game)
✅ Debug mode showing move evaluations
- Language: Java 17
- GUI Framework: JavaFX with FXML
- AI Algorithm: Custom Alpha-Beta pruning with configurable depth
- ML Model: Manually implemented logistic regression (no external ML libraries)
- Architecture: Modular design with separation of concerns
tic-tac-toe/
├── pom.xml
├── src/
│ ├── main/
│ │ ├── java/edu/najah/ai/tictactoe/
│ │ │ ├── TicTacToeApp.java # Main application entry point
│ │ │ ├── game/
│ │ │ │ ├── Board.java # Game board logic
│ │ │ │ ├── Move.java # Move representation
│ │ │ │ ├── Player.java # Player enum (X, O, EMPTY)
│ │ │ │ └── GameSettings.java # Settings manager
│ │ │ ├── ai/
│ │ │ │ ├── AlphaBeta.java # Alpha-Beta pruning implementation
│ │ │ │ ├── Evaluator.java # Evaluation interface
│ │ │ │ ├── ClassicalEvaluator.java # Heuristic-based evaluation
│ │ │ │ ├── MLEvaluator.java # ML-based evaluation
│ │ │ │ └── Difficulty.java # Difficulty levels
│ │ │ ├── ml/
│ │ │ │ ├── FeatureExtractor.java # Extract features from board
│ │ │ │ └── TrainedModel.java # ML model (manual implementation)
│ │ │ └── gui/
│ │ │ ├── MenuController.java # Main menu controller
│ │ │ ├── SettingsController.java # Settings screen controller
│ │ │ └── GameController.java # Game screen controller
│ │ └── resources/
│ │ ├── menu.fxml # Main menu UI
│ │ ├── settings.fxml # Settings UI
│ │ └── game.fxml # Game UI
- Java 17 or higher
- Maven 3.6 or higher
mvn clean compilemvn javafx:runAlternatively, you can package and run:
mvn clean package
java --module-path "path\to\javafx-sdk\lib" --add-modules javafx.controls,javafx.fxml -jar target\tic-tac-toe-0.0.1-SNAPSHOT.jar-
Start the Application: Run using
mvn javafx:run -
Configure Settings:
- Click "Settings" on the main menu
- Choose your symbol (X or O)
- Select difficulty level (Easy/Normal/Hard)
- Choose evaluation function (Classical/ML)
- Enable/disable Debug Mode
- Click "Save Settings"
-
Play the Game:
- Click "Start Game" from the main menu
- Click on an empty cell to make your move
- The AI will automatically respond
- Game ends when someone wins or it's a draw
-
Debug Mode:
- When enabled, the right panel shows:
- AI evaluation scores for all possible moves
- Number of nodes evaluated
- Number of branches pruned
- Current search depth
- When enabled, the right panel shows:
- Implements minimax with alpha-beta cutoffs
- Configurable depth limits based on difficulty:
- Easy: Depth 2 (weak play)
- Normal: Depth 4 (moderate play)
- Hard: Depth 9 (perfect play)
- Prunes branches when α ≥ β
Considers:
- Terminal states: Win (+1000), Loss (-1000), Draw (0)
- Center control: +30 for occupying center
- Corner control: +20 per corner
- Two-in-a-row: +50 for potential winning lines
- Blocking opportunities: Detects and values defensive moves
Features extracted:
- X count on board
- O count on board
- Center control
- Corner control for X and O
- Two-in-a-row counts
- Blocking opportunities
Uses a manually implemented logistic regression model with pre-trained weights.
✅ Game can be played from start to finish against AI
✅ Three difficulty levels produce different AI strength
✅ Both evaluation functions (Classical & ML) work correctly
✅ Full GUI flow: Menu → Settings → Game → End Screen → Restart/Menu
✅ Alpha-Beta runs with pruning and variable depth
✅ ML evaluation produces consistent numeric results
✅ Debug mode shows evaluation scores for all candidate moves
✅ No external AI libraries used (custom implementation)
✅ ML model manually implemented (no TensorFlow, scikit-learn, etc.)
- Real-time status updates
- Visual highlighting of winning line
- Thread-based AI thinking (non-blocking UI)
- Clean, modern UI design
- Help dialog with instructions
- Settings persistence during session
To test the application:
- Test Easy Difficulty: AI should make suboptimal moves (beatable)
- Test Normal Difficulty: AI should be challenging but beatable
- Test Hard Difficulty: AI should never lose (perfect play)
- Test Classical vs ML: Both should produce valid moves
- Test Debug Mode: Verify scores are displayed correctly
- Test Both Players: Try playing as X and as O
- Settings are not persisted across application restarts
- ML model uses pre-set weights (not actually trained on data)
- No animations or sound effects (as per SRS optional features)
- Single-player mode only (no human vs human)
Project: Tic-Tac-Toe AI
Technology: Java 17 + JavaFX
AI Techniques: Alpha-Beta Pruning, Heuristic Evaluation, ML Integration
Implementation: Custom (no external AI libraries)
Enjoy playing against the AI! 🎮