Matchboxes

com.phasmidsoftware.gambit.examples.tictactoe.Matchboxes
See theMatchboxes companion object
class Matchboxes

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.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def get(ttt: TicTacToe): Matchbox

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.

def selectMove(ttt: TicTacToe, random: Random): Option[Int]

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.

def size: Int

Number of distinct matchboxes created so far.

Number of distinct matchboxes created so far.

Attributes

def totalBeads: Int

Total beads across all matchboxes (useful for diagnostics).

Total beads across all matchboxes (useful for diagnostics).

Attributes

def update(ttt: TicTacToe, cell: Int, result: BeadResult): Unit

Update the Matchbox for the given position after a game result. The cell index is in the original orientation (as returned by selectMove).

Update the Matchbox for the given position after a game result. The cell index is in the original orientation (as returned by selectMove).

Value parameters

cell

the flat cell index (0..8, row-major) in original orientation.

result

the game result from the perspective of the player who owns this matchbox.

ttt

the TicTacToe position at the time the move was made.

Attributes