Added ICS engine analyze for winboard - not ready but usable
authorDaniel Mehrmann <mehrmann>
Tue, 22 Jun 2004 23:42:41 +0000 (23:42 +0000)
committerDaniel Mehrmann <mehrmann>
Tue, 22 Jun 2004 23:42:41 +0000 (23:42 +0000)
backend.c
common.h
winboard/winboard.c
xboard.c

index 673811c..8c795cd 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -4383,6 +4383,9 @@ HandleMachineMove(message, cps)
            break;
          case AnalyzeMode:
          case AnalyzeFile:
+         /* icsEngineAnalyze */
+         case IcsObserving:
+               if (!appData.icsEngineAnalyze) ignore = TRUE;
            break;
          case TwoMachinesPlay:
            if ((cps->twoMachinesColor[0] == 'w') !=
@@ -4445,8 +4448,8 @@ HandleMachineMove(message, cps)
                        prefixHint ? lastHint : "",
                        prefixHint ? " " : "", buf1);
 
-               if (currentMove == forwardMostMove ||
-                   gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
+               if (currentMove == forwardMostMove || gameMode == AnalyzeMode
+                       || gameMode == AnalyzeFile || appData.icsEngineAnalyze) {
                    DisplayMove(currentMove - 1);
                    DisplayAnalysis();
                }
@@ -4472,7 +4475,7 @@ HandleMachineMove(message, cps)
                programStats.line_is_book = 1;
 
                if (currentMove == forwardMostMove || gameMode==AnalyzeMode ||
-                   gameMode == AnalyzeFile) {
+                   gameMode == AnalyzeFile || appData.icsEngineAnalyze) {
                    DisplayMove(currentMove - 1);
                    DisplayAnalysis();
                }
@@ -4517,7 +4520,7 @@ HandleMachineMove(message, cps)
                strcat(programStats.movelist, " ");
                strcat(programStats.movelist, p);
                if (currentMove == forwardMostMove || gameMode==AnalyzeMode ||
-                   gameMode == AnalyzeFile) {
+                   gameMode == AnalyzeFile || appData.icsEngineAnalyze) {
                    DisplayMove(currentMove - 1);
                    DisplayAnalysis();
                }
@@ -7295,8 +7298,10 @@ AnalyzeModeEvent()
       return;
 
     if (gameMode != AnalyzeFile) {
-       EditGameEvent();
-       if (gameMode != EditGame) return;
+               if (!appData.icsEngineAnalyze) {
+                       EditGameEvent();
+               if (gameMode != EditGame) return;
+               }
        ResurrectChessProgram();
        SendToProgram("analyze\n", &first);
        first.analyzing = TRUE;
@@ -7305,7 +7310,7 @@ AnalyzeModeEvent()
        AnalysisPopUp(_("Analysis"),
                      _("Starting analysis mode...\nIf this message stays up, your chess program does not support analysis."));
     }
-    gameMode = AnalyzeMode;
+    if (!appData.icsEngineAnalyze) gameMode = AnalyzeMode;
     pausing = FALSE;
     ModeHighlight();
     SetGameInfo();
@@ -7771,6 +7776,9 @@ EditPositionEvent()
 void
 ExitAnalyzeMode()
 {
+       /* icsEngineAnalyze - possible call of other functions */
+       if (appData.icsEngineAnalyze) appData.icsEngineAnalyze = FALSE;
+
     if (first.analysisSupport && first.analyzing) {
       SendToProgram("exit\n", &first);
       first.analyzing = FALSE;
@@ -9240,7 +9248,8 @@ DisplayAnalysisText(text)
 {
     char buf[MSG_SIZ];
 
-    if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) {
+    if (gameMode == AnalyzeMode || gameMode == AnalyzeFile 
+               || appData.icsEngineAnalyze) {
        sprintf(buf, "Analysis (%s)", first.tidy);
        AnalysisPopUp(buf, text);
     }
index 62281a4..4a8c502 100644 (file)
--- a/common.h
+++ b/common.h
@@ -407,6 +407,7 @@ typedef struct {
     int firstProtocolVersion;
     int secondProtocolVersion;
     Boolean showButtonBar;
+       Boolean icsEngineAnalyze; 
 #if ZIPPY
     char *zippyLines;
     char *zippyPinhead;
index 4095feb..89051aa 100644 (file)
@@ -1611,6 +1611,7 @@ InitAppData(LPSTR lpCmdLine)
   appData.reuseFirst = TRUE;
   appData.reuseSecond = TRUE;
   appData.blindfold = FALSE;
+  appData.icsEngineAnalyze = FALSE;
   dcb.DCBlength = sizeof(DCB);
   dcb.BaudRate = 9600;
   dcb.fBinary = TRUE;
@@ -1627,7 +1628,7 @@ InitAppData(LPSTR lpCmdLine)
   dcb.fAbortOnError = FALSE;
   /* Microsoft SDK >= Feb. 2003 (MS VS >= 2002) */
   #if (defined(_MSC_VER) && _MSC_VER <= 1200) 
-       dcb.wReserved = 0;
+       //dcb.wReserved = 0;
   #else
     dcb.wReserved = 0;
   #endif
@@ -3404,6 +3405,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
   FILE *f;
   UINT number;
   char fileTitle[MSG_SIZ];
+  char buf[MSG_SIZ];
 
   switch (message) {
 
@@ -3638,15 +3640,37 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 
     case IDM_AnalysisMode:
       if (!first.analysisSupport) {
-        char buf[MSG_SIZ];
         sprintf(buf, "%s does not support analysis", first.tidy);
         DisplayError(buf, 0);
       } else {
+       /* icsEngineAnlyze */
+       if (appData.icsActive) {
+               if (gameMode != IcsObserving) {
+                       sprintf(buf, "You are not observing a game");
+                       DisplayError(buf, 0);
+                       /* secure check */
+                       if (appData.icsEngineAnalyze) {
+                               appData.icsEngineAnalyze = FALSE;
+                               ExitAnalyzeMode();
+                               ModeHighlight();
+                               break;
+                       }
+                       break;
+               } else {
+                       /* if enable, user want disable icsEngineAnalyze */
+                       if (appData.icsEngineAnalyze) {
+                               appData.icsEngineAnalyze = FALSE;
+                               ExitAnalyzeMode();
+                               ModeHighlight();
+                               break;
+                       }
+                       appData.icsEngineAnalyze = TRUE;
+               }
+       } 
        if (!appData.showThinking) ToggleShowThinking();
        AnalyzeModeEvent();
       }
       break;
-
     case IDM_AnalyzeFile:
       if (!first.analysisSupport) {
         char buf[MSG_SIZ];
@@ -4019,8 +4043,8 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
       AutoPlayGameLoop(); /* call into back end */
       break;
     case ANALYSIS_TIMER_ID:
-      if ((gameMode == AnalyzeMode || gameMode == AnalyzeFile) && 
-         appData.periodicUpdates) {
+      if ((gameMode == AnalyzeMode || gameMode == AnalyzeFile
+                 || appData.icsEngineAnalyze) && appData.periodicUpdates) {
        AnalysisPeriodicEvent(0);
       } else {
        KillTimer(hwnd, analysisTimerEvent);
@@ -6219,6 +6243,14 @@ ModeHighlight()
   }
 
   prevChecked = nowChecked;
+  /* icsEngineAnalyze - Do a sceure check too */
+  if (appData.icsEngineAnalyze) {
+       (void) CheckMenuItem(GetMenu(hwndMain), IDM_AnalysisMode,
+               MF_BYCOMMAND|MF_CHECKED);
+  } else {
+       (void) CheckMenuItem(GetMenu(hwndMain), IDM_AnalysisMode,
+               MF_BYCOMMAND|MF_UNCHECKED);
+  }
 }
 
 VOID
@@ -6231,6 +6263,10 @@ SetICSMode()
 #ifdef ZIPPY
   if (appData.zippyPlay) {
     SetMenuEnables(hmenu, zippyEnables);
+       /* icsEngineAnalyze */
+    if (!appData.noChessProgram) 
+         (void) EnableMenuItem(GetMenu(hwndMain), IDM_AnalysisMode,
+          MF_BYCOMMAND|MF_ENABLED);
   }
 #endif
 }
index 743a5ff..643be29 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -2466,6 +2466,9 @@ XBoard square size (hint): %d\n\
                    args, 1);
     }
 
+       /* icsEngineAnalyze - Currently not yet implemented in XBoard */
+       appData.icsEngineAnalyze = FALSE;
+
     /*
      * Create an icon.
      */