1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-04-30 16:53:09 +00:00

Revert to byTypeBB[0] storing occupied squares

As it was in Glaurung times. Also rearranged order
so that byTypeBB[0] is accessed before byTypeBB[x]
to be more cache friendly. It seems there is even
a small speedup.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2012-03-18 11:33:54 +01:00
parent fc3ea7365a
commit 7bc3688714
3 changed files with 22 additions and 23 deletions

View file

@ -787,9 +787,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
st->npMaterial[them] -= PieceValueMidgame[capture];
// Remove the captured piece
byColorBB[them] ^= capsq;
byTypeBB[ALL_PIECES] ^= capsq;
byTypeBB[capture] ^= capsq;
occupied ^= capsq;
byColorBB[them] ^= capsq;
// Update piece list, move the last piece at index[capsq] position and
// shrink the list.
@ -837,9 +837,9 @@ void Position::do_move(Move m, StateInfo& newSt, const CheckInfo& ci, bool moveI
// Move the piece
Bitboard from_to_bb = SquareBB[from] | SquareBB[to];
byColorBB[us] ^= from_to_bb;
byTypeBB[ALL_PIECES] ^= from_to_bb;
byTypeBB[pt] ^= from_to_bb;
occupied ^= from_to_bb;
byColorBB[us] ^= from_to_bb;
board[to] = board[from];
board[from] = NO_PIECE;
@ -1002,9 +1002,9 @@ void Position::undo_move(Move m) {
// Put the piece back at the source square
Bitboard from_to_bb = SquareBB[from] | SquareBB[to];
byColorBB[us] ^= from_to_bb;
byTypeBB[ALL_PIECES] ^= from_to_bb;
byTypeBB[pt] ^= from_to_bb;
occupied ^= from_to_bb;
byColorBB[us] ^= from_to_bb;
board[from] = board[to];
board[to] = NO_PIECE;
@ -1029,9 +1029,9 @@ void Position::undo_move(Move m) {
}
// Restore the captured piece
byColorBB[them] |= capsq;
byTypeBB[ALL_PIECES] |= capsq;
byTypeBB[capture] |= capsq;
occupied |= capsq;
byColorBB[them] |= capsq;
board[capsq] = make_piece(them, capture);
@ -1085,20 +1085,20 @@ void Position::do_castle_move(Move m) {
assert(piece_on(rfrom) == make_piece(us, ROOK));
// Remove pieces from source squares
byColorBB[us] ^= kfrom;
byTypeBB[ALL_PIECES] ^= kfrom;
byTypeBB[KING] ^= kfrom;
occupied ^= kfrom;
byColorBB[us] ^= rfrom;
byColorBB[us] ^= kfrom;
byTypeBB[ALL_PIECES] ^= rfrom;
byTypeBB[ROOK] ^= rfrom;
occupied ^= rfrom;
byColorBB[us] ^= rfrom;
// Put pieces on destination squares
byColorBB[us] |= kto;
byTypeBB[ALL_PIECES] |= kto;
byTypeBB[KING] |= kto;
occupied |= kto;
byColorBB[us] |= rto;
byColorBB[us] |= kto;
byTypeBB[ALL_PIECES] |= rto;
byTypeBB[ROOK] |= rto;
occupied |= rto;
byColorBB[us] |= rto;
// Update board
Piece king = make_piece(us, KING);
@ -1345,9 +1345,9 @@ void Position::put_piece(Piece p, Square s) {
index[s] = pieceCount[c][pt]++;
pieceList[c][pt][index[s]] = s;
byTypeBB[ALL_PIECES] |= s;
byTypeBB[pt] |= s;
byColorBB[c] |= s;
occupied |= s;
}

View file

@ -231,7 +231,6 @@ private:
// Bitboards
Bitboard byTypeBB[8]; // [pieceType]
Bitboard byColorBB[2]; // [color]
Bitboard occupied;
// Piece counts
int pieceCount[2][8]; // [color][pieceType]
@ -286,7 +285,7 @@ inline Color Position::side_to_move() const {
}
inline Bitboard Position::pieces() const {
return occupied;
return byTypeBB[ALL_PIECES];
}
inline Bitboard Position::pieces(Color c) const {
@ -334,7 +333,7 @@ inline bool Position::can_castle(Color c) const {
}
inline bool Position::castle_impeded(CastleRight f) const {
return occupied & castlePath[f];
return byTypeBB[ALL_PIECES] & castlePath[f];
}
inline Square Position::castle_rook_square(CastleRight f) const {
@ -354,11 +353,11 @@ inline Bitboard Position::attacks_from<PAWN>(Square s, Color c) const {
}
inline Bitboard Position::attacks_from(Piece p, Square s) const {
return attacks_from(p, s, occupied);
return attacks_from(p, s, byTypeBB[ALL_PIECES]);
}
inline Bitboard Position::attackers_to(Square s) const {
return attackers_to(s, occupied);
return attackers_to(s, byTypeBB[ALL_PIECES]);
}
inline Bitboard Position::checkers() const {

View file

@ -200,7 +200,7 @@ enum Value {
};
enum PieceType {
NO_PIECE_TYPE = 0,
NO_PIECE_TYPE = 0, ALL_PIECES = 0,
PAWN = 1, KNIGHT = 2, BISHOP = 3, ROOK = 4, QUEEN = 5, KING = 6
};