Skip to content

Commit

Permalink
[Go] Add step_count (#1155)
Browse files Browse the repository at this point in the history
  • Loading branch information
sotetsuk authored Jan 9, 2024
1 parent 3fbe27c commit 296b845
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pgx/_src/games/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class GameState(NamedTuple):
color: Array = jnp.int32(0) # 0 = black, 1 = white
step_count: Array = jnp.int32(0)
# ids of representative stone id (smallest) in the connected stones
# positive for black, negative for white, and zero for empty.
chain_id_board: Array = jnp.zeros(19 * 19, dtype=jnp.int32)
Expand All @@ -31,6 +31,10 @@ class GameState(NamedTuple):
ko: Array = jnp.int32(-1) # by SSK
is_psk: Array = jnp.bool_(False)

@property
def color(self) -> Array:
return self.step_count % 2

@property
def size(self) -> int:
return int(jnp.sqrt(self.chain_id_board.shape[-1]).astype(jnp.int32).item())
Expand All @@ -57,7 +61,7 @@ def step(self, state: GameState, action: Array) -> GameState:
lambda: _apply_pass(state),
)
# increment turns
state = state._replace(color=(state.color + 1) % 2)
state = state._replace(step_count=state.step_count + 1)
# update board history
board_history = jnp.roll(state.board_history, self.size**2)
board_history = board_history.at[0].set(jnp.clip(state.chain_id_board, -1, 1).astype(jnp.int32))
Expand Down

0 comments on commit 296b845

Please sign in to comment.