Ignore checks in 50-move count for Xiangqi
authorH.G. Muller <h.g.muller@hccnet.nl>
Wed, 30 Jun 2010 08:41:25 +0000 (10:41 +0200)
committerArun Persaud <arun@nubati.net>
Thu, 1 Jul 2010 05:34:44 +0000 (22:34 -0700)
Both checks and evasions are discounted; this is only done after the
naive counting exceeds the maximum, so during most of the game it causes
no CPU load.

backend.c

index 742bf03..2df9b7d 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -6897,6 +6897,17 @@ Adjudicate(ChessProgramState *cps)
                 if( count == backwardMostMove )
                     count -= initialRulePlies;
                 count = forwardMostMove - count; 
+               if(gameInfo.variant == VariantXiangqi && ( count >= 100 || count >= 2*appData.ruleMoves ) ) {
+                       // adjust reversible move counter for checks in Xiangqi
+                       int i = forwardMostMove - count, inCheck = 0, lastCheck;
+                       if(i < backwardMostMove) i = backwardMostMove;
+                       while(i <= forwardMostMove) {
+                               lastCheck = inCheck; // check evasion does not count
+                               inCheck = (MateTest(boards[i], PosFlags(i)) == MT_CHECK);
+                               if(inCheck || lastCheck) count--; // check does not count
+                               i++;
+                       }
+               }
                 if( count >= 100)
                          boards[forwardMostMove][EP_STATUS] = EP_RULE_DRAW;
                          /* this is used to judge if draw claims are legal */