net.sourceforge.foobase
Class Move

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

public class Move
extends java.lang.Object

Implements one single move.

The implementation of a move includes not only information about which piece moves on the board, but also variations, annotations etc.

Board-cells are numbered 0 up to 63. Currently, Board uses the convention that cell a1 is 0, a8 is 7, b1 is 8 etc. up to h8 having code 63.


Field Summary
static java.lang.String __version
           
protected  java.lang.String _annotation
          Annotation string.
protected  Board _board
          Board setup to which this move applies.
protected  int _castle
          Switch indicating castling and, if so, if it is on the king-side (code 1) or on the queen-side (code 2).
protected  java.lang.String _eval
          Evaluation string (e.g.
protected  int _from
          Start position (in the range 0 to 63)
protected  java.lang.String _moveval
          Move evaluation (e.g.
protected  boolean _needs_diagram
          Diagram required in notation?
protected  java.lang.String _poseval
          Position evalutation string (e.g.
protected  int _prom
          Code for new piece, in case of pawn promotion.
protected  int _to
          End position (in the range 0 to 63)
protected  java.util.Vector _vars
          Variations on this move.
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
Move()
          Default public constructor.
Move(int from, int to, int prom, int castle)
          Public constructor.
 
Method Summary
 void addVariation(java.util.Vector var)
          Add a variation.
 boolean equals(java.lang.Object o)
          Compare two moves for equality.
 java.lang.String formatMove(int halfmove, boolean first)
          Format move for human readable output.
 java.lang.String formatMove(int halfmove, boolean first, byte[] cells)
          Format move for human readable output.
 java.lang.String getAnnotation()
          Get annotation text for this move.
 Board getBoard()
          Get board setup to which this move applies.
 java.lang.String getEvaluation()
          Get evaluation string (e.g.
 int getFrom()
          Retrieve start position of move.
 java.lang.String getMoveEvaluation()
          Get the move evaluation string (e.g.
 java.lang.String getPositionEvaluation()
          Get position evalutation string (e.g.
 int getPromotedPiece()
          Retrieve code for piece in case of pawn promotion.
 int getTo()
          Retrieve end position of move.
 java.util.Vector getVariations()
          Get all registered variations.
 boolean hasVariations()
          Test if this move has variations registered.
 boolean isAnnotated()
          Check if there is any form of annotation available for this move.
 boolean isCastling()
          Test if this is a castling operation.
 boolean isKingCastling()
          Test if this is a king-side castling operation.
 boolean isPromotion()
          Test if this is a pawn promotion.
 boolean isQueenCastling()
          Test if this is a queen-side castling operation.
 boolean needsDiagram()
          Test if a diagram is to be part of the annotation.
 void setAnnotation(java.lang.String txt)
          Set annotation text for this move.
 void setBoard(Board b)
          Set board to which this move applies.
 void setDiagram(boolean b)
          Set if a diagram is to be part of the annotation.
 void setEvaluation(java.lang.String txt)
          Set evaluation string (e.g.
 void setMoveEvaluation(java.lang.String txt)
          Set the move evaluation string (e.g.
 void setPositionEvaluation(java.lang.String txt)
          Set position evalutation string (e.g.
 java.lang.String toString()
          Convert move to string format.
 
Methods inherited from class java.lang.Object
clone, 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.

_from

protected int _from
Start position (in the range 0 to 63)

_to

protected int _to
End position (in the range 0 to 63)

_prom

protected int _prom
Code for new piece, in case of pawn promotion.

_castle

protected int _castle
Switch indicating castling and, if so, if it is on the king-side (code 1) or on the queen-side (code 2). If no castling, the code is 0.

_eval

protected java.lang.String _eval
Evaluation string (e.g. "blunder")

_poseval

protected java.lang.String _poseval
Position evalutation string (e.g. "with compensation")

_moveval

protected java.lang.String _moveval
Move evaluation (e.g. "better is")

_annotation

protected java.lang.String _annotation
Annotation string.

_needs_diagram

protected boolean _needs_diagram
Diagram required in notation?

_vars

protected java.util.Vector _vars
Variations on this move.

Each element is itself a Vector containing the moves for that variation.


_board

protected Board _board
Board setup to which this move applies.

Storing that info in the move objects allows easier navigation through a game (undoing and redoing moves)


__version

public static final java.lang.String __version
Constructor Detail

Move

public Move()
Default public constructor.

Move

public Move(int from,
            int to,
            int prom,
            int castle)
Public constructor.
Parameters:
from - int containing the start-position of the move
to - int containing the end-position of the move
prom - int containing the code for the piece a pawn promotes into (or zero for no promotion)
castle - int containing a code indicating in which direction is being castled: 0 means no castling, 1 means 0-0 and 2 means 0-0-0
Method Detail

setBoard

public void setBoard(Board b)
Set board to which this move applies.

This method stores a local copy of the board, not just a reference to it.

Parameters:
b - Board to which this move applies.

getBoard

public Board getBoard()
Get board setup to which this move applies.

The returned information is not just a reference but a full copy of the board setup.

Returns:
Board setup to which this move applies or null if none is specified.

equals

public boolean equals(java.lang.Object o)
Compare two moves for equality.
Overrides:
equals in class java.lang.Object
Parameters:
o - Object to compare against
Returns:
boolean value true if o represents the same move as the current object.

getFrom

public int getFrom()
Retrieve start position of move.
Returns:
int containing the start position of this move

getTo

public int getTo()
Retrieve end position of move.
Returns:
int containing the end position of this move

isPromotion

public boolean isPromotion()
Test if this is a pawn promotion.
Returns:
boolean value true if this is a pawn promotion.

getPromotedPiece

public int getPromotedPiece()
Retrieve code for piece in case of pawn promotion.

The possible return values are:

Returns:
int containing the code for piece in case of pawn promotion.

isCastling

public boolean isCastling()
Test if this is a castling operation.
Returns:
boolean value true if this is a castling operation.

isKingCastling

public boolean isKingCastling()
Test if this is a king-side castling operation.
Returns:
boolean value true if this is a king-side castling operation.

isQueenCastling

public boolean isQueenCastling()
Test if this is a queen-side castling operation.
Returns:
boolean value true if this is a queen-side castling operation.

setDiagram

public void setDiagram(boolean b)
Set if a diagram is to be part of the annotation.
Parameters:
b - boolean value true is a diagram is to be generated when the annotation of this move is produced.

needsDiagram

public boolean needsDiagram()
Test if a diagram is to be part of the annotation.
Returns:
b boolean value true is a diagram is to be generated when the annotation of this move is produced.

isAnnotated

public boolean isAnnotated()
Check if there is any form of annotation available for this move.
Returns:
boolean value true if at least one of the different annotation or evaluation strings is non-empty.

setAnnotation

public void setAnnotation(java.lang.String txt)
Set annotation text for this move.

If the first character of the annotation string is 0xed04, a diagram will be part of the full notation of this move. That special character is not part of the annotation string obtained by getAnnotation().

Parameters:
txt - String containing the annotation text

getAnnotation

public java.lang.String getAnnotation()
Get annotation text for this move.
Returns:
String containing the annotation text for this move. Note that this string will not contain the special character used elsewhere for denoting the need of a diagram (that is 0xed04). If no annotation is available, null is returned.

addVariation

public void addVariation(java.util.Vector var)
Add a variation.
Parameters:
var - Vector containing a variation on this move. The vector elements are themeselves of the type Move.

hasVariations

public boolean hasVariations()
Test if this move has variations registered.
Returns:
boolean value true if there is at least one variation.

getVariations

public java.util.Vector getVariations()
Get all registered variations.
Returns:
Vector of Move elements where each move represents one variation on the current move.

setEvaluation

public void setEvaluation(java.lang.String txt)
Set evaluation string (e.g. "blunder")
Parameters:
txt - String containing the move evaluation

getEvaluation

public java.lang.String getEvaluation()
Get evaluation string (e.g. "blunder")
Returns:
String containing the non-null move evaluation

setPositionEvaluation

public void setPositionEvaluation(java.lang.String txt)
Set position evalutation string (e.g. "with compensation")
Parameters:
txt - String containing the position evalutation string

getPositionEvaluation

public java.lang.String getPositionEvaluation()
Get position evalutation string (e.g. "with compensation")
Returns:
String containing the non-null position evalutation string

setMoveEvaluation

public void setMoveEvaluation(java.lang.String txt)
Set the move evaluation string (e.g. "better is")
Parameters:
txt - String containing the move evaluation string

getMoveEvaluation

public java.lang.String getMoveEvaluation()
Get the move evaluation string (e.g. "better is")
Parameters:
txt - String containing the non-null move evaluation string

formatMove

public java.lang.String formatMove(int halfmove,
                                   boolean first)
Format move for human readable output.

For now, the long notation is used and no mentioning of checks is added to the output.

The halfmove parameter contains both information about the move number and the side to play.

Parameters:
halfmove - int containing the number of the halfmove that is represented by the current Move (first move of the game is halfmove zero)
first - boolean value true if this move is either the first of the game or the first of a variation.
Returns:
String containing the human readable representation of this Move.

formatMove

public java.lang.String formatMove(int halfmove,
                                   boolean first,
                                   byte[] cells)
Format move for human readable output.

For now, the long notation is used and no mentioning of checks is added to the output.

The halfmove parameter contains both information about the move number and the side to play.

Parameters:
halfmove - int containing the number of the halfmove that is represented by the current Move (first move of the game is halfmove zero)
first - boolean value true if this move is either the first of the game or the first of a variation.
cells - byte[] containing the current pieces setup or null if no such information is available.
Returns:
String containing the human readable representation of this Move.

toString

public java.lang.String toString()
Convert move to string format.

This method is primarily intended for debugging puropses.

Overrides:
toString in class java.lang.Object
Returns:
String containing the move properties in human readable format.