Improve calculation of thinking time in sudden-death games
[gnushogi.git] / gnushogi / rawdsp.c
index d9ebe36..a63f86d 100644 (file)
@@ -758,11 +758,16 @@ Raw_SelectLevel(char *sx)
     } else {
         int min, sec=0, inc, mps;
         /* parse regular "level MPS TC INC" command of WB protocol */
-        sscanf(sx, "%d %d %d", &mps, &min, &inc) == 3 ||
-        sscanf(sx, "%d %d:%d %d", &mps, &min, &sec, &inc);
+        if (sscanf(sx, "%d %d %d", &mps, &min, &inc) != 3)
+            sscanf(sx, "%d %d:%d %d", &mps, &min, &sec, &inc);
         TCminutes = min; TCseconds = sec;
-        TCadd = inc*100; TCmoves = mps ? mps : 50;
+        TCadd = inc*100; TCmoves = mps;
         MaxResponseTime = 0; TCflag = true;
+        if (!mps) /* Fischer TC or sudden death */
+        {
+            TCmoves = 50;
+            TCflag = 2; /* kludge to requests special calculation of ResponseTime */
+        }
     }
 
     TimeControl.clock[black] = TimeControl.clock[white] = 0;
@@ -980,7 +985,7 @@ Raw_PollForInput(void)
         Raw_ExitShogi();
     }
 #endif
-    if (cnt) { /* if anything to read, or error occured */
+    if (cnt && InputCommand(false)) { /* if anything to read, or error occured */
         if (!flag.timeout)
             flag.back = true; /* previous: flag.timeout = true; */
         flag.bothsides = false;