Fix bug in storing time of first move
authorH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 25 Nov 2016 21:59:35 +0000 (22:59 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 13 Jan 2017 15:39:23 +0000 (16:39 +0100)
TwoMachinesEvent() reset the clocks for re-calculating time odds (as the
first engine would play white, while any previous Reset() would have
assumed it played black). But it did not save the start time in the
tmeReamaining array. Actually TwoMachinesEvent() was not supposed to
unconditionally reset the clocks, and this bug was introduced when the
ResetClocks was moved out of the conditional, separating it from saving
the start times. It is nowput back inside the conditional, but the
condition is now also incorporating the case TwoMachineEvent() was called
at the start of a game (i.e. no moves done). When used to resume a game
in progress it keeps the existing clocks (except for engines that do not
support time/otim).

backend.c

index c3a68e7..196b8a0 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -15032,7 +15032,7 @@ WaitForEngine (ChessProgramState *cps, DelayedEventCallback retry)
 void
 TwoMachinesEvent P((void))
 {
-    int i;
+    int i, move = forwardMostMove;
     char buf[MSG_SIZ];
     ChessProgramState *onmove;
     char *bookHit = NULL;
@@ -15149,8 +15149,8 @@ TwoMachinesEvent P((void))
     }
   }
 
-    ResetClocks();
-    if (!first.sendTime || !second.sendTime) {
+    if (!first.sendTime || !second.sendTime || move == 0) { // [HGM] first engine changed sides from Reset, so recalc time odds
+       ResetClocks();
        timeRemaining[0][forwardMostMove] = whiteTimeRemaining;
        timeRemaining[1][forwardMostMove] = blackTimeRemaining;
     }