Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void Position::move_piece(Square from, Square to) {
hash ^= zobrist::zobrist_table[board[from]][from] ^ zobrist::zobrist_table[board[from]][to]
^ zobrist::zobrist_table[board[to]][to];
Bitboard mask = SQUARE_BB[from] | SQUARE_BB[to];
piece_bb[NO_PIECE] = SQUARE_BB[from] | piece_bb[NO_PIECE]& ~SQUARE_BB[to];
piece_bb[board[from]] ^= mask;
piece_bb[board[to]] &= ~mask;
board[to] = board[from];
Expand All @@ -118,7 +119,9 @@ void Position::move_piece(Square from, Square to) {
//Moves a piece to an empty square. Note that it is an error if the <to> square contains a piece
void Position::move_piece_quiet(Square from, Square to) {
hash ^= zobrist::zobrist_table[board[from]][from] ^ zobrist::zobrist_table[board[from]][to];
piece_bb[board[from]] ^= (SQUARE_BB[from] | SQUARE_BB[to]);
Bitboard mask = SQUARE_BB[from] | SQUARE_BB[to];
piece_bb[board[from]] ^= mask;
piece_bb[NO_PIECE] ^= mask;
board[to] = board[from];
board[from] = NO_PIECE;
}
Expand Down
5 changes: 4 additions & 1 deletion src/position.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class Position {
hash(0), pinned(0), checkers(0) {

//Sets all squares on the board as empty
piece_bb[NO_PIECE] =~piece_bb[NO_PIECE];
for (int i = 0; i < 64; i++) board[i] = NO_PIECE;
history[0] = UndoInfo();
}
Expand All @@ -98,13 +99,15 @@ class Position {
inline void put_piece(Piece pc, Square s) {
board[s] = pc;
piece_bb[pc] |= SQUARE_BB[s];
piece_bb[NO_PIECE] &= ~SQUARE_BB[s];
hash ^= zobrist::zobrist_table[pc][s];
}

//Removes a piece from a particular square and updates the hash.
inline void remove_piece(Square s) {
hash ^= zobrist::zobrist_table[board[s]][s];
piece_bb[board[s]] &= ~SQUARE_BB[s];
piece_bb[NO_PIECE] |= SQUARE_BB[s];
board[s] = NO_PIECE;
}

Expand Down Expand Up @@ -369,7 +372,7 @@ Move* Position::generate_legals(Move* list) {

const Bitboard us_bb = all_pieces<Us>();
const Bitboard them_bb = all_pieces<Them>();
const Bitboard all = us_bb | them_bb;
const Bitboard all = ~piece_bb[NO_PIECE];

const Square our_king = bsf(bitboard_of(Us, KING));
const Square their_king = bsf(bitboard_of(Them, KING));
Expand Down