Skip to content

LordXerra/Mancala

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mancala

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.

Features

  • 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)

Gameplay

Board Layout

  [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

Rules

  1. On your turn, click any of your non-empty pits.
  2. Stones are distributed counter-clockwise, one per pit (your opponent's store is skipped).
  3. Extra Turn — If the last stone lands in your store, you get another move.
  4. 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.
  5. The game ends when either player has no stones remaining in their pits. All remaining stones go to their respective stores.
  6. The player with the most stones in their store wins.

Difficulty Levels

Level Depth Behavior
Easy 1-ply 80% random, 20% optimal
Medium 3-ply 45% random, 55% optimal
Hard 9-ply Always plays optimally

Requirements

  • Java 21 (JDK 21+)
  • Gradle (wrapper included)

Building & Running

# Run the game
./gradlew run

# Build a fat JAR
./gradlew jar
java -jar build/libs/mancala-1.0.jar

Project Structure

src/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

Persistent Data

The game stores data in ~/.mancala/:

File Contents
profile.txt Player name
highscores.dat Top 10 scores (pipe-delimited)

License

This project is for personal/educational use.

About

Java remake of the classic pots and stones game.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages