A modern C++ implementation of the classic Kalah (Mancala) board game with an AI opponent, based on the original BESM-6 Pascal program from the 1970s-80s.
This is a faithful recreation of a sophisticated mainframe game, featuring:
- AI opponent using minimax search with alpha-beta pruning
- Four difficulty levels from Novice to Master
- ncurses-based terminal UI with animated moves
- Tournament scoring system tracking wins across multiple games
- Conversational AI that comments during gameplay
Kalah is a two-player strategy game played on a board with:
- 6 pits per player (each starting with 6 stones)
- 1 Kalah (store) per player for captured stones
- Choose a pit (1-6) on your side containing stones
- Distribute stones counter-clockwise, one per pit
- Special rules:
- Landing in your Kalah grants an extra turn
- Landing in an empty pit on your side captures the opposite pit's stones
- Skip your opponent's Kalah when distributing
- Game ends when one side has no stones in their pits
- Winner has the most stones in their Kalah
- C++17 compatible compiler (g++ 7+ or clang++ 5+)
- ncurses library
Ubuntu/Debian:
sudo apt-get install g++ libncurses5-devFedora/RHEL/CentOS:
sudo yum install gcc-c++ ncurses-develmacOS:
brew install ncursesmake./kalahOr:
make run- 1-6: Select pit to play
- h: Show help
- q: Quit game
- y/n: Confirm prompts
- Search depth: 2 ply
- Good for learning the game
- Makes occasional mistakes
- Search depth: 2 ply
- Better position evaluation
- More consistent play
- Search depth: 4 ply
- Strategic planning
- Challenging opponent
- Search depth: 4 ply
- Optimal evaluation
- Near-perfect play
- Minimax with alpha-beta pruning
- Variable depth based on difficulty level
- Extra turn handling in search tree
- Cutoff optimization for efficiency
The AI evaluates positions using weighted factors:
- Material balance: Stones in Kalah (highest weight)
- Mobility: Available moves and stone distribution
- Captures: Empty pits opposite opponent stones
- Extra turns: Moves landing in Kalah
- Distance: Proximity of stones to Kalah
- Multi-lap potential: Stones that traverse the board
Each difficulty level uses different weight configurations:
Novice: {kalah: 10, extra: 5, capture: 3, mobility: 1}
Candidate: {kalah: 15, extra: 8, capture: 5, mobility: 2}
Participant: {kalah: 20, extra: 10, capture: 8, mobility: 3}
Master: {kalah: 25, extra: 12, capture: 10, mobility: 4}kalah-re/
├── kalah.h - Game logic header (Position, GameStats, AI)
├── kalah.cpp - Game implementation (minimax, evaluation)
├── ui.h - UI interface header
├── ui.cpp - ncurses UI implementation
├── main.cpp - Game controller and main loop
├── Makefile - Build configuration
├── README.md - This file
└── comments.txt - Original Pascal analysis
KalahGame: Core game logic
- Board state management
- Move validation and execution
- AI opponent (minimax search)
- Position evaluation
- Statistics tracking
KalahUI: Terminal interface
- ncurses-based display
- Animated board updates
- User input handling
- Message display
- Color-coded elements
GameController: Game flow
- Game loop coordination
- Turn management
- Win/loss detection
- Multi-game sessions
This C++ version modernizes the original BESM-6 Pascal program:
- ✅ Core game rules and mechanics
- ✅ Minimax AI with alpha-beta pruning
- ✅ Four difficulty levels
- ✅ Position evaluation heuristics
- ✅ Tournament scoring system
- ✅ Conversational AI commentary
- ❌ Opening book database (BESM-6 zone files)
- ❌ Correction learning system (persistent storage)
- ❌ Multi-user mainframe features
- ❌ Time-of-day scheduling
- ❌ Game save/resume (persistent zones)
- ❌ Cyrillic/Russian text (English interface)
- ❌ Islamic cultural references
- ✨ C++17 with STL containers
- ✨ Portable ncurses UI
- ✨ Standard random number generation
- ✨ RAII resource management
- ✨ Object-oriented design
- ✨ Simplified control flow (no goto)
- Plan ahead: Think 2-3 moves in advance
- Value extra turns: Moves landing in your Kalah are powerful
- Setup captures: Create empty pits opposite opponent stones
- Control endgame: Force opponent to empty their side first
- Count stones: Track totals to know when you're winning
The AI searches thousands of positions per move:
- Novice: ~100-500 nodes
- Candidate: ~500-2000 nodes
- Participant: ~5000-20000 nodes
- Master: ~10000-50000 nodes
Response time is typically under 1 second even at Master level.
The original BESM-6 Pascal program was written circa 1975-1985 for Soviet mainframe computers. Key characteristics:
- 2700+ lines of Pascal
- Sophisticated AI for its era
- Rich conversational personality
- Multi-user shared environment
- Persistent tournament system
Created May 2026 as a modern C++ recreation:
- ~1500 lines of C++
- Maintains core AI algorithms
- Simplified architecture
- Portable across Unix-like systems
- Focus on single-player experience
This implementation is inspired by the original BESM-6 Kalah program. The original program's authorship and licensing status from the 1970s-80s Soviet era are unknown.
This C++ recreation is provided for educational and recreational purposes.
- Original Pascal implementation: Unknown author(s), circa 1975-1985
- C++ recreation: 2026
- Game rules: Ancient (believed to be 6th-7th century origins)
- Original program:
kalah.pas(BESM-6 Pascal dialect) - Analysis:
comments.txt(detailed program documentation) - Kalah rules: https://en.wikipedia.org/wiki/Kalah
- Mancala family: https://en.wikipedia.org/wiki/Mancala
Enjoy the game! May the best strategist win! 🎮