klaus.chess
Class Position

java.lang.Object
  extended by klaus.chess.Position

public class Position
extends Object

This class stores a position.

Since:
2009-03-11
Author:
Stephan Hillebrand

Field Summary
private  int enPassantPossibility
          This variable stores the posiibilities to take en passant (e. p.).
private  boolean longCastlingBlack
           
private  boolean longCastlingWhite
           
private  int noOfDrawMoves
          Number of half-moves since the last time a pawn moved or a piece was taken.
private  int noOfMove
          Number of moves (not half-moves, notice the dirfference to noOfDrawMoves!!!)
private  char[][] pieces
          This matrix is used to store the position.
private  boolean shortCastlingBlack
           
private  boolean shortCastlingWhite
           
private  boolean whitesTurn
          Is it white's turn (is this a max position) ???
 
Constructor Summary
Position()
          Creates a default position
Position(String fen)
          This creates a new position from a FEN string.
 
Method Summary
 Object clone()
           
 void dump(PrintStream ps)
           
 boolean equals(Object obj)
           
 int getEnPassantPossibility()
           
 int getNoOfDrawMoves()
           
 int getNoOfMove()
           
 char getPieceAt(int line, int row)
           
 Point[] getPositionsOf(char piece)
           
 int hashCode()
           
 boolean hasLegalMoves()
          check if the player moving next has any possible moves
 boolean isCheck()
           
 boolean isCheckmate()
           
 boolean isLongCastlingBlack()
           
 boolean isLongCastlingWhite()
           
 boolean isShortCastlingBlack()
           
 boolean isShortCastlingWhite()
           
 boolean isStalemate()
           
 boolean isWhitesTurn()
           
 void setEnPassantPossibility(int enPassantPossibility)
           
 void setLongCastlingBlack(boolean longCastlingBlack)
           
 void setLongCastlingWhite(boolean longCastlingWhite)
           
 void setNoOfDrawMoves(int noOfDrawMoves)
           
 void setNoOfMove(int noOfMove)
           
 void setPieceAt(int line, int row, char piece)
           
 void setShortCastlingBlack(boolean shortCastlingBlack)
           
 void setShortCastlingWhite(boolean shortCastlingWhite)
           
 void setWhitesTurn(boolean whitesTurn)
           
 String toFEN()
          Generate a FEN (Forsyth-Edwards notation) string from this position.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

whitesTurn

private boolean whitesTurn
Is it white's turn (is this a max position) ???


noOfDrawMoves

private int noOfDrawMoves
Number of half-moves since the last time a pawn moved or a piece was taken. If this number reaches 100 (that is, 50 moves) the game is drawn.


noOfMove

private int noOfMove
Number of moves (not half-moves, notice the dirfference to noOfDrawMoves!!!)


enPassantPossibility

private int enPassantPossibility
This variable stores the posiibilities to take en passant (e. p.). If the last move was a pawn's double step, this is set to the line number of this pawn (0 for A, 7 for H). If not, -1 will signal that there is no posiibility to take en passant. After each half-move this has to be reset.


longCastlingWhite

private boolean longCastlingWhite

longCastlingBlack

private boolean longCastlingBlack

shortCastlingWhite

private boolean shortCastlingWhite

shortCastlingBlack

private boolean shortCastlingBlack

pieces

private char[][] pieces

This matrix is used to store the position. Capital letters are white pieces, other characters are black. The blanks are empty fields.

Each new position is initialized with the default position. I don't know if this is that good, but it makes things more easy.

Constructor Detail

Position

public Position(String fen)

This creates a new position from a FEN string.

.

The most simple way to create a Position is giving a FEN String. This might look like this: rbnqknbr/pppppppp/8/8/8/8/PPPPPPPP/RBNQKNBR w - - 0 1 where the rbn... sequence is the board, w means it's white's move (b would mean black), - is the possibility to castle (in this example nobody can castle, Kq would mean white can do a short castling and black can do a long castling), the second - means nobody can take e. p. (else e. g. 4 for e. p. on the E line). 0 is the number of half-moves for the 50 moves rule and 1 is the number of this move (NOT half-move but move, really!)

Parameters:
fen - the FEN string used (Forsyth-Edwards notation, see Wikipedia for details)

Position

public Position()
Creates a default position

Method Detail

setPieceAt

public void setPieceAt(int line,
                       int row,
                       char piece)

getPieceAt

public char getPieceAt(int line,
                       int row)

getEnPassantPossibility

public int getEnPassantPossibility()

getNoOfDrawMoves

public int getNoOfDrawMoves()

isWhitesTurn

public boolean isWhitesTurn()

setEnPassantPossibility

public void setEnPassantPossibility(int enPassantPossibility)

setNoOfDrawMoves

public void setNoOfDrawMoves(int noOfDrawMoves)

setWhitesTurn

public void setWhitesTurn(boolean whitesTurn)

clone

public Object clone()
Overrides:
clone in class Object

isLongCastlingBlack

public boolean isLongCastlingBlack()

isLongCastlingWhite

public boolean isLongCastlingWhite()

isShortCastlingBlack

public boolean isShortCastlingBlack()

isShortCastlingWhite

public boolean isShortCastlingWhite()

setLongCastlingBlack

public void setLongCastlingBlack(boolean longCastlingBlack)

setLongCastlingWhite

public void setLongCastlingWhite(boolean longCastlingWhite)

setShortCastlingBlack

public void setShortCastlingBlack(boolean shortCastlingBlack)

setShortCastlingWhite

public void setShortCastlingWhite(boolean shortCastlingWhite)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hasLegalMoves

public boolean hasLegalMoves()
check if the player moving next has any possible moves

Returns:

isCheck

public boolean isCheck()

isCheckmate

public boolean isCheckmate()

isStalemate

public boolean isStalemate()

dump

public void dump(PrintStream ps)

getPositionsOf

public Point[] getPositionsOf(char piece)

toFEN

public String toFEN()
Generate a FEN (Forsyth-Edwards notation) string from this position.

Returns:
a FEN string for this position

getNoOfMove

public int getNoOfMove()

setNoOfMove

public void setNoOfMove(int noOfMove)