Implement sittuyin stalemate rule (#14)
authorFabian Fichter <ianfab@users.noreply.github.com>
Mon, 4 Mar 2019 19:22:44 +0000 (20:22 +0100)
committerFabian Fichter <ianfab@users.noreply.github.com>
Mon, 4 Mar 2019 20:06:07 +0000 (21:06 +0100)
Taking a promotion to avoid stalemate is optional (rule 3.9 c.7).

Example:
setoption name multipv value 20
setoption name UCI_Variant value sittuyin
position fen k5PK/3r4/8/8/8/8/8/8 b - - 0 1
go depth 1

No functional change for other variants.

src/position.cpp

index 7c6c007..3aa68ef 100644 (file)
@@ -1605,6 +1605,26 @@ bool Position::is_optional_game_end(Value& result, int ply) const {
       return true;
   }
 
+  // sittuyin stalemate due to optional promotion (3.9 c.7)
+  if (   sittuyin_promotion()
+      && count<ALL_PIECES>(sideToMove) == 2
+      && count<PAWN>(sideToMove) == 1
+      && !checkers())
+  {
+      bool promotionsOnly = true;
+      for (const auto& m : MoveList<LEGAL>(*this))
+          if (type_of(m) != PROMOTION)
+          {
+              promotionsOnly = false;
+              break;
+          }
+      if (promotionsOnly)
+      {
+          result = VALUE_DRAW;
+          return true;
+      }
+  }
+
   return false;
 }