Skip to content

SearchGame

Defined in: src/modules/game-search/game.ts:11

The rules of a turn-based game as four functions over plain states, with no world: all a search needs. S is the game state, M a move, P the player id (default number).

A state is final when moves returns an empty list; a game with forced passes models the pass as a move. Chance (dice, shuffles) lives in the state, for example a SeededRng’s state field, so apply stays deterministic.

S

M

P = number

apply: (state, move) => S

Defined in: src/modules/game-search/game.ts:16

A new state with move played; never mutates state, and returns the same result for the same arguments.

S

M

S


currentPlayer: (state) => P

Defined in: src/modules/game-search/game.ts:18

Who moves in state, compared with ===. Only called on non-final states.

S

P


moves: (state) => readonly M[]

Defined in: src/modules/game-search/game.ts:24

The legal moves in state, or [] once the game is over. Returns the same order for the same state; searches try moves in that order, so list likely-good moves first.

S

readonly M[]


outcome: (state, player) => number

Defined in: src/modules/game-search/game.ts:26

The result of a final state for player: -1 a loss, 0 a draw, 1 a win.

S

P

number