Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mancala

A two-player Mancala game written in Java. It runs in the terminal and supports Kalah and Ayo.

This was built as a school project and then improved a bit after.

About

The project supports two Mancala rule sets:

  • Kalah
  • Ayo

The app uses a simple terminal interface.

Demo

Mancala terminal demo

Running

From the project folder:

javac -d build/classes $(find src/main/java -name "*.java")
java -cp build/classes ui.TextUI

Example

Welcome to Mancala!
Choose rules, 1 for Kalah or 2 for Ayo: 1
Enter P1 name: Alice
Enter P2 name: Bob

Mancala Game
P2's Store: 0
4  4  4  4  4  4
4  4  4  4  4  4
P1's Store: 0

Current Player: Alice

Players choose pits by number. Player 1 uses pits 1-6, and Player 2 uses pits 7-12.

Rules

The board has 12 pits and 2 stores. Each pit starts with 4 stones. Player 1 owns pits 1-6, and Player 2 owns pits 7-12.

For both rule sets:

  • Players can only move from a non-empty pit on their own side.
  • Stones are placed one at a time around the board.
  • A move is invalid if the pit is empty, out of range, or on the other player's side.
  • The game ends when one player's side is empty.
  • When the game ends, the remaining stones are moved into each player's store.
  • The player with the most stones in their store wins.

Kalah rules:

  • The opponent's store is skipped while placing stones.
  • If the last stone lands in your own store, you get another turn.
  • If the last stone lands in an empty pit on your side, you capture that stone and the stones from the opposite pit.
  • Captured stones go into your store.

Ayo rules:

  • The opponent's store and the starting pit are skipped while placing stones.
  • If the last stone lands in a pit that now has more than one stone, those stones are picked up and the move keeps going.
  • If the move ends in an empty pit on your side, you capture stones from the opposite pit.
  • Ayo does not give bonus turns.

Testing

The repo includes a small Java test runner for the main rules and edge cases:

javac -d build/classes $(find src/main/java -name "*.java")
javac -cp build/classes -d build/test-classes $(find src/test/java -name "*.java")
java -cp build/classes:build/test-classes mancala.MancalaRulesTest

Folder Structure

mancala/
|-- assets/
|-- src/
|   |-- main/java/mancala/
|   |-- main/java/ui/
|   `-- test/java/mancala/
|-- build.gradle
`-- README.md

Important paths:

  • src/main/java/mancala/ contains the board, players, pits, stores, and rules.
  • src/main/java/ui/TextUI.java runs the terminal game.
  • src/test/java/mancala/MancalaRulesTest.java contains the rule and edge case tests.
  • assets/mancala-terminal-demo.gif is the terminal demo.
  • assets/github-banner.png is the GitHub social preview banner.

About

Two-player Mancala game in Java.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages