From 974872e226af5a52bba6d061e3216503c587d17d Mon Sep 17 00:00:00 2001 From: Calcitem Date: Tue, 22 Dec 2020 00:24:20 +0800 Subject: [PATCH] bb: Fix crash after mirror/turn/rotate --- src/position.cpp | 18 ++++++++++++++++++ src/position.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/position.cpp b/src/position.cpp index 3ab0adfa..9a22409a 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -1837,6 +1837,18 @@ void Position::print_board() } } +void Position::reset_bb() +{ + memset(byTypeBB, 0, sizeof(byTypeBB)); + memset(byColorBB, 0, sizeof(byColorBB)); + + for (Square s = SQ_BEGIN; s < SQ_END; ++s) { + Piece pc = board[s]; + byTypeBB[ALL_PIECES] |= byTypeBB[type_of(pc)] |= s; + byColorBB[color_of(pc)] |= s; + } +} + void Position::mirror(vector &cmdlist, bool cmdChange /*= true*/) { Piece ch; @@ -1851,6 +1863,8 @@ void Position::mirror(vector &cmdlist, bool cmdChange /*= true*/) } } + reset_bb(); + uint64_t llp[3] = { 0 }; if (move < 0) { @@ -1956,6 +1970,8 @@ void Position::turn(vector &cmdlist, bool cmdChange /*= true*/) board[RANK_NB * FILE_NB + r] = ch; } + reset_bb(); + uint64_t llp[3] = { 0 }; if (move < 0) { @@ -2156,6 +2172,8 @@ void Position::rotate(vector &cmdlist, int degrees, bool cmdChange /*= return; } + reset_bb(); + uint64_t llp[3] = { 0 }; if (move < 0) { diff --git a/src/position.h b/src/position.h index 6c0fdf07..a03ed0c3 100644 --- a/src/position.h +++ b/src/position.h @@ -129,6 +129,8 @@ public: void turn(std::vector &cmdlist, bool cmdChange = true); void rotate(std::vector &cmdlist, int degrees, bool cmdChange = true); + void reset_bb(); + void create_mill_table(); int add_mills(Square s); int in_how_many_mills(Square s, Color c, Square squareSelected = SQ_0);