Problem statement
Design the object model and core APIs for a Mancala (Kalah) engine: two players sow stones counterclockwise around pits and stores, with extra-turn and capture rules, until one side is empty.
Operating context. A standard Kalah board has two rows of six pits plus one store per player, starting with four stones per pit. On a turn a player lifts all stones from one of their own non-empty pits and sows them one per following pit counterclockwise, dropping into their own store but skipping the opponent's store. Landing the last stone in the player's own store grants another turn. Landing the last stone in one of the player's own empty pits captures that stone plus all stones in the directly opposite pit into the store. The game ends when a player's six pits are all empty; the opponent sweeps their remaining stones into their store, and the higher store wins. Single in-process match.
Out of scope. AI move search, networked play, alternate rule families (Oware, Bao) beyond a rule seam, move clocks, and any rendering or animation.
What to produce. The class model (board, pit, store, move/sow, game, player, rule set), the public API each exposes, and the sowing traversal (order, and skipping the opponent's store). Be explicit about how the extra-turn and capture rules are decided from the landing pit alone, how end detection and the final sweep work, how pit indexing stays encapsulated so callers never do modular arithmetic, and how a variant (different pit count or starting stones) plugs in behind a seam.
Functional requirements
- Sow the stones from a chosen non-empty own pit, one per following pit counterclockwise, into the player's own store but skipping the opponent's store.
- Grant the current player another turn when the last sown stone lands in their own store.
- Capture the last stone and the opposite pit's stones into the store when the last stone lands in a previously empty pit on the player's own side.
- Detect game end when one side's pits are all empty, then sweep the other side's remaining stones into its store.
- Reject a move from an empty pit or from a pit not owned by the current player.
Non-functional requirements
- A single sow is O(stones sown), touching only the pits on the traversal path, not the whole board.
- Pit indexing and the counterclockwise traversal (with opponent-store skip) are encapsulated so callers never do modular arithmetic themselves.
- The extra-turn and capture rules are total transition steps decided from the landing pit alone.
- Board geometry (pit count, starting stones) and rule variants live behind a rule-set seam, not hard-coded literals in the sow loop.
- The engine is deterministic and unit-testable from any board configuration, with no clock or randomness.
- Pit and store contents are encapsulated; scores are read from the stores, never set directly by callers.
Topics
- System Design LLD
- Oop Solid
- Patterns Strategy
- Oop Encapsulation
- Domain Board-Games