chesspresso.game
Class Game

java.lang.Object
  |
  +--chesspresso.game.Game
All Implemented Interfaces:
PositionChangeListener

public class Game
extends java.lang.Object
implements PositionChangeListener

Abstraction of a chess game. A chess game consists of the following parts:

If you only need the information, not a cursor, use GameModel consisting of GameHeaderModel and GameMoveModel. The game offers the following groups of operation:

Version:
$Revision: 1.2 $
Author:
Bernhard Seybold

Constructor Summary
Game()
           
Game(GameModel gameModel)
           
 
Method Summary
 void addChangeListener(GameModelChangeListener listener)
           
 void addComment(java.lang.String comment)
           
 void addNag(short nag)
           
 boolean containsPosition(ImmutablePosition position)
          Returns whether the main line of the current game contains the given position.
 void deleteCurrentLine()
           
 void deleteCurrentLine(boolean silent)
           
 boolean equals(java.lang.Object obj)
          Returns whether two games are equal.
 void fireMoveModelChanged()
           
 java.lang.String getBlack()
           
 int getBlackElo()
           
 java.lang.String getBlackEloStr()
           
 java.lang.String getComment()
           
 int getCurNode()
           
 int getCurrentMoveNumber()
           
 int getCurrentPly()
           
 java.lang.String getDate()
           
 java.lang.String getECO()
           
 java.lang.String getEvent()
           
 java.lang.String getEventDate()
           
 java.lang.String getHeaderString(int line)
           
 java.lang.String getInfoString()
           
 Move getLastMove()
           
 java.lang.String getLongInfoString()
           
 Move[] getMainLine()
           
 GameModel getModel()
           
 short[] getNags()
           
 Move getNextMove()
           
 Move getNextMove(int whichLine)
           
 int getNextMoveNumber()
           
 Move[] getNextMoves()
           
 short getNextShortMove()
           
 short getNextShortMove(int whichLine)
           
 short[] getNextShortMoves()
           
 int getNumOfMoves()
           
 int getNumOfNextMoves()
           
 int getNumOfPlies()
           
 Position getPosition()
           
 int getResult()
           
 java.lang.String getResultStr()
           
 int getRootNode()
           
 java.lang.String getRound()
           
 java.lang.String getSite()
           
 java.lang.String getTag(java.lang.String tagName)
           
 java.lang.String[] getTags()
           
 int getTotalNumOfPlies()
           
 java.lang.String getWhite()
           
 int getWhiteElo()
           
 java.lang.String getWhiteEloStr()
           
 boolean goBack()
           
 void goBackToLineBegin()
           
 void goBackToMainLine()
           
 boolean goForward()
           
 boolean goForward(int whichLine)
           
 void gotoEndOfLine()
           
 void gotoNode(int node)
           
 void gotoNode(int node, boolean silent)
           
 void gotoPosition(ImmutablePosition pos)
           
 void gotoPosition(ImmutablePosition pos, boolean silent)
           
 void gotoStart()
           
 int hashCode()
          Returns the hash code of the game, which is defined as the hash code of the move model.
 boolean hasNag(short nag)
           
 boolean hasNextMove()
           
 void notifyMoveDone(ImmutablePosition position, short move)
           
 void notifyMoveUndone(ImmutablePosition position)
           
 void notifyPositionChanged(ImmutablePosition position)
           
 void pack()
           
 void removeChangeListener(GameModelChangeListener listener)
           
 void removeComment()
           
 void removeNag(short nag)
           
 void save(java.io.DataOutput out, int headerMode, int movesMode)
           
 void setAlwaysAddLine(boolean alwaysAddLine)
           
 void setComment(java.lang.String comment)
           
 void setTag(java.lang.String tagName, java.lang.String tagValue)
           
 java.lang.String toString()
          Returns a string represention of the game.
 void traverse(GameListener listener, boolean withLines)
          Method to traverse the game in postfix order (first the lines, then the main line).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Game

public Game()

Game

public Game(GameModel gameModel)
Method Detail

getModel

public GameModel getModel()

getPosition

public Position getPosition()

getCurNode

public int getCurNode()

getRootNode

public int getRootNode()

pack

public void pack()

setAlwaysAddLine

public void setAlwaysAddLine(boolean alwaysAddLine)

addChangeListener

public void addChangeListener(GameModelChangeListener listener)

removeChangeListener

public void removeChangeListener(GameModelChangeListener listener)

fireMoveModelChanged

public void fireMoveModelChanged()

notifyPositionChanged

