Version 0.1.9

Rules are checked and en passant works.

Does not check if black or white is playing.
Does not check multiple possibilities for promotion.
This commit is contained in:
2006-01-13 12:29:54 +00:00
parent eb0e593ee1
commit c62bdacb9f
5 changed files with 233 additions and 29 deletions

View File

@ -57,6 +57,9 @@ public class Board {
protected long bitBoards[];
private boolean enPassant=false; //is there an 'en passant pawn' on the board
private Square enPassantSquare;
/*=============*
@ -122,7 +125,11 @@ public class Board {
public void doMove(Move move) throws NoPieceOnSquare {
if (move.isCaptureMove()) {
removePiece(move.toSquare(), move.getCapturedPiece());
if (move.isEnPassant()) {
removePiece(move.getEnPassantSquare(), move.getCapturedPiece());
} else {
removePiece(move.toSquare(), move.getCapturedPiece());
}
}
removePiece(move.fromSquare(), move.getMovingPiece());
if (move.isPromotionMove()) {
@ -130,6 +137,14 @@ public class Board {
} else {
addPiece(move.toSquare(), move.getMovingPiece());
}
this.enPassant=false;
if (move.enablesEnPassant()) {
enPassant=true;
enPassantSquare=move.getEnPassantSquare();
}
}
/**
@ -171,6 +186,39 @@ public class Board {
return square.getFileNb() -1 + (square.getRank()-1)*NB_OF_FILES;
}
// /**
// * This function is used to set the table to an state in which a {@link Square} is an 'en passant' Square
// * @param Square The 'en passant' Square
// * @see Square
// */
// public void setEnPassant(Square square) {
// enPassant=true;
// enPassantSquare=square;
// }
//
// /**
// * This function is used to set the table back to a state with no 'en passant' Squares.
// */
// public void clearEnPassant () {
// enPassant=false;
// }
/**
* This function returns a boolean saying if the board is in an 'en passant' state.
* @return boolean
*/
public boolean isEnPassant() {
return enPassant;
}
/**
* This function is used to return the 'en passant' Square. Don't use it unless table is in an 'en passant' state.
* @return Square
* @see Square
*/
public Square getEnPassantSquare() {
return enPassantSquare;
}
/**
* This function can be used to display the board
@ -178,8 +226,8 @@ public class Board {
*/
public void display(){
for (int file = NB_OF_FILES; file >= 1; file--) {
System.out.println("+---+---+---+---+---+---+---+---+");
String display = "| ";
System.out.println(" +---+---+---+---+---+---+---+---+");
String display = file+" | ";
for (int rank=1; rank <= NB_OF_RANKS; rank++) {
boolean displayedSomething = false;
long mask = mapSquaresToBits[rank-1+(file-1)*NB_OF_RANKS];
@ -237,7 +285,8 @@ public class Board {
}
System.out.println(display);
}
System.out.println("+---+---+---+---+---+---+---+---+");
System.out.println(" +---+---+---+---+---+---+---+---+");
System.out.println(" a b c d e f g h");
}