com.phasmidsoftware.gambit.examples.tictactoe
Members list
Type members
Classlikes
This class represents 9 x 2 bits, at the high end of the 32-bit word.
This class represents 9 x 2 bits, at the high end of the 32-bit word.
NOTE: this used to extend AnyVal before we added the sequence parameter.
Value parameters
- value
-
the bit value of this board. NOTE: that the low 14 bits of this value should always be zero.
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Supertypes
-
trait Singletontrait Producttrait Mirrortrait Serializabletrait Producttrait Equalstrait BeadResultclass Objecttrait Matchableclass AnyShow all
- Self type
-
Draw.type
A player that uses the existing heuristic (TicTacToeState$.heuristic) to greedily pick the best available move. Useful as a strong baseline.
Attributes
- Supertypes
-
trait Singletontrait Producttrait Mirrortrait Serializabletrait Producttrait Equalstrait BeadResultclass Objecttrait Matchableclass AnyShow all
- Self type
-
Loss.type
A Matchbox represents one position in the MENACE machine. It holds a bead count for each legal move (open cell index 0..8). Weighted random selection picks a move proportional to bead counts. After a game, beads are added (win) or removed (loss), with a floor of 1.
A Matchbox represents one position in the MENACE machine. It holds a bead count for each legal move (open cell index 0..8). Weighted random selection picks a move proportional to bead counts. After a game, beads are added (win) or removed (loss), with a floor of 1.
Value parameters
- beads
-
a Map from cell index (0..8, row-major) to bead count.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
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.
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
- Supertypes
-
class Objecttrait Matchableclass Any
Attributes
- Companion
- class
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
Matchboxes.type
A MENACE player backed by a shared Matchboxes registry. Records the sequence of (position, move) pairs during a game so it can back-propagate the result afterwards.
A MENACE player backed by a shared Matchboxes registry. Records the sequence of (position, move) pairs during a game so it can back-propagate the result afterwards.
All cell indices in history are in original board orientation, matching what selectMove returns and what update expects.
Pl = Boolean: true = X (first player), false = O (second player).
Value parameters
- matchboxes
-
the shared registry.
Attributes
- Supertypes
Implicit class Outcome which allows for two Option[Int] values to be combined.
Implicit class Outcome which allows for two Option[Int] values to be combined.
NOTE: currently this class is not used.
Value parameters
- x
-
an Option[Int] on the left of the &
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
A perfect TicTacToe player built by running a full minimax evaluation over the game DAG using Visitor's post-order DFS.
A perfect TicTacToe player built by running a full minimax evaluation over the game DAG using Visitor's post-order DFS.
Construction (once, on first use):
- A mutable score map
Map[TicTacToe, Int]is allocated. - A
given Evaluable[TicTacToe, Int]closes over the map; for terminal positions it scores directly; for internal positions it reads children's scores from the map (already populated in post-order). Traversal.dfsis called withDfsOrder.PostfromTicTacToe.start. The defaultgiven VisitedSet[TicTacToe]ensures each position is evaluated exactly once (DAG, not tree).- The completed score map drives
chooseMove.
Minimax convention:
- X maximises (score +1 = X wins, 0 = draw, -1 = O wins).
- O minimises.
TicTacToe.playeris true when it was X's turn to produce this board (i.e., X just moved), so when choosing the next move, we look at whose turn it is, which is!ttt.playerfor the node just settled.
Scores in the map are from X's perspective throughout.
Attributes
- Supertypes
A player that selects moves uniformly at random. Useful as a baseline opponent for MENACE to learn against.
Case class to represent a TicTacToe state (layout).
Case class to represent a TicTacToe state (layout).
Value parameters
- board
-
the current state.
- maybePrior
-
the prior state.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
Factory for a TicTacToe GameRunner. Requires an implicit State[Board, TicTacToe] in scope.
Factory for a TicTacToe GameRunner. Requires an implicit State[Board, TicTacToe] in scope.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
TicTacToeGameRunner.type
Shared utility methods for TicTacToe cell operations.
Shared utility methods for TicTacToe cell operations.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
TicTacToeUtils.type
Attributes
- Supertypes
-
trait Singletontrait Producttrait Mirrortrait Serializabletrait Producttrait Equalstrait BeadResultclass Objecttrait Matchableclass AnyShow all
- Self type
-
Win.type
Types
If there is a "cell" (a matching square in the 3x3 grid), then: Some(true) for player X, and Some(false) for player 0. else None (no match).
If there is a "cell" (a matching square in the 3x3 grid), then: Some(true) for player X, and Some(false) for player 0. else None (no match).
Attributes
Representation of a row (or column or diagonal) of a TicTacToe state. Only the six low bits are significant.
Representation of a row (or column or diagonal) of a TicTacToe state. Only the six low bits are significant.
CONSIDER using Row(x: Int) extends AnyVal
Attributes
Representation of a Row with a bit mask representing the difference between two states.
Representation of a Row with a bit mask representing the difference between two states.
Attributes
Value members
Concrete methods
Demonstrates TicTacToe games between all four player types. Each distinct pair plays twice — home (X) and away (O) — to account for the first-mover advantage X enjoys in TicTacToe.
Demonstrates TicTacToe games between all four player types. Each distinct pair plays twice — home (X) and away (O) — to account for the first-mover advantage X enjoys in TicTacToe.
Attributes
Play a single TicTacToe game, printing each move with board and heuristic.
Play a single TicTacToe game, printing each move with board and heuristic.
Attributes
Render a TicTacToe board with its heuristic score.
Render a TicTacToe board with its heuristic score.
Attributes
Givens
Givens
The Game typeclass instance for TicTacToe.
The Game typeclass instance for TicTacToe.
S = TicTacToe M = Int (flat cell index, 0..8 row-major) Pl = Boolean (true = X, moves first; false = O, moves second)
Attributes
Implicits
Implicits
Implicit class Outcome which allows for two Option[Int] values to be combined.
Implicit class Outcome which allows for two Option[Int] values to be combined.
NOTE: currently this class is not used.
Value parameters
- x
-
an Option[Int] on the left of the &