Skip to content

[TicTacToe] step: reuse computed board, hoist win lines to a constant#1322

Open
gweber wants to merge 1 commit into
sotetsuk:mainfrom
gweber:tictactoe-dedup-step
Open

[TicTacToe] step: reuse computed board, hoist win lines to a constant#1322
gweber wants to merge 1 commit into
sotetsuk:mainfrom
gweber:tictactoe-dedup-step

Conversation

@gweber

@gweber gweber commented Jun 10, 2026

Copy link
Copy Markdown

What

Game.step in tic-tac-toe had two small redundancies:

  • It computed board = state.board.at[action].set(state.color) for the win check, then recomputed the same scatter in _replace(board=state.board.at[action].set(state.color), ...) instead of reusing board.
  • It rebuilt the 8×3 win-line table as a literal on every call.

This reuses the already-computed board (one scatter instead of two) and lifts the win lines to a module-level WIN_LINES constant.

Behaviour

Pure refactor — no behavioural change. Verified that outputs (board, winner, color) match the previous implementation across 22.9k steps of random playouts, and the tic-tac-toe game-logic tests pass.

…tant

step recomputed state.board.at[action].set(state.color) a second time in
_replace instead of reusing the `board` it had just built for the win
check, and rebuilt the 8x3 win-line table as a literal on every call.
Reuse the board (one scatter instead of two) and lift the win lines to a
module-level WIN_LINES constant.

Pure refactor, behaviour identical: outputs match the previous
implementation across 22.9k steps of random playouts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant