I have posted a fix for this timing bug in Chenard: it is version 2009.09.19. Please use the link below in my signature line, download the latest wxchenard.zip and replace your copy of xchenard.exe with the contents of that zip file.
It was a fairly simple fix, but for the sake of other authors of WinBoard-compatible chess engines, I think it might be helpful to offer some insight into what I had to do, because there was one slightly tricky bit. WinBoard will send you a "time" command to inform you of how much time you have left, before it sends you the opponent's move (or before the "go" command on the first move). This means it is not your engine's turn (yet). However, if your engine supports pondering, and it is in the middle of pondering when the opponent's move arrives, and that move is not what you expected (pondering miss), you will probably want to call the same time budgeting function after receiving the opponent's move, not after receiving the preceding "time" command. At least this is what I did.
This leads to a special case: in the first case, it is not yet your engine's turn, but in the second case it is. I had to detect whether it was XChenard's turn or not. If not, I pretend like it is by using plycount+1, otherwise I use plycount. Here a code snippet that is executed only when TotalMovesPerPeriod > 0:
- Code: Select all
const bool computersTurn = IsComputersTurn();
const int plyCounter = MoveUndoIndex + (computersTurn ? 0 : 1);
const int plyWithinPeriod = plyCounter % (2 * TotalMovesPerPeriod);
const int myRemainingMoves = TotalMovesPerPeriod - (plyWithinPeriod/2);
(You can download the complete C++ source code from my site if you are curious, and find this in xchenard.cpp in the function TimeBudgetForNextMove.)
I tried to test all the special cases (XChenard playing White and Black, pondering and no pondering, pondering miss and pondering hit). I believe it is all working correctly, but hopefully Gabor can re-test with Arena and external opening books and let us know!