Matchbox

com.phasmidsoftware.gambit.examples.tictactoe.Matchbox
See theMatchbox companion object
case class Matchbox(beads: Map[Int, Int])

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
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def moveCount: Int

The number of distinct moves this matchbox knows about.

The number of distinct moves this matchbox knows about.

Attributes

def penalise(cell: Int, delta: Int = ..., floor: Int = ...): Matchbox

Penalise: remove delta beads from the given cell, floored at floor. Used after a loss.

Penalise: remove delta beads from the given cell, floored at floor. Used after a loss.

Value parameters

cell

the cell index that was played.

delta

the number of beads to remove (typically 1 for a loss).

floor

the minimum bead count (default 1, so a move is never impossible).

Attributes

Returns

a new Matchbox with updated beads.

def reward(cell: Int, delta: Int = ...): Matchbox

Reward: add delta beads to the given cell. Used after a win.

Reward: add delta beads to the given cell. Used after a win.

Value parameters

cell

the cell index that was played.

delta

the number of beads to add (typically 3 for a win).

Attributes

Returns

a new Matchbox with updated beads.

def select(random: Random): Option[Int]

Select a move by weighted random sampling over the bead counts. Returns None if the matchbox is empty (should not happen in normal play).

Select a move by weighted random sampling over the bead counts. Returns None if the matchbox is empty (should not happen in normal play).

Value parameters

random

a Random instance for reproducibility.

Attributes

Returns

Some(cellIndex) or None.

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

Definition Classes
Any
def totalBeads: Int

Total beads across all moves.

Total beads across all moves.

Attributes

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product