some small bugfixes
authorH.G. Muller <h.g.muller@hccnet.nl>
Sat, 13 Jun 2009 22:27:26 +0000 (15:27 -0700)
committerArun Persaud <arun@nubati.net>
Sat, 13 Jun 2009 22:27:26 +0000 (15:27 -0700)
I had overlooked one place from which the FEN writer (of whicf I changed the argument types), which made WB crash if you copied a FEN (or PGN that cotained FEN) to the clipboard. I must have overlooked a warning during compile, or some depedency is not correct in the makefile. Anyway, wclipboard.c had to be changed.

I also moved adjudication of some losing conditions to before tetsing for stalemate, (e.g. in atomic, if your king get destroyd you lose, even if you have no moves after that because it was your only piece.). this affects backend.c.

I had used the same bits in the frule-modifier flags for indicating mandatory capture as was already used for indicating FRC-style castling. This led to frequent illegal move calls in FRC... (moves.h)

backend.c
moves.h
winboard/wclipbrd.c

index c34724e..0f24243 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -5606,6 +5606,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
                         machineMove, fromX+AAA, fromY+ONE, toX+AAA, toY+ONE, 0);\r
                 GameEnds(machineWhite ? BlackWins : WhiteWins,\r
                            buf1, GE_XBOARD);\r
+               return;\r
            } else if(gameInfo.variant != VariantFischeRandom && gameInfo.variant != VariantCapaRandom)\r
            /* [HGM] Kludge to handle engines that send FRC-style castling\r
               when they shouldn't (like TSCP-Gothic) */\r
