From b373e8a2f1e4a06143102d01ddf92422966fce36 Mon Sep 17 00:00:00 2001 From: olex17127 Date: Thu, 26 Aug 2021 19:19:26 -0400 Subject: [PATCH] Populated the value of piece_bb[NO_PIECE] It is initialized to all '1's in default Position constructor; The value is updated in put_piece, remove_piece, move_piece and move_piece_quiet methods --- src/position.cpp | 5 ++++- src/position.h | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index 3bfd2d2..dd2a44e 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -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]; @@ -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 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; } diff --git a/src/position.h b/src/position.h index cd43bfd..1eb23b5 100644 --- a/src/position.h +++ b/src/position.h @@ -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(); } @@ -98,6 +99,7 @@ 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]; } @@ -105,6 +107,7 @@ class Position { 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; } @@ -369,7 +372,7 @@ Move* Position::generate_legals(Move* list) { const Bitboard us_bb = all_pieces(); const Bitboard them_bb = all_pieces(); - 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));