Formal Specification
Nerenchi (Sri Lankan Alignment Game) — Formal Specification
Sri Lanka · board-abstract · Confidence: high
← Back to game pageImplementation Suitability
Suitability: engine-readyFidelity: directGap-fills: 3
# Nerenchi Keliya — AI-optimized specification
## General idea
Nerenchi Keliya is an ancient Sri Lankan two-player abstract strategy alignment game (Nine Men's Morris family). Played on a board of three concentric squares with 24 intersection vertices connected by orthogonal midpoint lines, players place and maneuver 9 pieces each to form 3-in-a-row alignments (*nerenchi*), which award the capture and removal of opposing pieces. When reduced to 3 pieces, an agent gains free jumping mobility until reduced to 2 pieces or immobilized.
## Formal model
- **Abstraction taken:** Direct discrete formalization on a topological graph `G = (V, E)` with `|V| = 24` vertices and 32 undirected edges. The 16 straight 3-in-a-row alignment lines form the set of valid *nerenchi* mills `M`.
- **Player/agent count:** Exactly 2 players (Player 0 / White, Player 1 / Black).
- **Turn model:** Strictly sequential alternating turns.
## Formal rules
R1. Setup:
- Graph `G = (V, E)` has 24 vertices indexed `0..23` (Outer square: 0..7, Middle square: 8..15, Inner square: 16..23).
- Board starts completely vacant (`board[v] = EMPTY` for all `v in V`).
- Each player holds 9 unplaced pieces in hand (`unplaced[0] = 9`, `unplaced[1] = 9`).
- Active player starts as Player 0.
R2. Phase 1 — Piece Placement:
- While `unplaced[active_player] > 0`:
- Active player selects any vacant vertex `v in V` and places a piece (`board[v] = active_player`, `unplaced[active_player] -= 1`).
- If placing this piece forms a new 3-in-a-row line `m in M` of friendly pieces (*nerenchi*):
- Active player selects and removes 1 opponent piece from the board (`board[v_target] = EMPTY`).
- [gap-fill] Capture Priority: If possible, the captured piece must NOT belong to an active opponent 3-in-a-row line; if all opponent pieces are in lines, any opponent piece may be captured.
R3. Phase 2 — Piece Movement (Sliding):
- When both players have placed all 9 pieces (`unplaced[0] == 0` and `unplaced[1] == 0`):
- Active player selects a friendly piece at `v_from` and moves it along an edge `(v_from, v_to) in E` to an adjacent vacant vertex `v_to`.
- If this move forms a new 3-in-a-row line `m in M`:
- Active player selects and removes 1 opponent piece per R2 capture rules.
R4. Phase 3 — Flying (*Pāna*):
- When a player's on-board piece count drops to exactly 3 pieces:
- That player's pieces gain the ability to "fly" — moving from `v_from` to ANY vacant vertex `v_to in V`, ignoring edge connectivity.
R5. Win / Loss Conditions:
- A player loses immediately if:
- Their total piece count (on-board + unplaced) drops to 2 (incapable of forming any 3-in-a-row).
- It is their turn to move in Phase 2/3 and they have 0 legal moves available (all pieces trapped).
R6. Draw / Loop Prevention:
- [gap-fill] Threefold Repetition: If the exact same board position (vertex occupancy and piece counts) occurs three times with the same player to move, the game is declared a draw.
- [gap-fill] Move Limit: If 50 consecutive moves occur without any capture, the game is declared a draw.
## Edge cases
- Tie at the end condition: Declared under threefold repetition or 50-move non-capture limit.
- A player with no legal move: The immobilized player immediately loses the game per R5.
- Repetition / cycles: Bounded strictly by R6 (threefold repetition and 50-move rule), guaranteeing termination.
- Simultaneous claims on the same resource: Not applicable — vertices are occupied sequentially.
- Player elimination mid-round: Reduction to 2 pieces triggers immediate game loss.
- Resource exhaustion: Pieces removed from the board are permanently eliminated and cannot re-enter.
- Termination guarantee: Captures reduce the total pieces strictly from 18 toward 4, and endless non-capturing loops are terminated by the 50-move rule.
## State representation
- Persistent state:
- `board` (24-element array: `0 = Player 0`, `1 = Player 1`, `-1 = EMPTY`).
- `unplaced_pieces` (2-element array `[count_0, count_1]`).
- `on_board_pieces` (2-element array `[count_0, count_1]`).
- `active_player` (0 or 1).
- `game_phase` (1 = PLACEMENT, 2 = MOVEMENT, 3 = FLYING).
- `halfmove_clock` (integer tracking moves since last capture).
- `position_history` (hash map tracking position frequencies).
- Per-turn ephemeral state:
- `formed_mill_this_turn` (boolean).
- `pending_capture` (boolean).
- Observable information: Fully observable — complete board graph and piece counts are public.
## Action space
- `place_piece(v)`:
- Phase 1 only. Precondition: `board[v] == EMPTY`.
- `move_piece(v_from, v_to)`:
- Phase 2/3. Precondition: `board[v_from] == active_player`, `board[v_to] == EMPTY`, and (`(v_from, v_to) in E` or `on_board_pieces[active_player] == 3`).
- `remove_piece(v_target)`:
- Triggered after forming a mill. Precondition: `board[v_target] == 1 - active_player` and valid per R2 capture priority.
## Playability notes
- Single-player-vs-AI: Engine-ready perfect-information abstract strategy game. Easily solved or evaluated with Minimax / Alpha-Beta pruning or MCTS.
- Group games (n>4): Strictly a 2-player game.
- Physical-skill games: Purely mathematical discrete board game with zero physical randomness.
- What is lost in the adaptation: The historical ambiance of moving smooth river pebbles across 1,500-year-old rock carvings at Sigiriya or Anuradhapura.
## Implementation hints
Standard graph representation. Define adjacency list of 24 nodes and 16 3-tuples for valid mills. Branching factor is ~10–18 in placement phase, ~4–10 in movement phase. Milestone 1: implement graph topology, mill detection, 2-phase state machine, and Alpha-Beta AI bot in under 200 lines.
Download as JSON
Download the full game corpus entry for this game as structured JSON.
Download JSONCite this page
Nerenchi Keliya (Sri Lanka). (n.d.). Games of Countries. https://gamesofcountries.com/games/lk-sri-lanka/nerenchi-keliya
@misc{gamesofcountries-lk-sri-lanka-nerenchi-keliya,
title = {Nerenchi Keliya (Sri Lanka)},
year = {n.d.},
publisher = {Games of Countries},
url = {https://gamesofcountries.com/games/lk-sri-lanka/nerenchi-keliya}
}