|
Internet Chess ToolKit v0.2.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectictk.boardgame.chess.ChessBoard
This is the playing board. It is a matrix of Squares with Pieces on those Squares. The Pieces themselves determine their legal moves. ChessBoard facilitates this but does not assess move legality by itself. Whenever specifying coordinates on a ChessBoard it should be done by using the range 1-MAX_FILE, or 1-8 for normal chess.
Field Summary | |
static long |
DEBUG
used as a mask for Log.debug() |
static char[][] |
DEFAULT_POSITION
the default setup of pieces in a traditional chess board |
static byte |
MAX_FILE
the max number of files on a traditional chess board |
static byte |
MAX_RANK
the max number of ranks on a traditional chess board |
static byte |
NO_ENPASSANT
the file that indicates no file is specified |
static byte |
NULL_FILE
the file that indicates no file is specified |
static byte |
NULL_RANK
the file that indicates no file is specified |
Constructor Summary | |
ChessBoard()
calls ChessBoard(true) |
|
ChessBoard(boolean defaultBoard)
|
|
ChessBoard(char[][] matrix)
|
|
ChessBoard(char[][] matrix,
boolean isBlackMove,
boolean castleWK,
boolean castleWQ,
boolean castleBK,
boolean castleBQ,
char enpassantFile,
int plyCount,
int moveNum)
|
Method Summary | |
void |
addBishop(int file,
int rank,
boolean isBlack)
adds a Bishop to a Square on the board and to the team of pieces of the correct color. |
void |
addBoardListener(BoardListener bl)
add a listener for board updates |
void |
addKing(int file,
int rank,
boolean isBlack)
adds a King to a Square on the board and to the team of pieces of the correct color. |
void |
addKnight(int file,
int rank,
boolean isBlack)
adds a Knight to a Square on the board and to the team of pieces of the correct color. |
void |
addPawn(int file,
int rank,
boolean isBlack)
adds a Pawn to a Square on the board and to the team of pieces of the correct color. |
void |
addQueen(int file,
int rank,
boolean isBlack)
adds a Queen to a Square on the board and to the team of pieces of the correct color. |
void |
addRook(int file,
int rank,
boolean isBlack)
adds a Rook to a Square on the board and to the team of pieces of the correct color. |
java.lang.String |
dump()
full dump of everything |
java.lang.String |
dumpLegalMoves()
|
java.lang.String |
dumpLegalMoves(boolean blacksMoves)
|
java.lang.String |
dumpOpposingMoves()
|
boolean |
equals(java.lang.Object o)
standard override of the equals(Object) function. |
void |
fireBoardEvent(int event)
this is used by controllers (such as History) to fire board events to BoardListeners. |
int |
get50MoveRulePlyCount()
returns how many ply (half-moves) the board is into the 50 move rule. |
BoardListener[] |
getBoardListeners()
|
ChessPiece[] |
getCapturedPieces(boolean isBlack)
get the pieces that have been captured. |
int |
getCurrentMoveNumber()
get move number for the last move executed |
byte |
getEnPassantFile()
returns the file index (1-8) of the file where enpassant is legal |
ChessPiece[] |
getGuards(ChessPiece piece)
returns an array of the pieces of the team specified who can guard the square (a friendly piece) specified. |
ChessPiece[] |
getGuards(Square sq,
boolean isBlack)
returns an array of the pieces of the team specified who can guard the square (a friendly piece) specified. |
int |
getLegalMoveCount()
how many legal moves on the current board. |
java.util.List |
getLegalMoves()
returns a list of moves that are legal on the current board. |
int |
getMaterialCount(boolean isBlack)
gets the material count evaluation for the side specified. |
int |
getMaxFile()
what is the maxium file allowed. |
int |
getMaxRank()
what is the maxium rank allowed. |
Square |
getOrigin(byte piece_index,
int file,
int rank,
Square dest)
determines where the origin of the move that goes to this destination is. |
Square |
getOrigin(byte piece_index,
Square dest)
determines where the origin of the move that goes to this destination is. |
int |
getPlayerToMove()
|
Square |
getSquare(char file,
char rank)
cx and cy should subscribe to the default locale of boardgame.chess.io.SAN. |
Square |
getSquare(int x,
int y)
x and y should be in the range 1-8 |
ChessPiece[] |
getThreats(ChessPiece piece)
return the ChessPieces that threaten to take this piece. |
ChessPiece[] |
getThreats(Square sq,
boolean isBlack)
returns an array of the pieces of the team specified who can attack the square specified. |
ChessPiece[] |
getUnCapturedPieces(boolean isBlack)
get the pieces that haven't been captured. |
int |
hashCode()
|
boolean |
is50MoveRuleApplicible()
tests to see if the 50 move rule can be applied to this game, thus indicating a legal Draw may be called. |
boolean |
isBlackCastleableKingside()
|
boolean |
isBlackCastleableQueenside()
|
boolean |
isBlackMove()
who's move is it? |
boolean |
isCheck()
returns true if the King in the side to move is in check or double-check. |
boolean |
isCheckmate()
returns true if the current board is in checkmate |
boolean |
isDoubleCheck()
returns true if the King on the side to move is threatened by two pieces. |
boolean |
isEnPassantFile(char f)
tests to see if the file (a-h) is the enpassant file. |
boolean |
isEnPassantFile(int f)
tests to see if the file (1-8) is the enpassant file. |
boolean |
isFileValid(int f)
is this a valid file for the board (in the proper range) |
boolean |
isGuarded(ChessPiece piece)
does a fellow team member recapture this square if the piece is taken |
boolean |
isGuarded(Square sq,
boolean isBlack)
does a fellow team member recapture this square if the piece is taken |
boolean |
isInitialPositionDefault()
was the initial position of the board (before any move) the default position of traditional chess? |
boolean |
isLegalMove(Move m)
Checks to see if the move is legal on the current board. |
boolean |
isRankValid(int r)
is this a valid rank for the board (in the proper range) |
boolean |
isStalemate()
returns true if there are no legal moves and the King is not in check |
boolean |
isThreatened(ChessPiece piece)
is a ChessPiece attacking this piece. |
boolean |
isThreatened(Square sq,
boolean isBlack)
is a ChessPiece attacking this square? |
boolean |
isWhiteCastleableKingside()
|
boolean |
isWhiteCastleableQueenside()
|
void |
playMove(Move move)
plays the move on the board. |
void |
removeBoardListener(BoardListener bl)
|
void |
set50MoveRulePlyCount(int i)
sets many ply (half-moves) the board is into the 50 move rule. |
void |
setBlackCastleableKingside(boolean t)
|
void |
setBlackCastleableQueenside(boolean t)
|
void |
setBlackMove(boolean t)
sets who's turn it is to move. |
void |
setEnPassantFile(char f)
sets the file (a-h) of the file where enpassant is legal |
void |
setEnPassantFile(int f)
sets the file index (1-8) of the file where enpassant is legal |
void |
setPosition(char[][] matrix)
set the position from an 8x8 matrix using the FEN characters to represent piece positions. |
void |
setPositionClear()
removes all pieces from the board |
void |
setPositionDefault()
sets the board position to the default chess board setup. |
void |
setWhiteCastleableKingside(boolean t)
|
void |
setWhiteCastleableQueenside(boolean t)
|
char[][] |
toCharArray()
returns the character matrix array of the current board. |
java.lang.String |
toString()
a diagnostic tool which shows the board state. |
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final long DEBUG
public static final byte NULL_FILE
public static final byte NULL_RANK
public static final byte NO_ENPASSANT
public static final char[][] DEFAULT_POSITION
public static final byte MAX_FILE
public static final byte MAX_RANK
Constructor Detail |
public ChessBoard()
public ChessBoard(boolean defaultBoard)
defaultBoard
- if true the default chess position will be used.
if false the board will be cleared and w/o pieces.public ChessBoard(char[][] matrix)
matrix
- the position using English SAN notation
for the pieces, (PNBRQK) where uppercase is
used for White pieces and lowercase for Black.public ChessBoard(char[][] matrix, boolean isBlackMove, boolean castleWK, boolean castleWQ, boolean castleBK, boolean castleBQ, char enpassantFile, int plyCount, int moveNum)
matrix
- the position using English SAN notation
for the pieces, (PNBRQK) where uppercase is
used for White pieces and lowercase for Black.isBlackMove
- who's move is it?castleWK
- can white castle Kingside?castleWQ
- can white castle Queenside?castleBK
- can white castle Kingside?castleBQ
- can white castle Queenside?enpassantFile
- the file (A-H) that is vulnerable to enpassantplyCount
- the ply count for the 50 move rule.moveNum
- which move number are we on?Method Detail |
public boolean isRankValid(int r)
public boolean isFileValid(int f)
public int getMaxRank()
public int getMaxFile()
public void playMove(Move move) throws IllegalMoveException, OutOfTurnException
playMove
in interface Board
IllegalMoveException
OutOfTurnException
public int getPlayerToMove()
getPlayerToMove
in interface Board
public boolean isLegalMove(Move m)
isLegalMove
in interface Board
public ChessPiece[] getThreats(Square sq, boolean isBlack)
sq
- square to do threat analysis forisBlack
- attackers must be of this team
public ChessPiece[] getThreats(ChessPiece piece)
public boolean isThreatened(Square sq, boolean isBlack)
sq
- the square in question.isBlack
- which side do you suppose attacks this square?public boolean isThreatened(ChessPiece piece)
piece
- the piece under possible attackpublic ChessPiece[] getGuards(Square sq, boolean isBlack)
sq
- square to do threat analysis forisBlack
- attackers must be of this team
public ChessPiece[] getGuards(ChessPiece piece)
piece
- the piece to be guarded
public boolean isGuarded(Square sq, boolean isBlack)
public boolean isGuarded(ChessPiece piece)
public int getLegalMoveCount()
getLegalMoveCount
in interface Board
public java.util.List getLegalMoves()
getLegalMoves
in interface Board
public Square getOrigin(byte piece_index, Square dest) throws AmbiguousChessMoveException, IllegalMoveException
AmbiguousChessMoveException
IllegalMoveException
public Square getOrigin(byte piece_index, int file, int rank, Square dest) throws AmbiguousChessMoveException, IllegalMoveException
AmbiguousChessMoveException
IllegalMoveException
public boolean isCheckmate()
public boolean isCheck()
public boolean isDoubleCheck()
public boolean isStalemate()
public char[][] toCharArray()
public ChessPiece[] getCapturedPieces(boolean isBlack)
isBlack
- if true returns Black pieces that have been captured.public ChessPiece[] getUnCapturedPieces(boolean isBlack)
isBlack
- if true returns Black pieces that haven't been captured.public int getMaterialCount(boolean isBlack)
isBlack
- the color of the side you wish to evaluate.public void setBlackMove(boolean t)
java.lang.IllegalStateException
- if a move has already been executed.public boolean isBlackMove()
public Square getSquare(char file, char rank)
public Square getSquare(int x, int y)
public java.lang.String toString()
public void setPositionDefault()
setPositionDefault
in interface Board
java.lang.IllegalStateException
- if this move is used on a board that
already has moves played on it.public void setPositionClear()
setPositionClear
in interface Board
java.lang.IllegalStateException
- if this move is used on a board that
already has moves played on it.public void setPosition(char[][] matrix)
java.lang.IllegalStateException
- if this move is used on a board that
already has moves played on it.public void addPawn(int file, int rank, boolean isBlack)
file
- the X coordinate (1-8)rank
- the Y coordinate (1-8)public void addKnight(int file, int rank, boolean isBlack)
file
- the X coordinate (1-8)rank
- the Y coordinate (1-8)public void addBishop(int file, int rank, boolean isBlack)
file
- the X coordinate (1-8)rank
- the Y coordinate (1-8)public void addRook(int file, int rank, boolean isBlack)
file
- the X coordinate (1-8)rank
- the Y coordinate (1-8)public void addQueen(int file, int rank, boolean isBlack)
file
- the X coordinate (1-8)rank
- the Y coordinate (1-8)public void addKing(int file, int rank, boolean isBlack)
file
- the X coordinate (1-8)rank
- the Y coordinate (1-8)public boolean isWhiteCastleableKingside()
public boolean isWhiteCastleableQueenside()
public boolean isBlackCastleableKingside()
public boolean isBlackCastleableQueenside()
public void setWhiteCastleableKingside(boolean t)
public void setWhiteCastleableQueenside(boolean t)
public void setBlackCastleableKingside(boolean t)
public void setBlackCastleableQueenside(boolean t)
public byte getEnPassantFile()
public void setEnPassantFile(int f)
f
- NO_ENPASSANT if the file is not setpublic void setEnPassantFile(char f)
f
- '-' if the file is not setpublic boolean isEnPassantFile(char f)
public boolean isEnPassantFile(int f)
public int get50MoveRulePlyCount()
public void set50MoveRulePlyCount(int i)
public boolean is50MoveRuleApplicible()
public int getCurrentMoveNumber()
public boolean isInitialPositionDefault()
isInitialPositionDefault
in interface Board
public void addBoardListener(BoardListener bl)
Board
addBoardListener
in interface Board
public BoardListener[] getBoardListeners()
getBoardListeners
in interface Board
public void removeBoardListener(BoardListener bl)
removeBoardListener
in interface Board
public void fireBoardEvent(int event)
Board
fireBoardEvent
in interface Board
event
- the BoardEvent.public boolean equals(java.lang.Object o)
Some things checked are:
1) who's move
2) pieces on the same squares
3) castling rights
4) enpassant file
Things not checked, but you might think they were:
1) last move played
2) plyCount (for 50 move rule determination
3) the move number
4) is the initial position the default for both boards
public int hashCode()
public java.lang.String dumpLegalMoves()
public java.lang.String dumpOpposingMoves()
public java.lang.String dumpLegalMoves(boolean blacksMoves)
public java.lang.String dump()
|
Submit a bug or feature Visit the Website Internet Chess ToolKit is licensed under the GPL v2 . |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |