A Java Swing implementation of the classic Mancala board game featuring a single-player mode against a minimax AI opponent, animated stone sowing, synthesized sound effects, and a persistent high-score leaderboard.
- AI Opponent — Minimax algorithm with alpha-beta pruning at three difficulty levels
- Animated Gameplay — Stone sowing flight animations, capture flashes, and gem pulse effects
- Synthesized Audio — Procedurally generated sound effects (no audio files required)
- High-Score Leaderboard — Top 10 scores persisted locally, sortable by score and time
- Player Profiles — Name persistence across sessions
- Customizable Setup — Choose 4, 5, or 6 starting stones per pit
- Programmatic Board Rendering — Pixel-perfect board drawn with Java2D (no image assets needed for the board)
[P2 Store] [12][11][10][ 9][ 8][ 7] [P1 Store]
[ 0][ 1][ 2][ 3][ 4][ 5]
- Pits 0–5: Player 1 (bottom row)
- Pits 7–12: Player 2 / Computer (top row)
- Indices 6 and 13: Stores
- On your turn, click any of your non-empty pits.
- Stones are distributed counter-clockwise, one per pit (your opponent's store is skipped).
- Extra Turn — If the last stone lands in your store, you get another move.
- Capture — If the last stone lands in an empty pit on your side and the opposite pit is not empty, you capture both pits' stones into your store.
- The game ends when either player has no stones remaining in their pits. All remaining stones go to their respective stores.
- The player with the most stones in their store wins.
| Level | Depth | Behavior |
|---|---|---|
| Easy | 1-ply | 80% random, 20% optimal |
| Medium | 3-ply | 45% random, 55% optimal |
| Hard | 9-ply | Always plays optimally |
- Java 21 (JDK 21+)
- Gradle (wrapper included)
# Run the game
./gradlew run
# Build a fat JAR
./gradlew jar
java -jar build/libs/mancala-1.0.jarsrc/main/java/mancala/
├── Main.java # Application entry point; window and screen management
├── GamePanel.java # Board rendering, animations, and input handling
├── GameState.java # Game logic, move execution, and rule enforcement
├── IntroPanel.java # Title/menu screen with leaderboard and settings
├── AIPlayer.java # Minimax AI with alpha-beta pruning
├── HighScoreManager.java # Persistent high-score storage (~/.mancala/highscores.dat)
├── ProfileManager.java # Player name persistence (~/.mancala/profile.txt)
└── SoundPlayer.java # Procedural audio synthesis via JavaSound
src/main/resources/
├── gem2.png # Green gem texture
└── gem5.png # Purple gem texture
The game stores data in ~/.mancala/:
| File | Contents |
|---|---|
profile.txt |
Player name |
highscores.dat |
Top 10 scores (pipe-delimited) |
This project is for personal/educational use.