Updated all files to GPL version 3.
[xboard.git] / backend.c
index b8cfa92..9c7e1c4 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -2,8 +2,10 @@
  * backend.c -- Common back end for X and Windows NT versions of\r
  * XBoard $Id: backend.c,v 2.6 2003/11/28 09:37:36 mann Exp $\r
  *\r
- * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts.\r
- * Enhancements Copyright 1992-2001 Free Software Foundation, Inc.\r
+ * Copyright 1991 by Digital Equipment Corporation, Maynard,\r
+ * Massachusetts.  Enhancements Copyright\r
+ * 1992-2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software\r
+ * Foundation, Inc.\r
  *\r
  * The following terms apply to Digital Equipment Corporation's copyright\r
  * interest in XBoard:\r
  * SOFTWARE.\r
  * ------------------------------------------------------------------------\r
  *\r
- * The following terms apply to the enhanced version of XBoard distributed\r
- * by the Free Software Foundation:\r
+ * The following terms apply to the enhanced version of XBoard\r
+ * distributed by the Free Software Foundation:\r
  * ------------------------------------------------------------------------\r
- * This program is free software; you can redistribute it and/or modify\r
+ *\r
+ * GNU XBoard is free software: you can redistribute it and/or modify\r
  * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
+ * the Free Software Foundation, either version 3 of the License, or (at\r
+ * your option) any later version.\r
  *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
+ * GNU XBoard is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * General Public License for more details.\r
  *\r
  * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * ------------------------------------------------------------------------\r
+ * along with this program. If not, see http://www.gnu.org/licenses/.  *\r
  *\r
- * See the file ChangeLog for a revision history.  */\r
+ *------------------------------------------------------------------------\r
+ ** See the file ChangeLog for a revision history.  */\r
 \r
 /* [AS] Also useful here for debugging */\r
 #ifdef WIN32\r
@@ -759,6 +761,10 @@ InitBackEnd1()
     first.debug = second.debug = FALSE;\r
     first.supportsNPS = second.supportsNPS = UNKNOWN;\r
 \r
+    /* [HGM] options */\r
+    first.optionSettings  = appData.firstOptions;\r
+    second.optionSettings = appData.secondOptions;\r
+\r
     first.scoreIsAbsolute = appData.firstScoreIsAbsolute; /* [AS] */\r
     second.scoreIsAbsolute = appData.secondScoreIsAbsolute; /* [AS] */\r
     first.isUCI = appData.firstIsUCI; /* [AS] */\r
