The most complex mancala game in existence, implemented in Python with 60+ AI and utility modules.
This is the fourth and final entry in a progressive series teaching students ages 10–17 how to code AI for mancala games:
| Game | Difficulty | Board | Language | Repo |
|---|---|---|---|---|
| Shisima | ★☆☆☆☆ | Triangle, 3 pieces | HTML/JS | shisima-game-lesson |
| Giuthi | ★★☆☆☆ | 2×8, relay sowing | HTML/JS | giuthi-ai-explorer |
| Kiothi | ★★★☆☆ | 2×10, nki, chain captures | HTML/JS | kiothi-mancala-lesson |
| Bao la Kiswahili | ★★★★★ | 4×8, two phases, nyumba, kichwa | Python | This repo |
Bao la Kiswahili ("board of the Swahili people") is the most sophisticated mancala game ever devised. Played in Zanzibar and coastal Tanzania, it features:
- 4×8 board (32 pits) with 64 seeds
- Two phases: namua (seed placement from hand) and mtaji (sowing from board)
- Nyumba (house): a special pit with 6+ seeds that can be "taxed" or enter safari mode
- Kichwa (head): directional sowing rules from board edges
- Marker pits: inner-row pits facing non-empty opponent pits
- Complex captures: capturing requires crossing from your row to the opponent's row, with directional constraints
- Takasia: restricted pits that cannot be sown from
Bao is considered a thinking game of the highest order — grandmasters in Zanzibar are held in the same esteem as chess grandmasters elsewhere.
bao-la-kiswahili/
├── bao/
│ ├── config.py # Constants (rows, cols, player positions)
│ ├── board.py # GameState, BaoBoard, Move, MoveResult
│ ├── engine.py # Rule engine: moves, captures, sowing, game over
│ ├── cli.py # Command-line interface
│ ├── ai/ # 34 AI strategy modules
│ │ ├── base.py # BaoAI abstract base class
│ │ ├── minimax.py # Classic alpha-beta pruning
│ │ ├── mcts.py # Monte Carlo Tree Search
│ │ ├── neural_net.py # Neural network evaluation
│ │ ├── ... # (30 more strategies)
│ ├── analysis/ # 6 analysis modules
│ ├── training/ # 5 training/evaluation modules
│ ├── tournament/ # 4 tournament systems
│ ├── ui/ # 5 UI/display modules
│ └── utils/ # 8 utility modules
├── tests/
│ └── test_bao.py # 19 engine tests (all passing)
├── AI_DEV_REFERENCE.py # API reference for module developers
├── setup.py # Package installation
└── requirements.txt # Dependencies (stdlib + optional numpy)
| Module | Class | Strategy |
|---|---|---|
minimax.py |
MinimaxAI |
Alpha-beta pruning with weighted evaluation |
mtdf.py |
MTDfAI |
MTD(f) zero-window iterative search |
scout.py |
ScoutAI |
Principal Variation Search (SCOUT) |
negamax.py |
NegamaxAI |
Negamax formulation |
negascout.py |
NegascoutAI |
NegaScout (PVS from negamax) |
alpha_beta_transposition.py |
AlphaBetaTtAI |
Transposition tables |
killer_moves.py |
KillerMoveAI |
Killer move + history heuristic |
iterative_deepening.py |
IterativeDeepeningAI |
Time-limited deepening |
aspiration_windows.py |
AspirationWindowAI |
Aspiration window narrowing |
quiescence.py |
QuiescenceAI |
Quiescence search (anti-horizon) |
ssstardis.py |
SSSStarAI |
SSS* best-first search |
best_first.py |
BestFirstAI |
Best-first alpha-beta |
expectimax.py |
ExpectimaxAI |
Stochastic opponent modeling |
paranoid.py |
ParanoidAI |
Worst-case loss maximization |
| Module | Class | Strategy |
|---|---|---|
mcts.py |
MCTSAI |
UCT-based MCTS with random rollouts |
mcts_heuristic.py |
MCTSHeuristicAI |
MCTS with heuristic rollouts |
mcts_rave.py |
MCTSRAVEAI |
MCTS with RAVE/AMAF values |
| Module | Class | Strategy |
|---|---|---|
temporal_difference.py |
TDAI |
TD(0) value function learning |
q_learning.py |
QLearningAI |
Q-learning with epsilon-greedy |
policy_gradient.py |
PolicyGradientAI |
REINFORCE policy gradient |
actor_critic.py |
ActorCriticAI |
Actor-Critic with TD error |
| Module | Class | Strategy |
|---|---|---|
genetic.py |
GeneticAI |
Genetic algorithm weight evolution |
neural_net.py |
NeuralNetAI |
2-layer MLP evaluation (numpy or pure Python) |
| Module | Class | Strategy |
|---|---|---|
greedy_captures.py |
GreedyCaptureAI |
Maximizes immediate captures |
defensive.py |
DefensiveAI |
Minimizes capture threats |
positional.py |
PositionalAI |
Weighted positional evaluation |
territorial.py |
TerritorialAI |
Territory zone control |
mobility.py |
MobilityAI |
Maximizes move options |
nyumba_aware.py |
NyumbaAwareAI |
Strategic nyumba management |
kichwa_tactics.py |
KichwaTacticsAI |
Exploits kichwa direction rules |
endgame_solver.py |
EndgameSolverAI |
Deep search for endgames |
| Module | Class | Strategy |
|---|---|---|
ensemble.py |
EnsembleAI |
Combines multiple AIs via voting |
hierarchical.py |
HierarchicalAI |
Phase-aware strategy switching |
human_like.py |
HumanLikeAI |
Simulates human play with mistakes |
board_analyzer.py— Threat counting, capture potential, vulnerabilitygame_replay.py— Step through game move-by-movemove_explainer.py— Natural-language move explanationsposition_evaluator.py— Multi-factor position scoringstatistics.py— Game statistics trackingthreat_detector.py— Capture threat detection
trainer.py— Self-play training loopcurriculum.py— Progressive difficulty trainingarena.py— Round-robin tournament frameworkparameter_tuner.py— Hyperparameter grid/random searchevaluator.py— Comprehensive AI evaluation
swiss.py— Swiss-system tournament with Buchholz tiebreaksingle_elim.py— Single-elimination bracketrating_system.py— Elo rating systemmatch_runner.py— Match execution with stats
cli.py— Interactive command-line interfacetext_display.py— Rich text board renderinghtml_renderer.py— HTML/SVG board with dark themegame_recorder.py— Save/load games as JSONnotation.py— Bao move notation (English + Swahili)
opening_book.py— Opening sequence storage and retrievalendgame_table.py— Retrograde analysis endgame solutionsstate_serializer.py— GameState serialization (dict/JSON/compact)move_generator.py— Comprehensive move generation utilitiesperft.py— Performance test for move generationbenchmark.py— AI speed benchmarkingopening_analyzer.py— Opening classification and analysisgame_tree.py— Game tree building and visualization
# Clone
git clone https://github.com/drwjkirkpatrick-web/bao-la-kiswahili.git
cd bao-la-kiswahili
# Run tests
python tests/test_bao.py
# List all AI strategies
python -m bao.cli --list-ais
# Play against minimax AI
python -m bao.cli --ai minimax --depth 3
# Watch two AIs play
python -m bao.cli --ai minimax --depth 2 --ai2 mcts
# Run a tournament
python -m bao.cli --tournament minimax mcts greedy --rounds 2
# Performance test
python -m bao.cli --perft 2See LESSON_PLAN.md for a 6-session curriculum designed for students ages 10–17. The curriculum covers:
- Bao rules and board mechanics
- Game state and move generation
- Evaluation functions and heuristics
- Minimax search and alpha-beta pruning
- Monte Carlo Tree Search
- Machine learning approaches (TD, Q-learning, neural nets)
Bao la Kiswahili is a living tradition of the Swahili coast. It is played in Zanzibar's stone town, in the coffee houses of Lamu, and across coastal Tanzania. The game is taken seriously — there are formal tournaments and recognized masters. This implementation is an educational project intended to share appreciation for this remarkable game.
MIT — free for educational and personal use.