TicTacToe

com.phasmidsoftware.gambit.examples.tictactoe.TicTacToe
See theTicTacToe companion object
case class TicTacToe(board: Board, maybePrior: Option[TicTacToe] = ...)

Case class to represent a TicTacToe state (layout).

Value parameters

board

the current state.

maybePrior

the prior state.

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Type members

Types

Defines a Matching type which takes a Row and returns a Cell.

Defines a Matching type which takes a Row and returns a Cell.

Attributes

Value members

Concrete methods

def draw: Option[Boolean]

Method to determine if this layout is a draw, i.e. no side can ever win.

Method to determine if this layout is a draw, i.e. no side can ever win.

TODO figure out a better way to determine a draw.

Attributes

Returns

Some(false) if it's a draw, else None.

override def equals(obj: Any): Boolean

Equals method based on the board only.

Equals method based on the board only.

Attributes

Returns

Boolean.

Definition Classes
Equals -> Any
override def hashCode(): Int

HashCode method based on the board only (not prior).

HashCode method based on the board only (not prior).

Attributes

Returns

a hashCode.

Definition Classes
Any
def maskMatch(mask: Int, pattern: Int)(b1: Board, b2: Board): Boolean

Value parameters

b1

a Board.

b2

another Board.

Attributes

Returns

true if the XOR of the two boards masked by mask is equal to pattern.

def oppositeCorner(opponent: Boolean): Boolean

Value parameters

opponent

if true then the opposite corner must be the opponent.

Attributes

Returns

true if this TicTacToe is a corner position and if the opponent (if true, else self) occupies the opposite corner.

def play(xOrO: Boolean)(row: Int, col: Int): Prototype

Method to create a new TicTacToe from this TicTacToe.

Method to create a new TicTacToe from this TicTacToe.

Value parameters

col

the column at which the mark should be made.

row

the row at which the mark should be made.

xOrO

true if X is to play, false otherwise.

Attributes

Returns

a new Board with the appropriate cell (i.e., square) marked.

def play0: (Int, Int) => Prototype

Function to make a play for the 0 player at a cell.

Function to make a play for the 0 player at a cell.

Attributes

def playX: (Int, Int) => Prototype

Function to make a play for the X player at a cell.

Function to make a play for the X player at a cell.

Attributes

def render(newlines: Boolean = ...): String

Method to create a string of Xs and 0s corresponding to this TicTacToe position. Also includes the heuristic for the position.

Method to create a string of Xs and 0s corresponding to this TicTacToe position. Also includes the heuristic for the position.

CONSIDER adding a parameter to allow dropping the heuristic.

Attributes

Returns

a String that is a rendition of the current state.

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product

Concrete fields

lazy val block: Cell

Method to determine whether there is a block by one player against his opponent.. The line may be horizontal (a row), vertical (a column) or diagonal.

Method to determine whether there is a block by one player against his opponent.. The line may be horizontal (a row), vertical (a column) or diagonal.

Attributes

Returns

Some(b) if there is a line of 0X0 or similar otherwise None. The Boolean b is true for player X, and false for player 0.

lazy val corner: Boolean
lazy val currentMove: Board
lazy val fork: Cell

Method to determine whether there are two potential wins. The lines may be horizontal (a row), vertical (a column) or diagonal and missing one element.

Method to determine whether there are two potential wins. The lines may be horizontal (a row), vertical (a column) or diagonal and missing one element.

Attributes

Returns

true if there is a line of two similar marks with a space between in this TicTacToe. The Boolean b is true for player X, and false for player 0.

lazy val history: List[String]

The history of a TicTacToe position, as a String.

The history of a TicTacToe position, as a String.

NOTE: it seems that this is a general method, not specific to TicTacToe

Attributes

lazy val maybeOpponentMove: Option[Board]
lazy val maybePreviousMove: Option[Board]
lazy val open: Seq[(Int, Int)]

The list of open cells for this TicTacToe.

The list of open cells for this TicTacToe.

Attributes

Returns

a sequence of (Int, Int) tuples corresponding to the row, column indices.

lazy val oppHasCenter: Boolean
lazy val player: Boolean

Method to determine which player was responsible for creating this state. The empty state will yield false (0 player). A goal state will yield the winner.

Method to determine which player was responsible for creating this state. The empty state will yield false (0 player). A goal state will yield the winner.

Attributes

Returns

true for the first player (X), false for the second player (0)

lazy val potentialWin: Cell

Method to determine whether there is a potential win. The line may be horizontal (a row), vertical (a column) or diagonal and missing one element.

Method to determine whether there is a potential win. The line may be horizontal (a row), vertical (a column) or diagonal and missing one element.

Attributes

Returns

true if there is a line of two similar marks with a space between in this TicTacToe. The Boolean b is true for player X, and false for player 0.

lazy val weHaveOppositeCorner: Boolean
lazy val win: Cell

Method to determine whether there is a line of marks for one player. The line may be horizontal (a row), vertical (a column) or diagonal.

Method to determine whether there is a line of marks for one player. The line may be horizontal (a row), vertical (a column) or diagonal.

Attributes

Returns

Some(b) if there is a line of similar marks in this TicTacToe otherwise None. The Boolean b is true for player X, and false for player 0.