In this version it is possible to add and remove a piece (BLACK_PAWN) to the board.

The board is diplayed in a very basic way in the console.
This commit is contained in:
2006-01-05 16:37:20 +00:00
parent c3ced2c700
commit 08c973a452
4 changed files with 80 additions and 17 deletions

View File

@ -15,7 +15,7 @@ package suicideChess;
* $LastChangedBy$
*/
public class BitBoard {
public class Board {
/*************
* CONSTANTS *
@ -26,7 +26,16 @@ public class BitBoard {
public static final int NB_OF_FILES = 8;
public static final int NB_OF_SQUARES = NB_OF_RANKS*NB_OF_FILES;
public static final int NB_OF_BITBOARDS = 14;
private static final int NB_OF_BITBOARDS = 14;
public class NoPieceOnSquare extends Exception {
/**
* Added by Eclipse
*/
private static final long serialVersionUID = -2750943856086117656L;
NoPieceOnSquare(String s) { super(s); };
}
/********
@ -51,7 +60,7 @@ public class BitBoard {
* CONSTRUCTOR *
***************/
public BitBoard() {
public Board() {
bitBoards = new long[NB_OF_BITBOARDS];
}
@ -61,13 +70,13 @@ public class BitBoard {
* METHODS *
***********/
public long getBitBoard(int bitboard_number) {
private long getBitBoard(int bitboard_number) {
return bitBoards[bitboard_number];
}
public void updateBitBoards(String move) {
private void updateBitBoards(String move) {
//TODO
}
@ -87,14 +96,33 @@ public class BitBoard {
bitBoards[piece.getColor()] |= mapSquaresToBits[squareToBitBoardSquare(square)];
}
protected void removePiece(Square square, Piece piece) {
protected void removePiece(Square square, Piece piece) throws NoPieceOnSquare {
//XOR :
// 0 XOR a = a
// 1 XOR 0 = 1 !!! Don't remove a piece that don't exist !!!
// 1 XOR 1 = 0
//remove Piece to corresponding bitboard.
bitBoards[piece.getPieceNumber()] ^= mapSquaresToBits[squareToBitBoardSquare(square)];
if (SuicideChess.BITBOARD_REMOVEPIECE_CHECK_REMOVE) {
if (checkIsNotEmpty(square, piece)) {
bitBoards[piece.getPieceNumber()] ^= mapSquaresToBits[squareToBitBoardSquare(square)];
} else {
throw new NoPieceOnSquare("Square: "+square + "; Piece: " + piece.getPieceNumber());
}
} else {
bitBoards[piece.getPieceNumber()] ^= mapSquaresToBits[squareToBitBoardSquare(square)];
}
//update the bitboard of all pieces of that color
bitBoards[piece.getColor()] ^= mapSquaresToBits[squareToBitBoardSquare(square)];;
}
//checks if a square is empty for a certain piece
private boolean checkIsNotEmpty(Square square, Piece piece) {
long mask = mapSquaresToBits[squareToBitBoardSquare(square)];
if ((bitBoards[piece.getPieceNumber()] & mask) == 0) {
return false;
} else {
return true;
}
}
}

View File

@ -0,0 +1,34 @@
package suicideChess;
import tests.TestMoves;
/**
* @author djib
*
* Main File
*
* $LastChangedDate$
* $LastChangedRevision$
* $LastChangedBy$
*/
public class SuicideChess {
/**
* Those flags are used to perform extra checks during the debugging of the
* program. They may be safely all set to false once the program is stable.
* It should improve performance a lot.
*/
//does BitBoard.class removePiece function checks if removing piece is legal ?
public static final boolean BITBOARD_REMOVEPIECE_CHECK_REMOVE = true;
/*****************
* MAIN FUNCTION *
*****************/
public static void main(String[] args) {
TestMoves.main(args);
}
}