Generalize SAN disambiguation
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 20 Jun 2020 13:01:26 +0000 (15:01 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 20 Jun 2020 13:01:26 +0000 (15:01 +0200)
Closes #152.

src/pyffish.cpp
test.py

index 89bf194..814a309 100644 (file)
@@ -169,18 +169,16 @@ Disambiguation disambiguation_level(const Position& pos, Move m, Notation n) {
 
     // A disambiguation occurs if we have more then one piece of type 'pt'
     // that can reach 'to' with a legal move.
-    Bitboard others, b;
-    others = b = ((pos.capture(m) ? attacks_bb(~us, pt, to, AttackRiderTypes[pt] & ASYMMETRICAL_RIDERS ? Bitboard(0) : pos.pieces())
-                                  : moves_bb(  ~us, pt, to, MoveRiderTypes[pt] & ASYMMETRICAL_RIDERS ? Bitboard(0) : pos.pieces()))
-                & pos.pieces(us, pt)) & ~square_bb(from);
+    Bitboard b = pos.pieces(us, pt) ^ from;
+    Bitboard others = 0;
 
     while (b)
     {
         Square s = pop_lsb(&b);
-        if (   !pos.pseudo_legal(make_move(s, to))
-            || !pos.legal(make_move(s, to))
-            || (is_shogi(n) && pos.unpromoted_piece_on(s) != pos.unpromoted_piece_on(from)))
-            others ^= s;
+        if (   pos.pseudo_legal(make_move(s, to))
+            && pos.legal(make_move(s, to))
+            && !(is_shogi(n) && pos.unpromoted_piece_on(s) != pos.unpromoted_piece_on(from)))
+            others |= s;
     }
 
     if (!others)
diff --git a/test.py b/test.py
index 11ebe34..0fee247 100644 (file)
--- a/test.py
+++ b/test.py
@@ -382,9 +382,6 @@ class TestPyffish(unittest.TestCase):
         result = sf.get_san("xiangqi", fen, "e7d7", False, sf.NOTATION_XIANGQI_WXF)
         self.assertEqual(result, "15=6")
 
-        result = sf.get_san("janggi", JANGGI, "b1c3", False, sf.NOTATION_JANGGI)
-        self.assertEqual(result, "H02-83")
-
         fen = "1rb1ka2r/4a4/2ncb1nc1/p1p1p1p1p/9/2P6/P3PNP1P/2N1C2C1/9/R1BAKAB1R w - - 1 7"
         result = sf.get_san("xiangqi", fen, "c3e2")
         self.assertEqual(result, "Hce2")
@@ -392,6 +389,17 @@ class TestPyffish(unittest.TestCase):
         result = sf.get_san("xiangqi", fen, "c3d5")
         self.assertEqual(result, "Hd5")
 
+        result = sf.get_san("janggi", JANGGI, "b1c3", False, sf.NOTATION_JANGGI)
+        self.assertEqual(result, "H02-83")
+
+        fen = "1b1aa2b1/5k3/3ncn3/1pp1pp3/5r2p/9/P1PPB1PPB/2N1CCN1c/9/R2AKAR2 w - - 19 17"
+        result = sf.get_san("janggi", fen, "d1e2", False, sf.NOTATION_SAN)
+        self.assertEqual(result, "Ade2")
+
+        fen = "1Pbcka3/3nNn1c1/N2CaC3/1pB6/9/9/5P3/9/4K4/9 w - - 0 23"
+        result = sf.get_san("janggi", fen, "f8f10", False, sf.NOTATION_SAN)
+        self.assertEqual(result, "Cfxf10")
+
         fen = "rnsm1s1r/4n1k1/1ppppppp/p7/2PPP3/PP3PPP/4N2R/RNSKMS2 b - - 1 5"
         result = sf.get_san("makruk", fen, "f8f7")
         self.assertEqual(result, "Sf7")