Defer book faking input move until ping balance
authorH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 28 Jul 2016 12:24:27 +0000 (14:24 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 28 Jul 2016 12:24:27 +0000 (14:24 +0200)
The use of ping after editing a position had broken the book handling:
'go' would be sent in the same batch of commands as this 'ping', so that
in case of a book hit the book move selected on behalf of the engine
would be fed back to XBoard before the engine had the opportunity to
restore the ping balanceby sending 'pong'. Now the book move is fed
through ScheduleDelayedEvent(DeferredBookMove) rather than instantly,
when a MachineWhite/BlackEvent sets the engine playing.

backend.c

index 5c37e3e..b288d6b 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -14877,7 +14877,9 @@ MachineWhiteEvent ()
 
        safeStrCpy(bookMove, "move ", sizeof(bookMove)/sizeof(bookMove[0]));
        strcat(bookMove, bookHit);
-       HandleMachineMove(bookMove, &first);
+       savedMessage = bookMove; // args for deferred call
+       savedState = &first;
+       ScheduleDelayedEvent(DeferredBookMove, 1);
     }
 }
 
@@ -14952,7 +14954,9 @@ MachineBlackEvent ()
 
        safeStrCpy(bookMove, "move ", sizeof(bookMove)/sizeof(bookMove[0]));
        strcat(bookMove, bookHit);
-       HandleMachineMove(bookMove, &first);
+       savedMessage = bookMove; // args for deferred call
+       savedState = &first;
+       ScheduleDelayedEvent(DeferredBookMove, 1);
     }
 }