@@ -7331,15 +7337,15 @@ MakeMove(fromX, fromY, toX, toY, promoChar)
      int fromX, fromY, toX, toY;\r
      int promoChar;\r
 {\r
-    forwardMostMove++;\r
+//    forwardMostMove++; // [HGM] bare: moved downstream\r
 \r
-    if(serverMoves != NULL) { /* [HGM] write moves on file for broadcasting */\r
+    if(serverMoves != NULL) { /* [HGM] write moves on file for broadcasting (should be separate routine, really) */\r
         int timeLeft; static int lastLoadFlag=0; int king, piece;\r
-        piece = boards[forwardMostMove-1][fromY][fromX];\r
+        piece = boards[forwardMostMove][fromY][fromX];\r
         king = piece < (int) BlackPawn ? WhiteKing : BlackKing;\r
         if(gameInfo.variant == VariantKnightmate)\r
             king += (int) WhiteUnicorn - (int) WhiteKing;\r
-        if(forwardMostMove == 1) {\r
+        if(forwardMostMove == 0) {\r
             if(blackPlaysFirst) \r
                 fprintf(serverMoves, "%s;", second.tidy);\r
             fprintf(serverMoves, "%s;", first.tidy);\r
@@ -7357,9 +7363,9 @@ MakeMove(fromX, fromY, toX, toY, promoChar)
                 fprintf(serverMoves, ":%c%c:%c%c", AAA+BOARD_LEFT, ONE+fromY, AAA+toX+1,ONE+toY);\r
         }\r
         // e.p. suffix\r
-        if( (boards[forwardMostMove-1][fromY][fromX] == WhitePawn ||\r
-             boards[forwardMostMove-1][fromY][fromX] == BlackPawn   ) &&\r
-             boards[forwardMostMove-1][toY][toX] == EmptySquare\r
+        if( (boards[forwardMostMove][fromY][fromX] == WhitePawn ||\r
+             boards[forwardMostMove][fromY][fromX] == BlackPawn   ) &&\r
+             boards[forwardMostMove][toY][toX] == EmptySquare\r
              && fromX != toX )\r
                 fprintf(serverMoves, ":%c%c:%c%c", AAA+fromX, ONE+fromY, AAA+toX, ONE+fromY);\r
         // promotion suffix\r
@@ -7367,28 +7373,29 @@ MakeMove(fromX, fromY, toX, toY, promoChar)
                 fprintf(serverMoves, ":%c:%c%c", promoChar, AAA+toX, ONE+toY);\r
         if(!loadFlag) {\r
             fprintf(serverMoves, "/%d/%d",\r
-               pvInfoList[forwardMostMove-1].depth, pvInfoList[forwardMostMove-1].score);\r
-            if(forwardMostMove & 1) timeLeft = whiteTimeRemaining/1000;\r
-            else                    timeLeft = blackTimeRemaining/1000;\r
+               pvInfoList[forwardMostMove].depth, pvInfoList[forwardMostMove].score);\r
+            if(forwardMostMove+1 & 1) timeLeft = whiteTimeRemaining/1000;\r
+            else                      timeLeft = blackTimeRemaining/1000;\r
             fprintf(serverMoves, "/%d", timeLeft);\r
         }\r
         fflush(serverMoves);\r
     }\r
 \r
-    if (forwardMostMove >= MAX_MOVES) {\r
+    if (forwardMostMove+1 >= MAX_MOVES) {\r
       DisplayFatalError(_("Game too long; increase MAX_MOVES and recompile"),\r
                        0, 1);\r
       return;\r
     }\r
     SwitchClocks();\r
-    timeRemaining[0][forwardMostMove] = whiteTimeRemaining;\r
-    timeRemaining[1][forwardMostMove] = blackTimeRemaining;\r
-    if (commentList[forwardMostMove] != NULL) {\r
-       free(commentList[forwardMostMove]);\r
-       commentList[forwardMostMove] = NULL;\r
-    }\r
-    CopyBoard(boards[forwardMostMove], boards[forwardMostMove - 1]);\r
-    ApplyMove(fromX, fromY, toX, toY, promoChar, boards[forwardMostMove]);\r
+    timeRemaining[0][forwardMostMove+1] = whiteTimeRemaining;\r
+    timeRemaining[1][forwardMostMove+1] = blackTimeRemaining;\r
+    if (commentList[forwardMostMove+1] != NULL) {\r
+       free(commentList[forwardMostMove+1]);\r
+       commentList[forwardMostMove+1] = NULL;\r
+    }\r
+    CopyBoard(boards[forwardMostMove+1], boards[forwardMostMove]);\r
+    ApplyMove(fromX, fromY, toX, toY, promoChar, boards[forwardMostMove+1]);\r
+    forwardMostMove++; // [HGM] bare: moved to after ApplyMove, to make sure clock interrupt finds complete board\r
     gameInfo.result = GameUnfinished;\r
     if (gameInfo.resultDetails != NULL) {\r
        free(gameInfo.resultDetails);\r
@@ -12377,6 +12384,14 @@ ParseOption(Option *opt, ChessProgramState *cps)
            opt->type = SaveButton;\r
        } else return FALSE;\r
        *p = 0; // terminate option name\r
+       // now look if the command-line options define a setting for this engine option.\r
+       p = strstr(cps->optionSettings, opt->name);\r
+       if(p == cps->optionSettings || p[-1] == ',') {\r
+               sprintf(buf, "option %s", p);\r
+               if(p = strstr(buf, ",")) *p = 0;\r
+               strcat(buf, "\n");\r
+               SendToProgram(buf, cps);\r
+       }\r
        return TRUE;\r
 }\r
 \r
@@ -12584,6 +12599,8 @@ DisplayMove(moveNumber)
     char res[MSG_SIZ];\r
     char cpThinkOutput[MSG_SIZ];\r
 \r
+    if(appData.noGUI) return; // [HGM] fast: suppress display of moves\r
+    \r
     if (moveNumber == forwardMostMove - 1 || \r
        gameMode == AnalyzeMode || gameMode == AnalyzeFile) {\r
 \r
@@ -12621,7 +12638,7 @@ DisplayMove(moveNumber)
     } else {\r
        res[0] = NULLCHAR;\r
     }\r
-    \r
+\r
     if (moveNumber < 0 || parseList[moveNumber][0] == NULLCHAR) {\r
        DisplayMessage(res, cpThinkOutput);\r
     } else {\r