From: Fabian Fichter Date: Sun, 1 Sep 2019 18:50:36 +0000 (+0200) Subject: Filter invalid moves early X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=6aab09c0b8571875fef70411ef6372a8bf30e33b;p=fairystockfish.git Filter invalid moves early No functional change. --- diff --git a/src/movegen.cpp b/src/movegen.cpp index a3e0ab2..55c4d5a 100644 --- a/src/movegen.cpp +++ b/src/movegen.cpp @@ -108,7 +108,7 @@ namespace { // Single and double pawn pushes, no promotions if (Type != CAPTURES) { - emptySquares = (Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces()); + emptySquares = (Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces() & pos.board_bb()); Bitboard b1 = shift(pawnsNotOn7) & emptySquares; Bitboard b2 = pos.double_step_enabled() ? shift(b1 & TRank3BB) & emptySquares : Bitboard(0); @@ -158,7 +158,7 @@ namespace { if (pawnsOn7) { if (Type == CAPTURES) - emptySquares = ~pos.pieces(); + emptySquares = ~pos.pieces() & pos.board_bb(); if (Type == EVASIONS) emptySquares &= target; @@ -193,7 +193,7 @@ namespace { { if (pos.count(Us, pt)) continue; - Bitboard b = (pos.attacks_from(Us, pt, from) & ~pos.pieces()) | from; + Bitboard b = (pos.attacks_from(Us, pt, from) & ~pos.pieces() & pos.board_bb()) | from; if (Type == EVASIONS) b &= target; @@ -404,7 +404,7 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) { if (pt == PAWN) continue; // Will be generated together with direct checks - Bitboard b = pos.moves_from(us, pt, from) & ~pos.pieces(); + Bitboard b = pos.moves_from(us, pt, from) & ~pos.pieces() & pos.board_bb(); if (pt == KING) b &= ~PseudoAttacks[~us][QUEEN][pos.square(~us)]; @@ -440,7 +440,7 @@ ExtMove* generate(const Position& pos, ExtMove* moveList) { } // Generate evasions for king, capture and non capture moves - Bitboard b = pos.attacks_from(us, ksq) & ~pos.pieces(us) & ~sliderAttacks; + Bitboard b = pos.attacks_from(us, ksq) & ~pos.pieces(us) & ~sliderAttacks & pos.board_bb(); while (b) moveList = make_move_and_gating(pos, moveList, us, ksq, pop_lsb(&b)); diff --git a/src/position.cpp b/src/position.cpp index 1f683d7..56f3a96 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -750,10 +750,6 @@ bool Position::legal(Move m) const { assert(color_of(moved_piece(m)) == us); assert(!count(us) || piece_on(square(us)) == make_piece(us, KING)); - // Illegal moves to squares outside of board - if (!(board_bb() & to)) - return false; - // Illegal checks if ((!checking_permitted() || (sittuyin_promotion() && type_of(m) == PROMOTION)) && gives_check(m)) return false; @@ -876,6 +872,10 @@ bool Position::pseudo_legal(const Move m) const { Square to = to_sq(m); Piece pc = moved_piece(m); + // Illegal moves to squares outside of board + if (!(board_bb() & to)) + return false; + // Use a fast check for piece drops if (type_of(m) == DROP) return piece_drops()