Improve calculation of thinking time in sudden-death games
authorH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 7 Mar 2014 12:30:14 +0000 (13:30 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 7 Mar 2014 12:30:14 +0000 (13:30 +0100)
GNU Chess seems to assume a session length of 50 moves in Fischer time
controls, and would be taken by surprise by the fact that it would not
receive new time after that. This is pretty fatal in sudden-death game,
when there is no time increment from which it could do the remaining
moves. So for sudden-death games in XBoard mode it now calculates the
thinking time as if there are at least still 30 moves to go.

gnushogi/rawdsp.c
gnushogi/tcontrl.c

index 45c2d8a..a63f86d 100644 (file)
@@ -761,8 +761,13 @@ Raw_SelectLevel(char *sx)
         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;
index 4e1da41..afdb32c 100644 (file)
@@ -163,11 +163,14 @@ void SetResponseTime(short side)
             {
                 short rtf = in_opening_stage ? 8 : 2;
                 short tcq = in_opening_stage ? 2 : 4;
+                int moves = TimeControl.moves[side];
 
                 if(!xboard) /* no pre-add of increment in XBoard mode */
                     TimeControl.clock[side] += TCadd;
+                if(TCflag == 2 && TCadd == 0) /* sudden death */
+                    moves = (moves < 30 ? 30 : moves);
                 ResponseTime = (TimeControl.clock[side])
-                    / (((TimeControl.moves[side]) * rtf) + 1);
+                    / (moves * rtf + 1);
                 TCleft = (long)ResponseTime / tcq;
                 ResponseTime += TCadd / 2;
             }
@@ -253,12 +256,15 @@ void SetResponseTime(short side)
         else
         {
             /* calculate avg time per move remaining */
+            int moves = TimeControl.moves[side];
 
             if(!xboard) /* no pre-add of increment in XBoard mode */
                 TimeControl.clock[side] += TCadd;
 
+            if(TCflag == 2 && TCadd == 0) /* sudden death */
+                moves = (moves < 30 ? 30 : moves);
             ResponseTime = (TimeControl.clock[side])
-                / (((TimeControl.moves[side]) * 2) + 1);
+                / (moves * 2 + 1);
             TCleft = (int) ResponseTime / 3;
             ResponseTime += TCadd / 2;