net.sourceforge.foobase
Class Game

java.lang.Object
  |
  +--net.sourceforge.foobase.Game

public class Game
extends java.lang.Object

Implements one game of chess.

This class does not depend on the particular database a game was read from or will be written to: it is basically the abstraction this package makes of each game.

Not all features implemented by this class are necessarily supported by all types of databases.


Field Summary
static java.lang.String __version
           
protected  java.lang.String _annotator
          Annotator.
protected  boolean _blackmoves
          Switch indicating black to move first.
protected  java.util.Date _date
          Date played.
protected  int _eco
          ECO code.
protected  char _ecoletter
          ECO letter
protected  int _ecosub
          ECO sub-code
protected  int _elo_black
          ELO black.
protected  int _elo_white
          ELO white.
protected  java.lang.String _gamenote
          Annotation for game (that is: it is not for any move in particular)
protected  boolean _has_initial_setup
          Flag indicating if the initial board setup is the initial game setup or not.
protected  java.util.Vector _ids
          Collection of unique ID's for this game in the different databases.
protected  Board _initialboard
          Initial board setup.
protected  java.util.Vector _moves
          Moves in this game.
protected  java.lang.String _name_black
          Name black player
protected  java.lang.String _name_white
          Name white player
protected  int _nmoves
          Number of moves by white in game.
protected  int _result
          Game result.
protected  java.lang.String _round
          Round.
protected  java.lang.String _tournament
          Tournament information.
static byte PC_EMPTY
          Code for an empty square in the board structure.
static byte PC_PAWN
          Code for a pawn in the board structure.
static byte PC_TYPE_MASK
          Mask for just the piece code without color information
 
Constructor Summary
Game()
          Default public constructor.
 
Method Summary
 void addMove(Move m)
          Add move to game.
protected  void appendMoveStrings(java.lang.StringBuffer sb, java.util.Vector mvs, Board brd, int halfmove)
          Recurively traverse a variations tree.
 java.lang.String getAnnotataor()
          Get name of annotataor
 int getBlackELO()
          Retrieve ELO of the black player.
 java.lang.String getBlackPlayer()
          Retrieve name of the black player.
 java.util.Date getDate()
          Get date game was played.
 int getECO()
          Get ECO code.
 char getECOLetter()
          Get ECO letter code.
 java.lang.String getGameAnnotation()
          Retrieve game annotation.
 java.util.Vector getIDs()
          Get available game IDs for this game.
 Board getInitialPosition()
          Retrieve initial board setup.
 java.util.Vector getMoves()
          Retrieve game moves.
 int getNumberMoves()
          Get the total number of moves white played in this game.
 int getResult()
          Get result of game.
 java.lang.String getRound()
          Get round number.
 int getSubECO()
          Get ECO sub-code.
 java.lang.String getTournament()
          Get name of tournament
 int getWhiteELO()
          Retrieve ELO of the white player.
 java.lang.String getWhitePlayer()
          Retrieve name of the white player.
 boolean hasInitialSetup()
          Tests if the game starts from a given initial position.
 boolean isBlackToMove()
          Get side to move next.
 void setAnnotator(java.lang.String txt)
          Set name of annotataor
 void setBlackELO(int elo)
          Set ELO of black player.
 void setBlackMoves(boolean black)
          Set color to move in the current position.
 void setBlackPlayer(java.lang.String txt)
          Set name of black player.
 void setDate(java.util.Date dat)
          Set date game was played.
 void setECO(int eco)
          Set ECO code
 void setECOLetter(char l)
          Set ECO letter code
 void setGameAnnotation(java.lang.String txt)
          Set annotation text at game level.
 void setHasInitialBoard(boolean b)
          Set flag indicating if the initial board setup is indeed the usual start setup for a new game.
 void setID(IsGameID id)
          Set/add a new ID for this game.
 void setInitialPosition(Board brd)
          Set initial board setup.
 void setMoves(java.util.Vector moves)
          Set entire move list at once.
 void setNumberMoves(int n)
          Set the total number of moves white played in this game.
 void setResult(int res)
          Set result of game.
 void setRound(java.lang.String r)
          Set round number.
 void setSubECO(int eco)
          Set ECO sub-code
 void setTournament(java.lang.String txt)
          Set name of tournament
 void setWhiteELO(int elo)
          Set ELO of white player.
 void setWhitePlayer(java.lang.String txt)
          Set name of white player.
 java.lang.String toString()
          Convert game and all its properties to human readable format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PC_TYPE_MASK

