State

com.phasmidsoftware.gambit.game.State
trait State[P, S] extends Ordering[S]

Type class for a State. A State is a position in a game or other situation which requires heuristically-directed tree search. For example, a State might describe a board position in Tic-tac-toe or Chess.

NOTE that State depends on Transition. CONSIDER eliminating Transition such that all logic is defined by State.

Type parameters

P

a proto-state, that's to say a type such that a P, S tuple can be converted into a new S.

S

the underlying type on which the state is based.

Attributes

Graph
Supertypes
trait Ordering[S]
trait PartialOrdering[S]
trait Equiv[S]
trait Serializable
trait Comparator[S]
class Object
trait Matchable
class Any
Show all
Known subtypes

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

Abstract methods

def construct(proto: (P, S)): S

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: S): Double

Abstract method to determine an estimate of an S's efficacy in reaching a goal.

Abstract method to determine an estimate of an S's efficacy in reaching a goal.

Value parameters

s

an S.

Attributes

Returns

a Double (in a domain appropriate to the type S where a higher value is always believed to be closer to a goal).

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

Abstract method to determine if state s is a goal state. In some games, the goal is to win. In other games, for example, contract bridge, the goal is to achieve some measurable state, such as a certain number of tricks.

Abstract method to determine if state s is a goal state. In some games, the goal is to win. In other games, for example, contract bridge, the goal is to achieve some measurable state, such as a certain number of tricks.

Value parameters

s

an S.

Attributes

Returns

an Option of Boolean: if None then this state is not a goal state. If Some(true), then s achieves a goal. If Some(false), then such a goal is impossible to achieve.

def isValid(s: S): 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: S): 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.

def moves(s: S): Seq[Transition[P, S]]

Abstract method to determine the possible moves from the given S.

Abstract method to determine the possible moves from the given S.

Value parameters

s

an S.

Attributes

Returns

a sequence of Transition[S]

def render(s: S): 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: S): 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

Concrete methods

def compare(s1: S, s2: S): 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.

def getStates(s: S): Seq[S]

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.

def isFirstPlayerToMove(s: S): 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 methods

override def equiv(x: S, y: S): Boolean

Attributes

Definition Classes
Ordering -> PartialOrdering -> Equiv
Inherited from:
Ordering
override def gt(x: S, y: S): Boolean

Attributes

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

Attributes

Definition Classes
Ordering -> PartialOrdering
Inherited from:
Ordering
def isReverseOf(other: Ordering[_]): Boolean

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

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

Attributes

Inherited from:
Ordering

Implicits

Inherited implicits

implicit def mkOrderingOps(lhs: S): OrderingOps

Attributes

Inherited from:
Ordering