Version 0.1.99
============== Everything seems to work fine for a two player game.
This commit is contained in:
@ -175,7 +175,25 @@ public class Board {
|
||||
return new Piece(Piece.NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* This function returns a boolean telling if a {@link Piece} is on a {@link Square}.
|
||||
* @param square The Square
|
||||
* @param piece A Piece constant
|
||||
* @return boolean
|
||||
* @see Piece
|
||||
* @see Square
|
||||
*/
|
||||
public boolean isEmpty(Square square, Piece piece) {
|
||||
long mask = mapSquaresToBits[squareToBitBoardSquare(square)];
|
||||
if ((bitBoards[piece.getPieceNumber()] & mask) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function converts a {@link Square} to a number representing a bitboard square
|
||||
* @param square The Square to be converted
|
||||
* @return int
|
||||
@ -227,66 +245,67 @@ public class Board {
|
||||
public void display(){
|
||||
for (int file = NB_OF_FILES; file >= 1; file--) {
|
||||
System.out.println(" +---+---+---+---+---+---+---+---+");
|
||||
String display = file+" | ";
|
||||
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];
|
||||
|
||||
if (displayPiece(Piece.BLACK_PAWN,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Character.toUpperCase(Piece.PAWN_CHAR)+" | ";
|
||||
display+="'"+Character.toUpperCase(Piece.PAWN_CHAR)+"'|";
|
||||
}
|
||||
if (displayPiece(Piece.BLACK_QUEEN,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Character.toUpperCase(Piece.QUEEN_CHAR)+" | ";
|
||||
display+="'"+Character.toUpperCase(Piece.QUEEN_CHAR)+"'|";
|
||||
}
|
||||
if (displayPiece(Piece.BLACK_KING,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Character.toUpperCase(Piece.KING_CHAR)+" | ";
|
||||
display+="'"+Character.toUpperCase(Piece.KING_CHAR)+"'|";
|
||||
}
|
||||
if (displayPiece(Piece.BLACK_KNIGHT,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Character.toUpperCase(Piece.KNIGHT_CHAR)+" | ";
|
||||
display+="'"+Character.toUpperCase(Piece.KNIGHT_CHAR)+"'|";
|
||||
}
|
||||
if (displayPiece(Piece.BLACK_ROOK,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Character.toUpperCase(Piece.ROOK_CHAR)+" | ";
|
||||
display+="'"+Character.toUpperCase(Piece.ROOK_CHAR)+"'|";
|
||||
}
|
||||
if (displayPiece(Piece.BLACK_BISHOP,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Character.toUpperCase(Piece.BISHOP_CHAR)+" | ";
|
||||
display+="'"+Character.toUpperCase(Piece.BISHOP_CHAR)+"'|";
|
||||
}
|
||||
if (displayPiece(Piece.WHITE_PAWN,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Piece.PAWN_CHAR+" | ";
|
||||
display+=" "+Piece.PAWN_CHAR+" |";
|
||||
}
|
||||
if (displayPiece(Piece.WHITE_QUEEN,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Piece.QUEEN_CHAR+" | ";
|
||||
display+=" "+Piece.QUEEN_CHAR+" |";
|
||||
}
|
||||
if (displayPiece(Piece.WHITE_KING,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Piece.KING_CHAR+" | ";
|
||||
display+=" "+Piece.KING_CHAR+" |";
|
||||
}
|
||||
if (displayPiece(Piece.WHITE_KNIGHT,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Piece.KNIGHT_CHAR+" | ";
|
||||
display+=" "+Piece.KNIGHT_CHAR+" |";
|
||||
}
|
||||
if (displayPiece(Piece.WHITE_ROOK,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Piece.ROOK_CHAR+" | ";
|
||||
display+=" "+Piece.ROOK_CHAR+" |";
|
||||
}
|
||||
if (displayPiece(Piece.WHITE_BISHOP,mask)) {
|
||||
displayedSomething=true;
|
||||
display+=Piece.BISHOP_CHAR+" | ";
|
||||
display+=" "+Piece.BISHOP_CHAR+" |";
|
||||
}
|
||||
if (!displayedSomething)
|
||||
display+=" | ";
|
||||
display+=" |";
|
||||
}
|
||||
System.out.println(display);
|
||||
}
|
||||
System.out.println(" +---+---+---+---+---+---+---+---+");
|
||||
System.out.println(" a b c d e f g h");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
||||
@ -331,16 +350,7 @@ public class Board {
|
||||
bitBoards[piece.getColor()] ^= mapSquaresToBits[squareToBitBoardSquare(square)];;
|
||||
}
|
||||
|
||||
//checks if a square is empty for a certain piece
|
||||
private boolean isEmpty(Square square, Piece piece) {
|
||||
long mask = mapSquaresToBits[squareToBitBoardSquare(square)];
|
||||
if ((bitBoards[piece.getPieceNumber()] & mask) == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//used by function display()
|
||||
private boolean displayPiece(int whatToDisplay, long mask) {
|
||||
if ((bitBoards[whatToDisplay] & mask)==0) {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user