public void notifyPositionChanged(ImmutablePosition position)
Specified by:
notifyPositionChanged in interface PositionChangeListener

notifyMoveDone

public void notifyMoveDone(ImmutablePosition position,
                           short move)
Specified by:
notifyMoveDone in interface PositionChangeListener

notifyMoveUndone

public void notifyMoveUndone(ImmutablePosition position)
Specified by:
notifyMoveUndone in interface PositionChangeListener

getTag

public java.lang.String getTag(java.lang.String tagName)

getTags

public java.lang.String[] getTags()

setTag

public void setTag(java.lang.String tagName,
                   java.lang.String tagValue)

getEvent

public java.lang.String getEvent()

getSite

public java.lang.String getSite()

getDate

public java.lang.String getDate()

getRound

public java.lang.String getRound()

getWhite

public java.lang.String getWhite()

getBlack

public java.lang.String getBlack()

getResultStr

public java.lang.String getResultStr()

getWhiteEloStr

public java.lang.String getWhiteEloStr()

getBlackEloStr

public java.lang.String getBlackEloStr()

getEventDate

public java.lang.String getEventDate()

getECO

public java.lang.String getECO()

getResult

public int getResult()

getWhiteElo

public int getWhiteElo()

getBlackElo

public int getBlackElo()

containsPosition

public boolean containsPosition(ImmutablePosition position)
Returns whether the main line of the current game contains the given position.

Returns:
whether the main line of the current game contains the given position

getInfoString

public java.lang.String getInfoString()

getLongInfoString

public java.lang.String getLongInfoString()

getHeaderString

public java.lang.String getHeaderString(int line)

hasNag

public boolean hasNag(short nag)

getNags

public short[] getNags()

addNag

public void addNag(short nag)

removeNag

public void removeNag(short nag)

getComment

public java.lang.String getComment()

addComment

public void addComment(java.lang.String comment)

setComment

public void setComment(java.lang.String comment)

removeComment

public void removeComment()

getCurrentPly

public int getCurrentPly()

getCurrentMoveNumber

public int getCurrentMoveNumber()

getNextMoveNumber

public int getNextMoveNumber()

getNumOfPlies

public int getNumOfPlies()

getNumOfMoves

public int getNumOfMoves()

getTotalNumOfPlies

public int getTotalNumOfPlies()

getLastMove

public Move getLastMove()

getNextMove

public Move getNextMove()

getNextShortMove

public short getNextShortMove()

getNextMove

public Move getNextMove(int whichLine)

getNextShortMove

public short getNextShortMove(int whichLine)

hasNextMove

public boolean hasNextMove()

getNumOfNextMoves

public int getNumOfNextMoves()

getNextShortMoves

public short[] getNextShortMoves()

getNextMoves

public Move[] getNextMoves()

getMainLine

public Move[] getMainLine()

goBack

public boolean goBack()

goForward

public boolean goForward()

goForward

public boolean goForward(int whichLine)

gotoStart

public void gotoStart()

gotoEndOfLine

public void gotoEndOfLine()

goBackToMainLine

public void goBackToMainLine()

goBackToLineBegin

public void goBackToLineBegin()

gotoNode

public void gotoNode(int node)

gotoPosition

public void gotoPosition(ImmutablePosition pos)

deleteCurrentLine

public void deleteCurrentLine()

gotoNode

public void gotoNode(int node,
                     boolean silent)

gotoPosition

public void gotoPosition(ImmutablePosition pos,
                         boolean silent)

deleteCurrentLine

public void deleteCurrentLine(boolean silent)

traverse

public void traverse(GameListener listener,
                     boolean withLines)
Method to traverse the game in postfix order (first the lines, then the main line). This method is used by PGN.

Parameters:
listener - the listener to receive event when arriving at nodes
withLines - whether or not to include lines of the current main line.

save

public void save(java.io.DataOutput out,
                 int headerMode,
                 int movesMode)
          throws java.io.IOException
java.io.IOException

hashCode

public int hashCode()
Returns the hash code of the game, which is defined as the hash code of the move model. That means two game are considered equal if they contain exactly the same lines. The header does not matter.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

equals

public boolean equals(java.lang.Object obj)
Returns whether two games are equal. This is the case if they contain exactly the same lines. The header does not matter.

Overrides:
equals in class java.lang.Object
Returns:
the hash code

toString

public java.lang.String toString()
Returns a string represention of the game. Implemented as the string represention of the header plus the move model.

Overrides:
toString in class java.lang.Object
Returns:
a string represention of the game