|
Othello 1.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.drexel.cs.ai.othello.GameState
public class GameState
A class for storing all aspects of the game state of Othello, including the board state and current player. This class also includes utilities such as a successor function.
| Nested Class Summary | |
|---|---|
static class |
GameState.GameStatus
An enumeration of the possible states of the game. |
static class |
GameState.Player
An enumeration of the possible owners of a square in the game board. |
| Constructor Summary | |
|---|---|
GameState()
Constructs a new GameState with the initial board
configuration, a random initial player, and the random number
generator seeded to a random value. |
|
GameState(long randomNumberGeneratorSeed)
Creates a new GameState with the initial board configuration, a random initial player, and the random number generator seeded to the given value. |
|
| Method Summary | |
|---|---|
GameState |
applyMove(Square move)
Equivalent to applyMove(move, true). |
GameState |
applyMove(Square move,
boolean includePreviousStateReference)
Returns the GameState resulting from applying the given move to this state. |
java.lang.Object |
clone()
Returns a copy of this GameState. |
boolean |
equals(java.lang.Object o)
Returns whether or not o is equivalent to this
GameState. |
GameState.Player |
getCurrentPlayer()
Returns the player whose turn it is to make a move. |
GameState.Player |
getOpponent(GameState.Player player)
Returns the opponent of a player. |
Square |
getPreviousMove()
Returns the previous move that was used to get to this state (or null if this is the initial state). |
GameState |
getPreviousState()
Returns the previous state (or null if this is the
initial state). |
java.util.Random |
getRandom()
Returns the random number generator for this game. |
int |
getScore(GameState.Player player)
Returns the number of spaces currently owned by the given player. |
GameState.Player |
getSquare(int row,
int col)
Returns the player that currently owns the given square. |
GameState.Player |
getSquare(Square square)
Returns the player that currently owns the given square. |
GameState.GameStatus |
getStatus()
Returns the current status of the game. |
java.util.AbstractSet<GameState> |
getSuccessors()
Equivalent to getSuccessors(true). |
java.util.AbstractSet<GameState> |
getSuccessors(boolean includePreviousStateReference)
Returns all valid GameStates that may succeed this state. |
java.util.AbstractSet<Square> |
getValidMoves()
Returns all valid Moves that may be taken from this state. |
java.util.AbstractSet<Square> |
getValidMoves(GameState.Player player)
Returns all valid Moves that may be taken by player from this state. |
GameState.Player |
getWinner()
Returns the winner of the game or null if the game
was either a tie or the game has not yet finished. |
int |
hashCode()
Equivalent to calling hashCode() on the result of uniqueHashCode(). |
boolean |
isLegalMove(Square move,
GameState.Player player)
Returns true if and only if move is
legal for player. |
static void |
main(java.lang.String[] args)
|
java.lang.String |
toString()
Returns a string representation of the game board. |
java.math.BigInteger |
uniqueHashCode()
Returns a unique number identifying this GameState. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public GameState()
GameState with the initial board
configuration, a random initial player, and the random number
generator seeded to a random value.
public GameState(long randomNumberGeneratorSeed)
| Method Detail |
|---|
public java.lang.Object clone()
clone in class java.lang.Objectpublic GameState.Player getCurrentPlayer()
public java.util.Random getRandom()
public GameState.Player getOpponent(GameState.Player player)
public GameState.Player getSquare(int row,
int col)
public GameState.Player getSquare(Square square)
public boolean isLegalMove(Square move,
GameState.Player player)
true if and only if move is
legal for player.
public java.util.AbstractSet<Square> getValidMoves()
public java.util.AbstractSet<Square> getValidMoves(GameState.Player player)
player from this state.
public int getScore(GameState.Player player)
public GameState.Player getWinner()
null if the game
was either a tie or the game has not yet finished.
public GameState.GameStatus getStatus()
public java.util.AbstractSet<GameState> getSuccessors()
getSuccessors(true).
getSuccessors(boolean)public java.util.AbstractSet<GameState> getSuccessors(boolean includePreviousStateReference)
Note that if includePreviousStateReference is
false, the returned states will return
null when getPreviousState() is called.
This is useful to reduce memory if the back-references are not
required.
includePreviousStateReference - whether or not the returned states should have back-references to this.applyMove(Square, boolean)
public GameState applyMove(Square move)
throws InvalidMoveException
applyMove(move, true).
InvalidMoveExceptionapplyMove(Square,boolean)
public GameState applyMove(Square move,
boolean includePreviousStateReference)
throws InvalidMoveException
applyMove does not apply the given move
to the current state; it does not in any way alter
this. Instead, applyMove
returns the state that results from making
the given move in the current state.
Note that if includePreviousStateReference is
false, the returned state will return
null when getPreviousState() is called.
This is useful to save memory if the back-references to
previous states are not required (i.e. the previous
states may be garbage collected).
includePreviousStateReference - whether or not the returned state should have a back-reference to this.
InvalidMoveException - if move is not a valid move from this state.public GameState getPreviousState()
null if this is the
initial state). This function may also return
null if this was created without a
back-reference to the previous state (to save memory).
applyMove(Square, boolean)public Square getPreviousMove()
null if this is the initial state).
public java.lang.String toString()
Example:
a b c d e f g h [@=2 O=5]
0 . . . . . . . .
1 . . . . . . . .
2 . . . O . . . .
3 . . . O O . . .
4 . . @ O @ . . .
5 . . O . . . . .
6 . . . . . . . .
7 . . . . . . . .
toString in class java.lang.Objectpublic boolean equals(java.lang.Object o)
o is equivalent to this
GameState.
equals in class java.lang.ObjectuniqueHashCode(),
hashCode()public java.math.BigInteger uniqueHashCode()
| The following are always true: | |||
x.uniqueHashCode() == y.uniqueHashCode() | ⇒ | x.equals(y) | |
x.equals(y) | ⇒ | x.uniqueHashCode() == y.uniqueHashCode() | |
x.equals(y) | ⇒ | x.hashCode() == y.hashCode() | |
| However, the following are not necessarily true: | |||
x.hashCode() == y.hashCode() | ⇒ | x.equals(y) | |
equals(Object),
hashCode()public int hashCode()
hashCode() on the result of uniqueHashCode().
hashCode in class java.lang.Objectequals(Object),
hashCode()public static void main(java.lang.String[] args)
|
Othello 1.0 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||