From 64ba62c1cc5d58a19a6a4cf755b6da3f9f05da4b Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Thu, 6 May 2010 17:23:24 +0200 Subject: [PATCH] Fix engine stall on perpetual-check evasion The adjudication code had already put the engine in force mode after postponing the actual adjudication to the next move. Now first determine if we want to adjudicate now, and with which result, before stopping the engine and ending the game. --- backend.c | 31 ++++++++++++++++--------------- 1 files changed, 16 insertions(+), 15 deletions(-) diff --git a/backend.c b/backend.c index 031141a..53799ec 100644 --- a/backend.c +++ b/backend.c @@ -6839,11 +6839,8 @@ Adjudicate(ChessProgramState *cps) if( rights == 0 && ++count > appData.drawRepeats-2 && canAdjudicate && appData.drawRepeats > 1) { /* adjudicate after user-specified nr of repeats */ - if(engineOpponent) { - SendToProgram("force\n", engineOpponent); // suppress reply - SendMoveToProgram(forwardMostMove-1, engineOpponent); /* make sure opponent gets to see move */ - } - ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ + int result = GameIsDrawn; + char *details = "XBoard adjudication: repetition draw"; if(gameInfo.variant == VariantXiangqi && appData.testLegality) { // [HGM] xiangqi: check for forbidden perpetuals int m, ourPerpetual = 1, hisPerpetual = 1; @@ -6856,27 +6853,31 @@ Adjudicate(ChessProgramState *cps) if(appData.debugMode) fprintf(debugFP, "XQ perpetual test, our=%d, his=%d\n", ourPerpetual, hisPerpetual); if(ourPerpetual && !hisPerpetual) { // we are actively checking him: forfeit - GameEnds( WhiteOnMove(forwardMostMove) ? WhiteWins : BlackWins, - "Xboard adjudication: perpetual checking", GE_XBOARD ); - return 1; - } - if(hisPerpetual && !ourPerpetual) // he is checking us, but did not repeat yet + result = WhiteOnMove(forwardMostMove) ? WhiteWins : BlackWins; + details = "Xboard adjudication: perpetual checking"; + } else + if(hisPerpetual && !ourPerpetual) { // he is checking us, but did not repeat yet break; // (or we would have caught him before). Abort repetition-checking loop. + } else // Now check for perpetual chases if(!ourPerpetual && !hisPerpetual) { // no perpetual check, test for chase hisPerpetual = PerpetualChase(k, forwardMostMove); ourPerpetual = PerpetualChase(k+1, forwardMostMove); if(ourPerpetual && !hisPerpetual) { // we are actively chasing him: forfeit - GameEnds( WhiteOnMove(forwardMostMove) ? WhiteWins : BlackWins, - "Xboard adjudication: perpetual chasing", GE_XBOARD ); - return 1; - } + result = WhiteOnMove(forwardMostMove) ? WhiteWins : BlackWins; + details = "Xboard adjudication: perpetual chasing"; + } else if(hisPerpetual && !ourPerpetual) // he is chasing us, but did not repeat yet break; // Abort repetition-checking loop. } // if neither of us is checking or chasing all the time, or both are, it is draw } - GameEnds( GameIsDrawn, "Xboard adjudication: repetition draw", GE_XBOARD ); + if(engineOpponent) { + SendToProgram("force\n", engineOpponent); // suppress reply + SendMoveToProgram(forwardMostMove-1, engineOpponent); /* make sure opponent gets to see move */ + } + ShowMove(fromX, fromY, toX, toY); /*updates currentMove*/ + GameEnds( result, details, GE_XBOARD ); return 1; } if( rights == 0 && count > 1 ) /* occurred 2 or more times before */ -- 1.7.0.4