Fix pseudo-legal move validation (close #35)
authorFabian Fichter <ianfab@users.noreply.github.com>
Mon, 7 Oct 2019 19:36:47 +0000 (21:36 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Tue, 8 Oct 2019 18:03:59 +0000 (20:03 +0200)
sittuyin STC
LLR: 2.95 (-2.94,2.94) [0.00,10.00]
Total: 126 W: 60 L: 2 D: 64
http://35.161.250.236:6543/tests/view/5d9b94916e23db3768ec08f3

sittuyin LTC
LLR: 2.96 (-2.94,2.94) [0.00,10.00]
Total: 111 W: 58 L: 1 D: 52
http://35.161.250.236:6543/tests/view/5d9b9f566e23db3768ec08fd

bench: 3686859

src/movepick.cpp
src/position.cpp
src/search.cpp

index 8d55ec4..862aed9 100644 (file)
@@ -164,6 +164,7 @@ top:
   case QSEARCH_TT:
   case PROBCUT_TT:
       ++stage;
+      assert(pos.legal(ttMove) == MoveList<LEGAL>(pos).contains(ttMove));
       return ttMove;
 
   case CAPTURE_INIT:
index 94ca68e..7a186e9 100644 (file)
@@ -926,7 +926,7 @@ bool Position::pseudo_legal(const Move m) const {
   {
       // We have already handled promotion moves, so destination
       // cannot be on the 8th/1st rank.
-      if (mandatory_pawn_promotion() && (promotion_zone_bb(us, promotion_rank(), max_rank()) & to))
+      if (mandatory_pawn_promotion() && rank_of(to) == relative_rank(us, promotion_rank(), max_rank()))
           return false;
 
       if (   !(attacks_from<PAWN>(us, from) & pieces(~us) & to) // Not a capture
@@ -956,7 +956,7 @@ bool Position::pseudo_legal(const Move m) const {
           // Our move must be a blocking evasion or a capture of the checking piece
           Square checksq = lsb(checkers());
           if (  !((between_bb(checksq, square<KING>(us)) | checkers()) & to)
-              || (LeaperAttacks[~us][type_of(piece_on(checksq))][checksq] & square<KING>(us)))
+              || ((LeaperAttacks[~us][type_of(piece_on(checksq))][checksq] & square<KING>(us)) && !(checkers() & to)))
               return false;
       }
       // In case of king moves under check we have to remove king so as to catch
index 33333d0..46ca3fb 100644 (file)
@@ -169,6 +169,7 @@ namespace {
 
     for (const auto& m : MoveList<LEGAL>(pos))
     {
+        assert(pos.pseudo_legal(m));
         if (Root && depth <= ONE_PLY)
             cnt = 1, nodes++;
         else