From d4e3b72141558ae9a49224718dc6d4f0990d9099 Mon Sep 17 00:00:00 2001 From: Fabian Fichter Date: Sat, 2 Oct 2021 23:46:35 +0200 Subject: [PATCH] Handle placement corner cases more naturally No functional change for legal positions, just generalizes more naturally to artifical positions. --- src/position.cpp | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/position.cpp b/src/position.cpp index f2d6e6f..acce8a4 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -958,13 +958,13 @@ bool Position::legal(Move m) const { { Bitboard remaining = drop_region(us, BISHOP) & ~pieces() & ~square_bb(to); // Are enough squares available to drop bishops on opposite colors? - if ( (!( DarkSquares & pieces(us, BISHOP)) && ( DarkSquares & remaining)) - + (!(~DarkSquares & pieces(us, BISHOP)) && (~DarkSquares & remaining)) < count_in_hand(us, BISHOP)) + if ( popcount( DarkSquares & (pieces(us, BISHOP) | remaining)) < count_with_hand(us, BISHOP) / 2 + || popcount(~DarkSquares & (pieces(us, BISHOP) | remaining)) < count_with_hand(us, BISHOP) / 2) return false; } else // Drop resulting in same-colored bishops - if ((DarkSquares & to ? DarkSquares : ~DarkSquares) & pieces(us, BISHOP)) + if (popcount((DarkSquares & to ? DarkSquares : ~DarkSquares) & pieces(us, BISHOP)) + 1 > (count_with_hand(us, BISHOP) + 1) / 2) return false; } @@ -1086,15 +1086,15 @@ bool Position::legal(Move m) const { if (var->makpongRule && checkers() && type_of(moved_piece(m)) == KING && (checkers() ^ to)) return false; - // Return early when without king - if (!count(us)) - return true; - // If the moving piece is a king, check whether the destination square is // attacked by the opponent. if (type_of(moved_piece(m)) == KING) return !attackers_to(to, occupied, ~us); + // Return early when without king + if (!count(us)) + return true; + Bitboard janggiCannons = pieces(JANGGI_CANNON); if (type_of(moved_piece(m)) == JANGGI_CANNON) janggiCannons = (type_of(m) == DROP ? janggiCannons : janggiCannons ^ from) | to; -- 1.7.0.4