@@ -5699,42 +5700,6 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
             int k, count = 0, epFile = epStatus[forwardMostMove]; static int bare = 1;\r
          if(gameInfo.holdingsSize == 0 || gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) {\r
 \r
-            if(appData.testLegality)\r
-            // don't wait for engine to announce game end if we can judge ourselves\r
-            switch (MateTest(boards[forwardMostMove],\r
-                                 PosFlags(forwardMostMove), epFile,\r
-                                       castlingRights[forwardMostMove]) ) {\r
-             case MT_NONE:\r
-             case MT_CHECK:\r
-             default:\r
-               break;\r
-             case MT_STALEMATE:\r
-               epStatus[forwardMostMove] = EP_STALEMATE;\r
-                if(appData.checkMates) {\r
-                   SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */\r
-                   ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/\r
-                   if(gameInfo.variant == VariantLosers || gameInfo.variant == VariantSuicide\r
-                                                        || gameInfo.variant == VariantGiveaway) // [HGM] losers:\r
-                       GameEnds( WhiteOnMove(forwardMostMove) ? WhiteWins : BlackWins, // stalemated side wins!\r
-                               "Xboard adjudication: Stalemate", GE_XBOARD );\r
-                   else\r
-                       GameEnds( GameIsDrawn, "Xboard adjudication: Stalemate", GE_XBOARD );\r
-                   return;\r
-               }\r
-               break;\r
-             case MT_CHECKMATE:\r
-               epStatus[forwardMostMove] = EP_CHECKMATE;\r
-                if(appData.checkMates) {\r
-                   SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */\r
-                   ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/\r
-                   GameEnds( WhiteOnMove(forwardMostMove) != (gameInfo.variant == VariantLosers) // [HGM] losers:\r
-                            ? BlackWins : WhiteWins,            // reverse the result ( A!=1 is !A for a boolean)\r
-                            "Xboard adjudication: Checkmate", GE_XBOARD );\r
-                   return;\r
-               }\r
-               break;\r
-           }\r
-\r
            if( appData.testLegality )\r
            {   /* [HGM] Some more adjudications for obstinate engines */\r
                int NrWN=0, NrBN=0, NrWB=0, NrBB=0, NrWR=0, NrBR=0,\r
@@ -5742,7 +5707,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
                     NrPieces=0, NrPawns=0, PawnAdvance=0, i, j;\r
                static int moveCount = 6;\r
 \r
-                /* First absolutely insufficient mating material. Count what is on board. */\r
+                /* Count what is on board. */\r
                for(i=0; i<BOARD_HEIGHT; i++) for(j=BOARD_LEFT; j<BOARD_RGHT; j++)\r
                {   ChessSquare p = boards[forwardMostMove][i][j];\r
                    int m=i;\r
@@ -5788,6 +5753,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
                    }\r
                 }\r
 \r
+               /* Some material-based adjudications that have to be made before stalemate test */\r
                if(gameInfo.variant == VariantAtomic && NrK < 2) {\r
                    // [HGM] atomic: stm must have lost his King on previous move, as destroying own K is illegal\r
                     epStatus[forwardMostMove] = EP_CHECKMATE; // make claimable as if stm is checkmated\r
@@ -5827,6 +5793,43 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h
                 } else bare = 1;\r
 \r
 \r
+            // don't wait for engine to announce game end if we can judge ourselves\r
+            switch (MateTest(boards[forwardMostMove],\r
+                                 PosFlags(forwardMostMove), epFile,\r
+                                       castlingRights[forwardMostMove]) ) {\r
+             case MT_NONE:\r
+             case MT_CHECK:\r
+             default:\r
+               break;\r
+             case MT_STALEMATE:\r
+               if(epStatus[forwardMostMove] != EP_CHECKMATE) // [HGM] spare win through baring or K-capt\r
+                   epStatus[forwardMostMove] = EP_STALEMATE;\r
+                if(appData.checkMates) {\r
+                   SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */\r
+                   ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/\r
+                   if(gameInfo.variant == VariantLosers || gameInfo.variant == VariantSuicide\r
+                                                        || gameInfo.variant == VariantGiveaway) // [HGM] losers:\r
+                       GameEnds( WhiteOnMove(forwardMostMove) ? WhiteWins : BlackWins, // stalemated side wins!\r
+                               "Xboard adjudication: Stalemate", GE_XBOARD );\r
+                   else\r
+                       GameEnds( GameIsDrawn, "Xboard adjudication: Stalemate", GE_XBOARD );\r
+                   return;\r
+               }\r
+               break;\r
+             case MT_CHECKMATE:\r
+               epStatus[forwardMostMove] = EP_CHECKMATE;\r
+                if(appData.checkMates) {\r
+                   SendMoveToProgram(forwardMostMove-1, cps->other); /* make sure opponent gets to see move */\r
+                   ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/\r
+                   GameEnds( WhiteOnMove(forwardMostMove) != (gameInfo.variant == VariantLosers) // [HGM] losers:\r
+                            ? BlackWins : WhiteWins,            // reverse the result ( A!=1 is !A for a boolean)\r
+                            "Xboard adjudication: Checkmate", GE_XBOARD );\r
+                   return;\r
+               }\r
+               break;\r
+           }\r
+\r
+                /* Next absolutely insufficient mating material. */\r
                 if( NrPieces == 2 || gameInfo.variant != VariantXiangqi && \r
                                     gameInfo.variant != VariantShatranj && // [HGM] baring will remain possible\r
                        (NrPieces == 3 && NrWN+NrBN+NrWB+NrBB == 1 ||\r
diff --git a/moves.h b/moves.h
index 50e6c17..73cf604 100644 (file)
--- a/moves.h
+++ b/moves.h
@@ -77,7 +77,7 @@ typedef void (*MoveCallback) P((Board board, int flags, ChessMove kind,
                                   and all non-pawns on adjacent squares; 
                                   destroying your own king is illegal */
 #define F_FRC_TYPE_CASTLING 256 /* generate castlings as captures of own Rook */
-#define F_MANDATORY_CAPTURE 0x100
+#define F_MANDATORY_CAPTURE 0x200
 
 /* Special epfile values. [HGM] positive values are non-reversible moves! */
 #define EP_NONE (-4)           /* [HGM] Tricky! order matters:            */
index 838d250..b187344 100644 (file)
@@ -48,7 +48,7 @@ CopyFENToClipboard()
 {\r
   char *fen = NULL;\r
 \r
-  fen = PositionToFEN(currentMove,1);\r
+  fen = PositionToFEN(currentMove, NULL);\r
   if (!fen) {\r
     DisplayError("Unable to convert position to FEN.", 0);\r
     return;\r