log

Implementing Bao la Kiswahili

Notes on implementing Bao la Kiswahili, a Zanzibari mancala, on the Parlourite engine. On the game, its cultural standing, the difficulty of the implementation, and decisions on points not stated in the source.

Bao la Kiswahili has been implemented on the Parlourite engine. A separate record is kept for this one as it joins the public lineup.

About Bao la Kiswahili

Bao is a mancala played mainly in Zanzibar and widely across the coastal regions of East Africa. On a 4 × 8 board, 64 seeds are distributed and sown around one’s two rows, with captures taken from the opponent’s side. Emptying the opponent’s front row wins the game (bao hamna).

Within the mancala family, Bao is distinctive for the richness of its rule branches. It has been refined over long stretches of play as a serious board sport that draws spectators. Around a special central hole called nyumba, the structure of legal moves itself shifts depending on whether seeds remain in hand or have run out. When a capture occurs at the end of a lap, it chains, and sowing resumes from another hole.

The rules appear to have reached their current form through generations of play, and when placed on a computer, the interior turns out to be considerably more involved than the surface would suggest.

What makes it hard

The implementation difficulty stems from the following features.

  • Two phases where the meaning of a position shifts depending on whether seeds remain in hand
  • Recursive chain captures
  • Multi-state behavior of the nyumba (existence, threshold, choice, disappearance)
  • Identification of unavailable holes that requires reading two plies ahead
  • Moves not guaranteed to terminate in finite time
  • The constraint that the front row must not be emptied

A naive implementation bloats into branching. Parlourite’s engine is built on a separation between a state machine and declarative transitions, and Bao turned out to be a fitting subject for exercising that design. Among classical abstracts it sits firmly in the harder tier, and work paused more than once along the way.

Verification

The legal-move sets were implemented independently using analysis materials available online as reference, and verified by matching against representative positions and move sequences. Puzzle-style problems were reproduced step by step, and termination and no-move loss conditions were checked.

Thirty random games were run; all reached termination, with an average of 61 moves per game, a maximum per-move processing time of 16 ms, and the sum of seeds on the board and in hand preserved at 64 throughout. The seed-count invariant is wired into the test suite as a conservation law, and it caught several bugs early during development.

Decisions on points not stated in the source

The rules of Bao leave several boundary conditions unspecified. The following were handled as explicit decisions and recorded in the project’s internal notes.

  1. Never-ending moves are treated as draws, as no treatment is given in the source
  2. Both nyumbas are considered to disappear at the moment the first capture occurs in mtaji
  3. When takata ends at a working nyumba, play stops in both phases
  4. A working nyumba is defined as one with six or more seeds while still in existence
  5. The first player is set to south (player 1)

Each of these is recorded as subject to revision should the source be updated, or should more authoritative material become available.

As a record

Bao is one of the games that has been genuinely refined within the culture of play, and keeping a correctly working version of it on a computer felt worth doing on its own terms. Working through the implementation offered a glimpse of the care accumulated by generations of players on the ground.

There is a quiet sense of relief at being done. In the public lineup it occupies a single line, but personally it will remain one of the memorable entries of this project.