public static final byte PC_TYPE_MASK
Mask for just the piece code without color information

PC_EMPTY

public static final byte PC_EMPTY
Code for an empty square in the board structure.

PC_PAWN

public static final byte PC_PAWN
Code for a pawn in the board structure.

_ids

protected java.util.Vector _ids
Collection of unique ID's for this game in the different databases.

The elements in this list are of type IsGameID


_gamenote

protected java.lang.String _gamenote
Annotation for game (that is: it is not for any move in particular)

_moves

protected java.util.Vector _moves
Moves in this game.

Elements are of type Move.


_initialboard

protected Board _initialboard
Initial board setup.

_blackmoves

protected boolean _blackmoves
Switch indicating black to move first.

_name_white

protected java.lang.String _name_white
Name white player

_name_black

protected java.lang.String _name_black
Name black player

_elo_white

protected int _elo_white
ELO white.

_elo_black

protected int _elo_black
ELO black.

_result

protected int _result
Game result.

_date

protected java.util.Date _date
Date played.

_tournament

protected java.lang.String _tournament
Tournament information.

_round

protected java.lang.String _round
Round.

The datatype String allows for round indications like "3/6" or "playoffs".


_annotator

protected java.lang.String _annotator
Annotator.

_ecoletter

protected char _ecoletter
ECO letter

_eco

protected int _eco
ECO code.

_ecosub

protected int _ecosub
ECO sub-code

_nmoves

protected int _nmoves
Number of moves by white in game.

_has_initial_setup

protected boolean _has_initial_setup
Flag indicating if the initial board setup is the initial game setup or not.

__version

public static final java.lang.String __version
Constructor Detail

Game

public Game()
Default public constructor.
Method Detail

setID

public void setID(IsGameID id)
Set/add a new ID for this game.
Parameters:
id - IsGameID containing the new ID for this game.

getIDs

public java.util.Vector getIDs()
Get available game IDs for this game.

Normally, every database will have its own ID for a game, so one game can have mulitple IDs (if it is present in more than one database)

Returns:
Vector containing all IsGameID identification objects for this game, or null if no IDs are present.

setHasInitialBoard

public void setHasInitialBoard(boolean b)
Set flag indicating if the initial board setup is indeed the usual start setup for a new game.
Parameters:
b - boolean value true if this game has a non-standard initial board setup.

hasInitialSetup

public boolean hasInitialSetup()
Tests if the game starts from a given initial position.
Returns:
boolean value true if the game starts from a non-standard initial board setup.

setGameAnnotation

public void setGameAnnotation(java.lang.String txt)
Set annotation text at game level.
Parameters:
txt - String meant for entire game, not just for one move

getGameAnnotation

public java.lang.String getGameAnnotation()
Retrieve game annotation.
Returns:
String meant for entire game, not just for one

addMove

public void addMove(Move m)
Add move to game.
Parameters:
m - Move to add to the list of moves in the game

setMoves

public void setMoves(java.util.Vector moves)
Set entire move list at once.
Parameters:
moves - Vector containing the entire movelist for this game

getMoves

public java.util.Vector getMoves()
Retrieve game moves.
Returns:
Vector containing the entire game and its registered variations.

setInitialPosition

public void setInitialPosition(Board brd)
Set initial board setup.
Parameters:
brd - Board containing the initial position for this game (only usefull if the game does not start at the usual initial board setup)

getInitialPosition

public Board getInitialPosition()
Retrieve initial board setup.
Returns:
Board containing the initial board setup for this game or null in case the game starts at the usual initial position of a game of chess.

setBlackMoves

public void setBlackMoves(boolean black)
Set color to move in the current position.
Parameters:
black - boolean value true if black is to move, false if white is to move.

isBlackToMove

public boolean isBlackToMove()
Get side to move next.
Returns:
boolean value true if black is to move next.

