I put in testing for the winning condition in 3checks
authorH.G. Muller <h.g.muller@hccnet.nl>
Thu, 25 Jun 2009 05:49:33 +0000 (22:49 -0700)
committerArun Persaud <arun@nubati.net>
Thu, 25 Jun 2009 05:49:33 +0000 (22:49 -0700)
on a check it just goes through the entire game to subject every position on a check test, to see if there were two more.

backend.c

index 3c3ff37..23ec636 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -831,7 +831,7 @@ InitBackEnd1()
        q = first.program;\r
        while (*q != ' ' && *q != NULLCHAR) q++;\r
        p = q;\r
-       while (p > first.program && *(p-1) != '/' && *(p-1) != '\\') p--; /* [HGM] bckslash added */\r
+       while (p > first.program && *(p-1) != '/' && *(p-1) != '\\') p--; /* [HGM] backslash added */\r
        programVersion = (char*) malloc(8 + strlen(PRODUCT) + strlen(VERSION)\r
                                        + strlen(PATCHLEVEL) + (q - p));\r
        sprintf(programVersion, "%s %s.%s + ", PRODUCT, VERSION, PATCHLEVEL);\r
@@ -5794,8 +5794,20 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
             // don't wait for engine to announce game end if we can judge ourselves\r
             switch (MateTest(boards[forwardMostMove], PosFlags(forwardMostMove), epFile,\r
                                        castlingRights[forwardMostMove]) ) {\r
-             case MT_NONE:\r
              case MT_CHECK:\r
+               if(gameInfo.variant == Variant3Check) { // [HGM] 3check: when in check, test if 3rd time\r
+                   int i, checkCnt = 0;    // (should really be done by making nr of checks part of game state)\r
+                   for(i=forwardMostMove-2; i>=backwardMostMove; i-=2) {\r
+                       if(MateTest(boards[i], PosFlags(i), epStatus[i], castlingRights[i]) == MT_CHECK)\r
+                           checkCnt++;\r
+                       if(checkCnt >= 2) {\r
+                           reason = "Xboard adjudication: 3rd check";\r
+                           epStatus[forwardMostMove] = EP_CHECKMATE;\r
+                           break;\r
+                       }\r
+                   }\r
+               }\r
+             case MT_NONE:\r
              default:\r
                break;\r
              case MT_STALEMATE:\r