Pieces can be added and removed to bitboards.
I need to implement move function and it will be ok for a very basic suicide chess program without any move checking.
This commit is contained in:
@ -25,24 +25,7 @@ public class BitBoard {
|
||||
public static final int NB_OF_RANKS = 8;
|
||||
public static final int NB_OF_FILES = 8;
|
||||
public static final int NB_OF_SQUARES = NB_OF_RANKS*NB_OF_FILES;
|
||||
|
||||
//Some constants used to access the bitboards
|
||||
//Note that in suicide chess there may be more than one king
|
||||
public static final int WHITE_PAWNS = 0;
|
||||
public static final int BLACK_PAWNS = 1;
|
||||
public static final int WHITE_KINGS = 2;
|
||||
public static final int BLACK_KINGS = 3;
|
||||
public static final int WHITE_QUEENS = 4;
|
||||
public static final int BLACK_QUEENS = 5;
|
||||
public static final int WHITE_BISHOPS = 6;
|
||||
public static final int BLACK_BISHOPS = 7;
|
||||
public static final int WHITE_KNIGHTS = 8;
|
||||
public static final int BLACK_KNIGHTS = 9;
|
||||
public static final int WHITE_ROOKS = 10;
|
||||
public static final int BLACK_ROOKS = 11;
|
||||
public static final int WHITE_PIECES = 12;
|
||||
public static final int BLACK_PIECES = 13;
|
||||
|
||||
|
||||
public static final int NB_OF_BITBOARDS = 14;
|
||||
|
||||
|
||||
@ -51,7 +34,7 @@ public class BitBoard {
|
||||
********/
|
||||
|
||||
//The following table is used to map squares to bits
|
||||
private static long mapSquaresToBits[];
|
||||
protected static long mapSquaresToBits[];
|
||||
|
||||
//static function used to initialise data
|
||||
static {
|
||||
@ -62,7 +45,7 @@ public class BitBoard {
|
||||
}
|
||||
|
||||
//The following table contains all the bit boards
|
||||
private long bitBoards[];
|
||||
protected long bitBoards[];
|
||||
|
||||
/***************
|
||||
* CONSTRUCTOR *
|
||||
@ -70,6 +53,7 @@ public class BitBoard {
|
||||
|
||||
public BitBoard() {
|
||||
bitBoards = new long[NB_OF_BITBOARDS];
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -77,18 +61,40 @@ public class BitBoard {
|
||||
* METHODS *
|
||||
***********/
|
||||
|
||||
public long getBitboard(int bitboard_number) {
|
||||
public long getBitBoard(int bitboard_number) {
|
||||
return bitBoards[bitboard_number];
|
||||
}
|
||||
|
||||
|
||||
public void updateBitboards(String move) {
|
||||
public void updateBitBoards(String move) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int squareToBitboardSquare(Square square) {
|
||||
private int squareToBitBoardSquare(Square square) {
|
||||
//converts a square ("e2") to a BitboardSquare (
|
||||
return square.getFileNb() -1 + (square.getRank()-1)*NB_OF_FILES;
|
||||
}
|
||||
|
||||
protected void addPiece(Square square, Piece piece) {
|
||||
//OR :
|
||||
// 0 OR a = a
|
||||
// 1 OR a = 1
|
||||
|
||||
//add Piece to corresponding bitboard.
|
||||
bitBoards[piece.getPieceNumber()] |= mapSquaresToBits[squareToBitBoardSquare(square)];
|
||||
//update the bitboard of all pieces of that color
|
||||
bitBoards[piece.getColor()] |= mapSquaresToBits[squareToBitBoardSquare(square)];
|
||||
}
|
||||
|
||||
protected void removePiece(Square square, Piece piece) {
|
||||
//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)];
|
||||
//update the bitboard of all pieces of that color
|
||||
bitBoards[piece.getColor()] ^= mapSquaresToBits[squareToBitBoardSquare(square)];;
|
||||
}
|
||||
}
|
78
src/suicideChess/Piece.java
Normal file
78
src/suicideChess/Piece.java
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package suicideChess;
|
||||
|
||||
/**
|
||||
* @author djib
|
||||
*
|
||||
* This file contains the moves representation.
|
||||
*
|
||||
* $LastChangedDate$
|
||||
* $LastChangedRevision$
|
||||
* $LastChangedBy$
|
||||
*/
|
||||
|
||||
public class Piece {
|
||||
/*************
|
||||
* CONSTANTS *
|
||||
*************/
|
||||
|
||||
|
||||
/**
|
||||
* Take really good care if you want to change those values
|
||||
* Class BitBoard makes intensive use of those
|
||||
*/
|
||||
//Contants used to detect color
|
||||
public static final int WHITE=0;
|
||||
public static final int BLACK=1;
|
||||
//Constants used in the board representation
|
||||
public static final int WHITE_PIECE = WHITE;
|
||||
public static final int BLACK_PIECE = BLACK;
|
||||
public static final int WHITE_PAWN = 2;
|
||||
public static final int BLACK_PAWN = 3;
|
||||
public static final int WHITE_KING = 4;
|
||||
public static final int BLACK_KING = 5;
|
||||
public static final int WHITE_QUEEN = 6;
|
||||
public static final int BLACK_QUEEN = 7;
|
||||
public static final int WHITE_BISHOP = 8;
|
||||
public static final int BLACK_BISHOP = 9;
|
||||
public static final int WHITE_KNIGHT = 10;
|
||||
public static final int BLACK_KNIGHT = 11;
|
||||
public static final int WHITE_ROOK = 12;
|
||||
public static final int BLACK_ROOK = 13;
|
||||
|
||||
|
||||
//Constants used for promotion (as used in the xboard protocol)
|
||||
public static final char KING_CHAR='k';
|
||||
public static final char QUEEN_CHAR='q';
|
||||
public static final char BISHOP_CHAR='b';
|
||||
public static final char KNIGHT_CHAR='n';
|
||||
public static final char ROOK_CHAR='r';
|
||||
|
||||
/****************
|
||||
* PRIVATE DATA *
|
||||
****************/
|
||||
|
||||
private static int pieceNumber;
|
||||
|
||||
/***************
|
||||
* CONSTRUCTOR *
|
||||
***************/
|
||||
|
||||
public Piece(int piece) {
|
||||
pieceNumber = piece;
|
||||
}
|
||||
|
||||
/***********
|
||||
* METHODS *
|
||||
***********/
|
||||
|
||||
public int getColor() {
|
||||
return pieceNumber%2; //cf declaration of BLACK and WHITE above and the pieces above.
|
||||
}
|
||||
|
||||
public int getPieceNumber() {
|
||||
return pieceNumber;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user