Evaluate potential piece flips
authorFabian Fichter <ianfab@users.noreply.github.com>
Fri, 3 Jul 2020 21:17:00 +0000 (23:17 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Fri, 3 Jul 2020 21:17:00 +0000 (23:17 +0200)
reversi
LLR: 3.00 (-2.94,2.94) [0.00,10.00]
Total: 268 W: 178 L: 76 D: 14

src/evaluate.cpp

index 1b94859..22e6f6d 100644 (file)
@@ -1005,6 +1005,29 @@ namespace {
         }
     }
 
+    // Potential piece flips
+    if (pos.flip_enclosed_pieces())
+    {
+        // Stable
+        Bitboard corners = pos.pieces(Us) & (FileABB | file_bb(pos.max_file())) & (Rank1BB | rank_bb(pos.max_rank()));
+        Bitboard stable = 0;
+        while (corners)
+            stable |= attacks_bb(Us, ROOK, pop_lsb(&corners), ~pos.pieces(~Us)) & pos.pieces(Us);
+        score += make_score(300, 300) * popcount(stable);
+
+        // Unstable
+        Bitboard unstable = 0;
+        Bitboard drops = pos.drop_region(Them, IMMOBILE_PIECE);
+        while (drops)
+        {
+            Square s = pop_lsb(&drops);
+            Bitboard b = attacks_bb(Them, QUEEN, s, ~pos.pieces(Us)) & ~PseudoAttacks[Them][KING][s] & pos.pieces(Them);
+            while(b)
+                unstable |= between_bb(s, pop_lsb(&b));
+        }
+        score -= make_score(200, 200) * popcount(unstable);
+    }
+
     if (T)
         Trace::add(VARIANT, Us, score);