Update 50 move rule for xiangqi
authorFabian Fichter <ianfab@users.noreply.github.com>
Thu, 19 May 2022 18:12:47 +0000 (20:12 +0200)
committerFabian Fichter <ianfab@users.noreply.github.com>
Wed, 25 May 2022 09:47:42 +0000 (11:47 +0200)
Closes #405.

src/position.cpp

index 1e0d2fc..eaa37d6 100644 (file)
@@ -2314,8 +2314,26 @@ bool Position::is_optional_game_end(Value& result, int ply, int countStarted) co
   // n-move rule
   if (n_move_rule() && st->rule50 > (2 * n_move_rule() - 1) && (!checkers() || MoveList<LEGAL>(*this).size()))
   {
-      result = var->materialCounting ? convert_mate_value(material_counting_result(), ply) : VALUE_DRAW;
-      return true;
+      int offset = 0;
+      if (var->chasingRule == AXF_CHASING && st->pliesFromNull >= 20)
+      {
+          int end = std::min(st->rule50, st->pliesFromNull);
+          StateInfo* stp = st;
+          int checkThem = bool(stp->checkersBB);
+          int checkUs = bool(stp->previous->checkersBB);
+          for (int i = 2; i < end; i += 2)
+          {
+              stp = stp->previous->previous;
+              checkThem += bool(stp->checkersBB);
+              checkUs += bool(stp->previous->checkersBB);
+          }
+          offset = 2 * std::max(std::max(checkThem, checkUs) - 10, 0) + 20 * (CurrentProtocol == UCCI || CurrentProtocol == UCI_CYCLONE);
+      }
+      if (st->rule50 - offset > (2 * n_move_rule() - 1))
+      {
+          result = var->materialCounting ? convert_mate_value(material_counting_result(), ply) : VALUE_DRAW;
+          return true;
+      }
   }
 
   // n-fold repetition