rules
Class GameState

java.lang.Object
  extended by rules.GameState

public class GameState
extends Object

An AntichessGameState is a GameState specific to Antichess. It represents all the information needed to play the game, but not auxiliary information like history and times. An AntichessGameState is mutable.

Specification Fields

Constructor Summary
GameState()
          Construct the initial GameState, representing the starting board position.
GameState(Color p, int n, Board b)
          Construct an Antichess-specific GameState.
GameState(Color p, int n, String s)
          Construct an Antichess-specific GameState
GameState(Map<Position,Piece> powerupDiffs)
          Construct the initial GameState, representing the starting board position.
 
Method Summary
 String boardString()
          Return the String representation of the board
 boolean canMove()
           
 Color checkmater()
           
 void checkRep()
           
 GameState copy()
           
 Board getBoard()
           
 Color getCurrentColor()
           
 int getMoveNum()
           
 Map<Position,Piece> getPieceMap()
           
 Collection<Piece> getPieces()
           
 Color getWinner()
           
 int hashCode()
           
 boolean invalidState()
          Is the current state invalid, by the opposite color being in check?
 boolean isLegal(Move m)
           
 boolean isThreatened(Position pos, Color color)
          Does a color threaten a position? (occupying does not count).
 Collection<Move> legalMoves()
           
 void makeMove(Move m)
          Make a move
 Color piecesWinner()
           
 boolean reversibleMakeMove(Map<Position,Piece> m, boolean isForward)
          Modify the AntichessGameState to apply a move, and turn the map into its inverse.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GameState

public GameState(Color p,
                 int n,
                 Board b)
Construct an Antichess-specific GameState.

Requires:
p, n, b != null

GameState

public GameState(Color p,
                 int n,
                 String s)
Construct an Antichess-specific GameState

Requires:
  • p, n, b != null
  • s represents a valid input to board.fromString

GameState

public GameState()
Construct the initial GameState, representing the starting board position.


GameState

public GameState(Map<Position,Piece> powerupDiffs)
Construct the initial GameState, representing the starting board position.

Method Detail

checkRep

public void checkRep()

copy

public GameState copy()

getBoard

public Board getBoard()

getPieceMap

public Map<Position,Piece> getPieceMap()
Returns:
A map from positions to pieces, representing the state of the board.

getCurrentColor

public Color getCurrentColor()
Returns:
The color of the player whose turn it is.

piecesWinner

public Color piecesWinner()
Returns:
the Color who has lost all his pieces (or NONE)

checkmater

public Color checkmater()
Returns:
The Color of the player who has checkmated his opponent (or NONE)

getWinner

public Color getWinner()
Returns:
The Color of the player who has won (or NONE if no player has won yet).

toString

public String toString()
Overrides:
toString in class Object
Returns:
The string representation of the board (mainly for debugging).

getMoveNum

public int getMoveNum()
Returns:
the number of moves (by either player) since the beginning of the game.

canMove

public boolean canMove()
Returns:
whether the current player has any move other than a pass.

legalMoves

public Collection<Move> legalMoves()
Returns:
The set of legal moves from the current position. Always has at least one move in this set.

isThreatened

public boolean isThreatened(Position pos,
                            Color color)
Does a color threaten a position? (occupying does not count).

Requires:
pos != null && color != null
Returns:
whether a given position is threatened by a color

invalidState

public boolean invalidState()
Is the current state invalid, by the opposite color being in check?

Returns:
whether the current state is invalid.

isLegal

public boolean isLegal(Move m)
Requires:
m != null
Returns:
Whether a move is legal.

getPieces

public Collection<Piece> getPieces()

makeMove

public void makeMove(Move m)
Make a move

Requires:
m != null
Effects:
continues game by one move
Modifies:
this

reversibleMakeMove

public boolean reversibleMakeMove(Map<Position,Piece> m,
                                  boolean isForward)
Modify the AntichessGameState to apply a move, and turn the map into its inverse.

Requires:
  • m != null
  • m != null
Effects:
  • this goes moves forward or backward as defined by isForward by updating by the map m.
  • m changes to its inverse on the current board, so a subsequent call to reversibleMakeMove(m, !isForward) will revert the change.
Modifies:
  • this
  • m
Returns:
whether this move involves a capture.

boardString

public String boardString()
Return the String representation of the board


hashCode

public int hashCode()
Overrides:
hashCode in class Object