Support prohibition of perpetual check
authorFabian Fichter <ianfab@users.noreply.github.com>
Sat, 12 Jan 2019 18:18:45 +0000 (19:18 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Sat, 12 Jan 2019 18:18:45 +0000 (19:18 +0100)
Completes the rule implementation of shogi variants.

src/position.cpp
src/variant.cpp
src/variant.h

index 9922efc..29ce04d 100644 (file)
@@ -1561,17 +1561,21 @@ bool Position::is_optional_game_end(Value& result, int ply) const {
 
       StateInfo* stp = st->previous->previous;
       int cnt = 0;
+      bool perpetual = true;
 
       for (int i = 4; i <= end; i += 2)
       {
           stp = stp->previous->previous;
+          perpetual &= bool(stp->checkersBB);
 
           // Return a draw score if a position repeats once earlier but strictly
           // after the root, or repeats twice before or at the root.
           if (   stp->key == st->key
               && ++cnt + 1 == (ply > i ? 2 : n_fold_rule()))
           {
-              result = convert_mate_value(var->nFoldValueAbsolute && sideToMove == BLACK ? -var->nFoldValue : var->nFoldValue, ply);
+              result = convert_mate_value(  var->perpetualCheckIllegal && perpetual ? VALUE_MATE
+                                          : var->nFoldValueAbsolute && sideToMove == BLACK ? -var->nFoldValue
+                                          : var->nFoldValue, ply);
               return true;
           }
       }
index 84260f5..14e2d9e 100644 (file)
@@ -271,6 +271,7 @@ VariantMap variants; // Global object
         v->stalemateValue = -VALUE_MATE;
         v->nFoldRule = 4;
         v->nMoveRule = 0;
+        v->perpetualCheckIllegal = true;
         return v;
     }
     Variant* minishogi_variant() {
index cd7421f..9fa1c0f 100644 (file)
@@ -73,6 +73,7 @@ struct Variant {
   int nFoldRule = 3;
   Value nFoldValue = VALUE_DRAW;
   bool nFoldValueAbsolute = false;
+  bool perpetualCheckIllegal = false;
   Value stalemateValue = VALUE_DRAW;
   Value checkmateValue = -VALUE_MATE;
   bool shogiPawnDropMateIllegal = false;