Connect4State

com.phasmidsoftware.gambit.examples.connect4.Connect4State

State[Connect4, Connect4] typeclass instance for Connect4.

P = S = Connect4: the proto-state and state are the same type. construct takes (newState, previousState) and returns newState.

Attributes

Graph
Supertypes
trait Ordering[Connect4]
trait PartialOrdering[Connect4]
trait Equiv[Connect4]
trait Serializable
trait Comparator[Connect4]
class Object
trait Matchable
class Any
Show all
Self type

Members list

Type members

Inherited classlikes

class OrderingOps(lhs: Ordering.this.T)

Attributes

Inherited from:
Ordering
Supertypes
class Object
trait Matchable
class Any

Value members

Concrete methods

Abstract method to construct an S from a P and an S.

Abstract method to construct an S from a P and an S.

Value parameters

proto

a (P, S) tuple.

Attributes

Returns

an S.

def heuristic(s: Connect4): Double

Heuristic from the perspective of the player who just moved (s.player). Positive = good for the player who just moved.

Heuristic from the perspective of the player who just moved (s.player). Positive = good for the player who just moved.

Terminal positions: s.player just won → Double.MaxValue s.player just lost → Double.MinValue draw → 0.0

Non-terminal: score for the player who just moved minus score for the opponent, plus center column bonus.

Attributes

def isGoal(s: Connect4): Option[Boolean]

Goal detection: Some(true) — there is a winner Some(false) — board is full, with no winner (draw) None — game is still in progress

Goal detection: Some(true) — there is a winner Some(false) — board is full, with no winner (draw) None — game is still in progress

Attributes

def isValid(s: Connect4): Boolean

Abstract method to determine if an S is valid.

Abstract method to determine if an S is valid.

Value parameters

s

an S.

Attributes

Returns

a Boolean.

def isWin(s: Connect4): Boolean

Method to determine if s is a winning state. NOTE: it makes no sense to invoke isWin unless the result of isGoal is Some(true).

Method to determine if s is a winning state. NOTE: it makes no sense to invoke isWin unless the result of isGoal is Some(true).

Value parameters

s

an S

Attributes

Returns

true if s is a win, else false.

Legal moves: one Transition per open column.

Legal moves: one Transition per open column.

Attributes

def render(s: Connect4): String

Method to render a State as a String.

Method to render a State as a String.

Value parameters

s

the State to render.

Attributes

Returns

a String representation of s.

def sequence(s: Connect4): Int

A significant sequence value that distinguishes this state from others. Typically the number of moves made so far (0 for the starting state). Used to determine whose turn it is via isFirstPlayerToMove.

A significant sequence value that distinguishes this state from others. Typically the number of moves made so far (0 for the starting state). Used to determine whose turn it is via isFirstPlayerToMove.

Value parameters

s

the state.

Attributes

Inherited methods

def compare(s1: Connect4, s2: Connect4): Int

Method to determine the ordering of two States. It is based on the heuristic.

Method to determine the ordering of two States. It is based on the heuristic.

Value parameters

s1

first S.

s2

second S.

Attributes

Returns

<0 if s1 < s2, >0 if s1 > s2, else 0.

Inherited from:
State
override def equiv(x: Connect4, y: Connect4): Boolean

Attributes

Definition Classes
Ordering -> PartialOrdering -> Equiv
Inherited from:
Ordering
def getStates(s: Connect4): Seq[Connect4]

Concrete method to get the possible states to follow the given state s. The resulting sequence is in no particular order.

Concrete method to get the possible states to follow the given state s. The resulting sequence is in no particular order.

Value parameters

s

an S.

Attributes

Returns

a sequence of S instances which are the possible states to follow s.

Inherited from:
State
override def gt(x: Connect4, y: Connect4): Boolean

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
override def gteq(x: Connect4, y: Connect4): Boolean

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
def isFirstPlayerToMove(s: Connect4): Boolean

Returns true if it is the first player's turn to move from state s.

Returns true if it is the first player's turn to move from state s.

To be completely unambiguous: the first player is the one who makes the very first move of the game. isFirstPlayerToMove(s) returns true when it is that player's turn again — e.g., for a two-player game, when an even number of moves have been made (sequence 0, 2, 4, ...).

It returns false when it is the second (or any subsequent) player's turn — i.e., when an odd number of moves have been made (sequence 1, 3, 5, ...).

Example (TicTacToe): empty board (sequence=0) → true (X moves first) after X plays (sequence=1) → false (O moves next) after O plays (sequence=2) → true (X moves next)

For games with more than two players, override this method as needed.

Value parameters

s

the current state.

Attributes

Returns

true if the first player is to move, false otherwise.

Inherited from:
State
def isReverseOf(other: Ordering[_]): Boolean

Attributes

Inherited from:
Ordering
override def lt(x: Connect4, y: Connect4): Boolean

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
override def lteq(x: Connect4, y: Connect4): Boolean

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
def max[U <: Connect4](x: U, y: U): U

Attributes

Inherited from:
Ordering
def min[U <: Connect4](x: U, y: U): U

Attributes

Inherited from:
Ordering
def on[U](f: U => Connect4): Ordering[U]

Attributes

Inherited from:
Ordering
def orElse(other: Ordering[Connect4]): Ordering[Connect4]

Attributes

Inherited from:
Ordering
def orElseBy[S](f: Connect4 => S)(implicit ord: Ordering[S]): Ordering[Connect4]

Attributes

Inherited from:
Ordering
override def reverse: Ordering[Connect4]

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
def reversed(): Comparator[Connect4]

Attributes

Inherited from:
Comparator
def thenComparing[U <: Comparable[_ >: U <: <FromJavaObject>]](x$0: Function[_ >: Connect4 <: <FromJavaObject>, _ <: U]): Comparator[Connect4]

Attributes

Inherited from:
Comparator
def thenComparing[U <: <FromJavaObject>](x$0: Function[_ >: Connect4 <: <FromJavaObject>, _ <: U], x$1: Comparator[_ >: U <: <FromJavaObject>]): Comparator[Connect4]

Attributes

Inherited from:
Comparator
def thenComparing(x$0: Comparator[_ >: Connect4 <: <FromJavaObject>]): Comparator[Connect4]

Attributes

Inherited from:
Comparator
def thenComparingDouble(x$0: ToDoubleFunction[_ >: Connect4 <: <FromJavaObject>]): Comparator[Connect4]

Attributes

Inherited from:
Comparator
def thenComparingInt(x$0: ToIntFunction[_ >: Connect4 <: <FromJavaObject>]): Comparator[Connect4]

Attributes

Inherited from:
Comparator
def thenComparingLong(x$0: ToLongFunction[_ >: Connect4 <: <FromJavaObject>]): Comparator[Connect4]

Attributes

Inherited from:
Comparator
def tryCompare(x: Connect4, y: Connect4): Some[Int]

Attributes

Inherited from:
Ordering

Implicits

Inherited implicits

implicit def mkOrderingOps(lhs: Connect4): OrderingOps

Attributes

Inherited from:
Ordering