Limit pawn moves to variant board size
authorFabian Fichter <ianfab@users.noreply.github.com>
Mon, 27 Sep 2021 19:41:51 +0000 (21:41 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Mon, 27 Sep 2021 19:41:51 +0000 (21:41 +0200)
Closes #372.

setup.py
src/movegen.cpp
src/pyffish.cpp
test.py
tests/perft.sh

index 72422ee..f964dff 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -39,7 +39,7 @@ pyffish_module = Extension(
     sources=sources,
     extra_compile_args=args)
 
-setup(name="pyffish", version="0.0.61",
+setup(name="pyffish", version="0.0.62",
       description="Fairy-Stockfish Python wrapper",
       long_description=long_description,
       long_description_content_type="text/markdown",
index 4daa190..7d11d74 100644 (file)
@@ -115,7 +115,7 @@ namespace {
     Bitboard  TRank3BB =  forward_ranks_bb(Us, relative_rank(Us, pos.double_step_rank_min(), pos.max_rank()))
                         & ~shift<Up>(forward_ranks_bb(Us, relative_rank(Us, pos.double_step_rank_max(), pos.max_rank())));
 
-    const Bitboard emptySquares = Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces();
+    const Bitboard emptySquares = Type == QUIETS || Type == QUIET_CHECKS ? target : ~pos.pieces() & pos.board_bb();
     const Bitboard enemies      = Type == EVASIONS ? (pos.checkers() & pos.non_sliding_riders() ? pos.pieces(Them) : pos.checkers())
                                 : Type == CAPTURES ? target : pos.pieces(Them);
 
index 3462beb..7551385 100644 (file)
@@ -54,7 +54,7 @@ void buildPosition(Position& pos, StateListPtr& states, const char *variant, con
 }
 
 extern "C" PyObject* pyffish_version(PyObject* self) {
-    return Py_BuildValue("(iii)", 0, 0, 61);
+    return Py_BuildValue("(iii)", 0, 0, 62);
 }
 
 extern "C" PyObject* pyffish_info(PyObject* self) {
diff --git a/test.py b/test.py
index 2dc7f5b..d2696a5 100644 (file)
--- a/test.py
+++ b/test.py
@@ -647,6 +647,11 @@ class TestPyffish(unittest.TestCase):
         result = sf.is_optional_game_end("capablanca", CAPA, [])
         self.assertFalse(result[0])
 
+        # sittuyin stalemate due to optional promotion
+        result = sf.is_optional_game_end("sittuyin", "1k4PK/3r4/8/8/8/8/8/8[] w - - 0 1", [])
+        self.assertTrue(result[0])
+        self.assertEqual(result[1], sf.VALUE_DRAW)
+
     def test_has_insufficient_material(self):
         for variant, positions in variant_positions.items():
             for fen, expected_result in positions.items():
index 946f88a..5f2ae0d 100755 (executable)
@@ -50,6 +50,7 @@ if [[ $1 == "all" || $1 == "variant" ]]; then
   expect perft.exp sittuyin "fen 8/8/6R1/s3r3/P5R1/1KP3p1/1F2kr2/8[] b - - 0 72" 4 652686 > /dev/null
   expect perft.exp sittuyin "fen 2r5/6k1/6p1/3s2P1/3npR2/8/p2N2F1/3K4[] w - - 1 50" 4 373984 > /dev/null
   expect perft.exp sittuyin "fen 8/6s1/5P2/3n4/pR2K2S/1P6/1k4p1/8[] w - - 1 50" 4 268869 > /dev/null
+  expect perft.exp sittuyin "fen 1k5K/3r2P1/8/8/8/8/8/8[] w - - 0 1" 5 68662 > /dev/null
   expect perft.exp shatranj startpos 4 68122 > /dev/null
   expect perft.exp amazon startpos 4 318185 > /dev/null
   expect perft.exp nightrider startpos 4 419019 > /dev/null