-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAI_DEV_REFERENCE.py
More file actions
116 lines (98 loc) · 3.9 KB
/
Copy pathAI_DEV_REFERENCE.py
File metadata and controls
116 lines (98 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""
Bao la Kiswahili — AI Module Developer Reference
This file documents the public API that all AI/analysis/training/UI modules
must use. Read this before writing any module.
## Core Classes (bao.board)
### GameState
- .board: BaoBoard (4x8 grid of seed counts)
- .hands: dict {SOUTH: int, NORTH: int} — seeds in hand (nemo)
- .phase: str 'namua' | 'mtaji'
- .turn: str 'south' | 'north'
- .nyumba_status: dict {SOUTH: str, NORTH: str} — 'functional' | 'destroyed'
- .captures: dict {SOUTH: int, NORTH: int} — total captured seeds
- .move_count: int
- .move_history: list[MoveResult]
- .takasia_pits: dict {player: set of (row, col)}
Methods:
- .clone() -> GameState (deep copy for search)
- .is_nyumba(player, row, col) -> bool
- .is_functional_nyumba(player, row, col) -> bool
- .destroy_nyumba(player) -> None
- .switch_turn() -> None
### BaoBoard
- .grid: list[list[int]] 4 rows x 8 cols
- .get(row, col) -> int
- .set(row, col, value)
- .add(row, col, amount=1)
- .take_all(row, col) -> int (removes and returns all seeds)
- .is_empty(row, col) -> bool
- .clone() -> BaoBoard
- .total_seeds() -> int
- .player_seeds(player) -> int (both rows)
- .inner_row_seeds(player) -> int
### Move
- .move_type: str 'namua' | 'mtaji'
- .player: str 'south' | 'north'
- .col: int (namua: inner row col; mtaji: pit col)
- .row: int (mtaji: pit row; namua: -1)
- .direction: str 'cw' | 'ccw' (for non-capture sowing choice)
- .is_capture: bool
- .safari_choice: bool (True = continue from nyumba)
### MoveResult
- .move: Move
- .player: str
- .seeds_captured: int
- .laps: int
- .ended_in_nyumba: bool
- .nyumba_destroyed: bool
- .phase_after: str
- .board_before: BaoBoard
- .board_after: BaoBoard
## Engine Functions (bao.engine)
- get_valid_moves(state, player) -> list[Move]
- execute_move(state, move) -> MoveResult (mutates state!)
- check_game_over(state) -> str | None (returns winner or None)
- is_terminal(state) -> bool
- winner(state) -> str | None
- seed_difference(state, player) -> int
- count_seeds(state, player) -> int (board + hand)
- is_marker(state, player, row, col) -> bool
- has_capture_available(state, player) -> bool
- has_mtaji_capture(state, player) -> bool
- build_sow_path(player, direction, start_row, start_col, length) -> list[(row,col)]
- get_board_display(state) -> str
## Config Constants (bao.config)
SOUTH = 'south', NORTH = 'north'
NAMUA = 'namua', MTAJI = 'mtaji'
CCW = 'ccw', CW = 'cw'
OPPONENT = {SOUTH: NORTH, NORTH: SOUTH}
PLAYER_INNER_ROW = {SOUTH: 2, NORTH: 1}
PLAYER_BACK_ROW = {SOUTH: 3, NORTH: 0}
PLAYER_NYUMBA_COL = {SOUTH: 3, NORTH: 4}
PLAYER_RIGHT_KICHWA = {SOUTH: 0, NORTH: 7}
PLAYER_LEFT_KICHWA = {SOUTH: 7, NORTH: 0}
Rows: 0=N-back, 1=N-inner, 2=S-inner, 3=S-back
## AI Base Class (bao.ai.base)
class BaoAI(ABC):
def __init__(self, name, **kwargs)
@abstractmethod
def select_move(self, state) -> Move | None
def evaluate(self, state, player) -> float (override this!)
@property
def name(self) -> str
def reset(self) -> None
def get_stats(self) -> dict
All AI modules MUST:
1. Inherit from BaoAI
2. Implement select_move(state) -> Move
3. Call self.nodes_evaluated += 1 in search loops
4. Accept **kwargs in __init__ and pass to super()
5. Be importable without side effects
## Module File Conventions
- Each module is one .py file in the appropriate package
- File starts with a docstring describing the strategy
- Classes use PascalCase, functions use snake_case
- No external dependencies beyond Python stdlib + bao package
- Each file is self-contained (imports from bao.* only)
- Include a __all__ list
"""