Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
geko authored and geko committed Jun 18, 2015
1 parent f592f1a commit 4f152ed
Show file tree
Hide file tree
Showing 19 changed files with 943 additions and 1,455 deletions.
22 changes: 2 additions & 20 deletions src/Bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,7 @@ class Bits {

static int BITScanForward(u64 bb) {
// @author Matt Taylor (2003)
static const int lsb_64_table[64] = {
63, 30, 3, 32, 59, 14, 11, 33,
60, 24, 50, 9, 55, 19, 21, 34,
61, 29, 2, 53, 51, 23, 41, 18,
56, 28, 1, 43, 46, 27, 0, 35,
62, 31, 58, 4, 5, 49, 54, 6,
15, 52, 12, 40, 7, 42, 45, 16,
25, 57, 48, 13, 10, 39, 8, 44,
20, 47, 38, 22, 17, 37, 36, 26
};
static const int lsb_64_table[64] = {63, 30, 3, 32, 59, 14, 11, 33, 60, 24, 50, 9, 55, 19, 21, 34, 61, 29, 2, 53, 51, 23, 41, 18, 56, 28, 1, 43, 46, 27, 0, 35, 62, 31, 58, 4, 5, 49, 54, 6, 15, 52, 12, 40, 7, 42, 45, 16, 25, 57, 48, 13, 10, 39, 8, 44, 20, 47, 38, 22, 17, 37, 36, 26};
unsigned int folded;
bb ^= bb - 1;
folded = (int) bb ^ (bb >> 32);
Expand All @@ -101,16 +92,7 @@ class Bits {

static int BITScanReverse(u64 bb) {
// authors Kim Walisch, Mark Dickinson
static const int index64[64] = {
0, 47, 1, 56, 48, 27, 2, 60,
57, 49, 41, 37, 28, 16, 3, 61,
54, 58, 35, 52, 50, 42, 21, 44,
38, 32, 29, 23, 17, 11, 4, 62,
46, 55, 26, 59, 40, 36, 15, 53,
34, 51, 20, 43, 31, 22, 10, 45,
25, 39, 14, 33, 19, 30, 9, 24,
13, 18, 8, 12, 7, 6, 5, 63
};
static const int index64[64] = {0, 47, 1, 56, 48, 27, 2, 60, 57, 49, 41, 37, 28, 16, 3, 61, 54, 58, 35, 52, 50, 42, 21, 44, 38, 32, 29, 23, 17, 11, 4, 62, 46, 55, 26, 59, 40, 36, 15, 53, 34, 51, 20, 43, 31, 22, 10, 45, 25, 39, 14, 33, 19, 30, 9, 24, 13, 18, 8, 12, 7, 6, 5, 63};
static const u64 debruijn64 = 0x03f79d71b4cb0a89ULL;
bb |= bb >> 1;
bb |= bb >> 2;
Expand Down
5 changes: 3 additions & 2 deletions src/ChessBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ ChessBoard::~ChessBoard() {
}

#ifdef DEBUG_MODE

u64 ChessBoard::getBitBoard(int side) {
return side ? getBitBoard<WHITE>() : getBitBoard<BLACK>();
}

int ChessBoard::getPieceAt(int side, u64 bitmapPos) {
return side ? getPieceAt<WHITE>(bitmapPos) : getPieceAt<BLACK>(bitmapPos);
}

#endif

uchar ChessBoard::getRightCastle() {
Expand Down Expand Up @@ -88,8 +90,7 @@ void ChessBoard::display() {
cout << "\n ----+---+---+---+---+---+---+----\n";
cout << " " << 8 - RANK_AT[t] << " | ";
}
x = (x = (x = FEN_PIECE[getPieceAt<WHITE>(POW2[63 - t])]) != '-' ? x : FEN_PIECE[getPieceAt<BLACK>(
POW2[63 - t])]) == '-' ? ' ' : x;
x = (x = (x = FEN_PIECE[getPieceAt<WHITE>(POW2[63 - t])]) != '-' ? x : FEN_PIECE[getPieceAt<BLACK>(POW2[63 - t])]) == '-' ? ' ' : x;
x != ' ' ? cout << x : POW2[t] & WHITE_SQUARES ? cout << " " : cout << ".";
cout << " | ";
};
Expand Down
22 changes: 8 additions & 14 deletions src/ChessBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ class ChessBoard : protected Bits {
int getPieceByChar(char);

#ifdef DEBUG_MODE

u64 getBitBoard(int side);

#endif

template<int side>
u64 getBitBoard() {
return chessboard[PAWN_BLACK + side] | chessboard[ROOK_BLACK + side] | chessboard[BISHOP_BLACK + side] |
chessboard[KNIGHT_BLACK + side]
| chessboard[KING_BLACK + side] | chessboard[QUEEN_BLACK + side];
return chessboard[PAWN_BLACK + side] | chessboard[ROOK_BLACK + side] | chessboard[BISHOP_BLACK + side] | chessboard[KNIGHT_BLACK + side] | chessboard[KING_BLACK + side] | chessboard[QUEEN_BLACK + side];
}

void setSide(bool b) {
Expand All @@ -88,18 +88,12 @@ class ChessBoard : protected Bits {

template<int side>
u64 getBitBoardNoPawns() {
return chessboard[ROOK_BLACK + side] | chessboard[BISHOP_BLACK + side] | chessboard[KNIGHT_BLACK + side]
| chessboard[KING_BLACK + side] | chessboard[QUEEN_BLACK + side];
return chessboard[ROOK_BLACK + side] | chessboard[BISHOP_BLACK + side] | chessboard[KNIGHT_BLACK + side] | chessboard[KING_BLACK + side] | chessboard[QUEEN_BLACK + side];
}

template<int side>
int getPieceAt(u64 bitmapPos) {
return ((chessboard[PAWN_BLACK + side] & bitmapPos) ? PAWN_BLACK + side :
((chessboard[ROOK_BLACK + side] & bitmapPos) ? ROOK_BLACK + side :
((chessboard[BISHOP_BLACK + side] & bitmapPos) ? BISHOP_BLACK + side :
((chessboard[KNIGHT_BLACK + side] & bitmapPos) ? KNIGHT_BLACK + side :
((chessboard[QUEEN_BLACK + side] & bitmapPos) ? QUEEN_BLACK + side :
((chessboard[KING_BLACK + side] & bitmapPos) ? KING_BLACK + side : SQUARE_FREE))))));
return ((chessboard[PAWN_BLACK + side] & bitmapPos) ? PAWN_BLACK + side : ((chessboard[ROOK_BLACK + side] & bitmapPos) ? ROOK_BLACK + side : ((chessboard[BISHOP_BLACK + side] & bitmapPos) ? BISHOP_BLACK + side : ((chessboard[KNIGHT_BLACK + side] & bitmapPos) ? KNIGHT_BLACK + side : ((chessboard[QUEEN_BLACK + side] & bitmapPos) ? QUEEN_BLACK + side : ((chessboard[KING_BLACK + side] & bitmapPos) ? KING_BLACK + side : SQUARE_FREE))))));
}

protected:
Expand Down Expand Up @@ -180,12 +174,11 @@ class ChessBoard : protected Bits {

template<int side>
int getNpiecesNoPawnNoKing() {
return bitCount(
chessboard[ROOK_BLACK + side] | chessboard[BISHOP_BLACK + side] | chessboard[KNIGHT_BLACK + side] |
chessboard[QUEEN_BLACK + side]);
return bitCount(chessboard[ROOK_BLACK + side] | chessboard[BISHOP_BLACK + side] | chessboard[KNIGHT_BLACK + side] | chessboard[QUEEN_BLACK + side]);
}

#ifdef DEBUG_MODE

void updateZobristKey(int piece, int position) {
ASSERT_RANGE(position, 0, 63);
ASSERT(piece != 12);
Expand All @@ -194,6 +187,7 @@ class ChessBoard : protected Bits {
}

int getPieceAt(int side, u64 bitmapPos);

#else
#define updateZobristKey(piece, position) (zobristKey ^= _random::RANDOM_KEY[piece][position])

Expand Down
Loading

0 comments on commit 4f152ed

Please sign in to comment.