Merge branch 'master-20091209' into gtk
[xboard.git] / backend.c
index 3223279..96e898a 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -2052,7 +2052,7 @@ read_from_ics(isr, closure, data, count, error)
      int count;
      int error;
 {
-#define BUF_SIZE 8192
+#define BUF_SIZE (16*1024) /* overflowed at 8K with "inchannel 1" on FICS? */
 #define STARTED_NONE 0
 #define STARTED_MOVES 1
 #define STARTED_BOARD 2
@@ -5458,8 +5458,6 @@ FinishMove(moveType, fromX, fromY, toX, toY, promoChar)
        }
       ModeHighlight();
     }
-    ModeHighlight();
-  }
 
   /* Relay move to ICS or chess engine */
   if (appData.icsActive)
@@ -5498,21 +5496,35 @@ FinishMove(moveType, fromX, fromY, toX, toY, promoChar)
   switch (gameMode) 
     {
     case EditGame:
-      switch (MateTest(boards[currentMove], PosFlags(currentMove)) ) {
-      case MT_NONE:
-      case MT_CHECK:
-       break;
-
+      switch (MateTest(boards[currentMove], PosFlags(currentMove)) ) 
+       {
+       case MT_NONE:
+       case MT_CHECK:
+         break;
+       case MT_CHECKMATE:
+       case MT_STAINMATE:
+         if (WhiteOnMove(currentMove)) {
+           GameEnds(BlackWins, "Black mates", GE_PLAYER);
+         } else {
+           GameEnds(WhiteWins, "White mates", GE_PLAYER);
+         }
+         break;
+       case MT_STALEMATE:
+         GameEnds(GameIsDrawn, "Stalemate", GE_PLAYER);
+         break;
+       }
+      break;
+      
     case MachinePlaysBlack:
     case MachinePlaysWhite:
       /* disable certain menu options while machine is thinking */
       SetMachineThinkingEnables();
       break;
-
+      
     default:
       break;
     }
-
+  
   if(bookHit)
     { // [HGM] book: simulate book reply
       static char bookMove[MSG_SIZ]; // a bit generous?
@@ -6952,8 +6964,13 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats.
                }
 
                 /* [AS] Negate score if machine is playing black and reporting absolute scores */
-                if( cps->scoreIsAbsolute &&
-                    ((gameMode == MachinePlaysBlack) || (gameMode == TwoMachinesPlay && cps->twoMachinesColor[0] == 'b')) )
+                if( cps->scoreIsAbsolute && 
+                    ( gameMode == MachinePlaysBlack ||
+                      gameMode == TwoMachinesPlay && cps->twoMachinesColor[0] == 'b' ||
+                      gameMode == IcsPlayingBlack ||     // [HGM] also add other situations where engine should report black POV
+                     (gameMode == AnalyzeMode || gameMode == AnalyzeFile || gameMode == IcsObserving && appData.icsEngineAnalyze) &&
+                     !WhiteOnMove(currentMove)
+                    ) )
                 {
                     curscore = -curscore;
                 }
@@ -13749,7 +13766,7 @@ PositionToFEN(move, overrideCastling)
     *p++ = ' ';
 
   if(q = overrideCastling) { // [HGM] FRC: override castling & e.p fields for non-compliant engines
-    while(*p++ = *q++); if(q != overrideCastling+1) p[-1] = ' ';
+    while(*p++ = *q++); if(q != overrideCastling+1) p[-1] = ' '; else --p;
   } else {
   if(nrCastlingRights) {
      q = p;