Matchboxes is the MENACE registry: a mutable map from canonical board value to Matchbox. Canonicalization uses the 8-element dihedral group D4 (4 rotations × 2 for reflection via transpose), so symmetrically equivalent positions share one matchbox and learn together.
The canonical form of a board is the minimum value over all 8 D4 transforms. (Minimum is arbitrary but deterministic — any fixed choice from the orbit works.)
Note: exchange (swapping X and O bits) is NOT included in canonicalization here. X always moves first so X-positions and O-positions are structurally distinct in the learning signal. We can revisit this if we want to halve the matchbox count.
Retrieves the Matchbox corresponding to the provided TicTacToe position. If a Matchbox for the position does not exist, a new one is created, using its canonical form as the key.
Retrieves the Matchbox corresponding to the provided TicTacToe position. If a Matchbox for the position does not exist, a new one is created, using its canonical form as the key.
Value parameters
ttt
the TicTacToe position for which to retrieve or create a Matchbox.
Attributes
Returns
the Matchbox corresponding to the position in its canonical form.
Selects a move for the given TicTacToe game state by utilizing the matchbox strategy. If a matchbox exists for the canonical form of the board, a move is selected based on the matchbox's bead distribution; otherwise, a new matchbox is created. The selected move is returned in the original orientation of the board.
Selects a move for the given TicTacToe game state by utilizing the matchbox strategy. If a matchbox exists for the canonical form of the board, a move is selected based on the matchbox's bead distribution; otherwise, a new matchbox is created. The selected move is returned in the original orientation of the board.
Value parameters
random
the Random instance used for probabilistic move selection.
ttt
the current TicTacToe game state.
Attributes
Returns
an Option containing the selected move as an integer cell index (0 through 8, row-major) in the board's original orientation, or None if no valid moves are available.