setWhitePlayer

public void setWhitePlayer(java.lang.String txt)
Set name of white player.
Parameters:
txt - String containing the name of the white player

getWhitePlayer

public java.lang.String getWhitePlayer()
Retrieve name of the white player.
Returns:
String containing the non-null name of the white player.

setBlackPlayer

public void setBlackPlayer(java.lang.String txt)
Set name of black player.
Parameters:
txt - String containing the name of the black player

getBlackPlayer

public java.lang.String getBlackPlayer()
Retrieve name of the black player.
Returns:
String containing the non-null name of the black player.

setWhiteELO

public void setWhiteELO(int elo)
Set ELO of white player.
Parameters:
elo - int containing the ELO of the white player

getWhiteELO

public int getWhiteELO()
Retrieve ELO of the white player.
Returns:
int containing the ELO of the white player.

setBlackELO

public void setBlackELO(int elo)
Set ELO of black player.
Parameters:
elo - int containing the ELO of the black player

getBlackELO

public int getBlackELO()
Retrieve ELO of the black player.
Returns:
int containing the ELO of the black player.

setResult

public void setResult(int res)
Set result of game.
Parameters:
res - int containing the result of the game, according to this table:

  • 0 : black won
  • 1 : draw
  • 2 : white won


getResult

public int getResult()
Get result of game.
Returns:
int containing the game result using these values:

  • 0 : black won
  • 1 : draw
  • 2 : white won


setDate

public void setDate(java.util.Date dat)
Set date game was played.
Parameters:
dat - Date when game was played.

getDate

public java.util.Date getDate()
Get date game was played.
Returns:
Date when game was played.

setTournament

public void setTournament(java.lang.String txt)
Set name of tournament
Parameters:
txt - String containing the name of tournament

getTournament

public java.lang.String getTournament()
Get name of tournament
Returns:
String containing the non-null name of tournament

setAnnotator

public void setAnnotator(java.lang.String txt)
Set name of annotataor
Parameters:
txt - String containing the name of annotataor

getAnnotataor

public java.lang.String getAnnotataor()
Get name of annotataor
Returns:
String containing the non-null name of annotataor

setRound

public void setRound(java.lang.String r)
Set round number.
Parameters:
r - String containing the round within the tournament that this game was played.

getRound

public java.lang.String getRound()
Get round number.
Returns:
String containing the non-null round within the tournament that this game was played.

setECOLetter

public void setECOLetter(char l)
Set ECO letter code
Parameters:
eco - char containing the ECO letter code

getECOLetter

public char getECOLetter()
Get ECO letter code.
Returns:
char containing the ECO letter code

setECO

public void setECO(int eco)
Set ECO code
Parameters:
eco - int containing the ECO code

getECO

public int getECO()
Get ECO code.
Returns:
int containing the ECO code

setSubECO

public void setSubECO(int eco)
Set ECO sub-code
Parameters:
eco - int containing the ECO sub-code

getSubECO

public int getSubECO()
Get ECO sub-code.
Returns:
int containing the ECO sub-code

setNumberMoves

public void setNumberMoves(int n)
Set the total number of moves white played in this game.

This is not the same as the number of moves in the moves list (which typically would contain at least about twice this amount due to black putting up a fight as well)

Parameters:
n - int containing the total number of moves white played in this game.

getNumberMoves

public int getNumberMoves()
Get the total number of moves white played in this game.

This is not the same as the number of moves in the moves list (which typically would contain at least about twice this amount due to black putting up a fight as well)

Returns:
n int containing the total number of moves white played in this game.

toString

public java.lang.String toString()
Convert game and all its properties to human readable format.
Overrides:
toString in class java.lang.Object
Returns:
String containing the game and all its properties in human readable format.

appendMoveStrings

protected void appendMoveStrings(java.lang.StringBuffer sb,
                                 java.util.Vector mvs,
                                 Board brd,
                                 int halfmove)
Recurively traverse a variations tree.
Parameters:
sb - StringBuffer to append the notation to
mvs - Vector containing the variation to process
brd - Board with setup at beginning of the variation
halfmove - int containing the number of the halfmove that is at the start of the variation (first move of the game is halfmove zero)