[TicTacToe] step: reuse computed board, hoist win lines to a constant#1322
Open
gweber wants to merge 1 commit into
Open
[TicTacToe] step: reuse computed board, hoist win lines to a constant#1322gweber wants to merge 1 commit into
gweber wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Game.stepin tic-tac-toe had two small redundancies: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 reusingboard.This reuses the already-computed
board(one scatter instead of two) and lifts the win lines to a module-levelWIN_LINESconstant.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.