From: H.G. Muller Date: Fri, 6 Jan 2012 23:01:36 +0000 (+0100) Subject: Implement test for perpetual checking X-Git-Url: http://winboard.nl/cgi-bin?p=capablanca.git;a=commitdiff_plain;h=400af23d7b0fd6fdbf595afab97d09b79ed4e696 Implement test for perpetual checking --- diff --git a/lasker-2.2.3/src/gamedb.c b/lasker-2.2.3/src/gamedb.c index da255dc..d084f81 100644 --- a/lasker-2.2.3/src/gamedb.c +++ b/lasker-2.2.3/src/gamedb.c @@ -362,6 +362,10 @@ char *EndString(int g, int personal) sprintf(endstr, "%s bared", game_globals.garray[g].winner == WHITE ? blackguy : whiteguy); break; + case END_PERPETUAL: + sprintf(endstr, "%s perpetually checking", + game_globals.garray[g].winner == WHITE ? blackguy : whiteguy); + break; case END_RESIGN: sprintf(endstr, "%s resigned", game_globals.garray[g].winner == WHITE ? blackguy : whiteguy); @@ -442,6 +446,7 @@ const char *EndSym(int g) case END_FLAG: case END_ADJWIN: case END_BARE: + case END_PERPETUAL: return ((game_globals.garray[g].winner == WHITE) ? symbols[0] : symbols[1]); break; case END_AGREEDDRAW: diff --git a/lasker-2.2.3/src/gamedb.h b/lasker-2.2.3/src/gamedb.h index d0249b7..3ebd55c 100644 --- a/lasker-2.2.3/src/gamedb.h +++ b/lasker-2.2.3/src/gamedb.h @@ -69,6 +69,7 @@ GENSTRUCT enum gameend { END_ADJWIN, END_ADJABORT, END_COURTESYADJOURN, + END_PERPETUAL, END_BARE // [HGM] bare king }; diff --git a/lasker-2.2.3/src/gameproc.c b/lasker-2.2.3/src/gameproc.c index c5f5d35..e7378d2 100644 --- a/lasker-2.2.3/src/gameproc.c +++ b/lasker-2.2.3/src/gameproc.c @@ -144,6 +144,11 @@ void game_ended(int g, int winner, int why) strcpy(EndSymbol, "Bar"); rate_change = 1; break; + case END_PERPETUAL: + sprintf(tmp, "%s perpetually checking} %s", NameOfLoser, winSymbol); + strcpy(EndSymbol, "Per"); + rate_change = 1; + break; case END_RESIGN: sprintf(tmp, "%s resigns} %s", NameOfLoser, winSymbol); strcpy(EndSymbol, "Res"); @@ -882,6 +887,26 @@ static int Check50MoveRule (int p, int g) return 0; } +static int perp_check(struct game g, int first, int third) +{ + struct game_state_t gs = g.game_state; // current position, both first and last of loop + int half_move, no_perp = 0; +printf("perp %d %d\n",first,third); + for(half_move=first+1; half_move= game_globals.garray[g].game_state.lastIrreversable - 1; move_num--) { pos = GetFENpos (g, move_num); if (strlen(pos1) == strlen(pos) && !strcmp(pos1, pos)) - flag1++; + flag1++ == 2 && (s1 = move_num); if (strlen(pos2) == strlen(pos) && !strcmp(pos2, pos)) - flag2++; -printf("%2d. %d-%d %s %s %s\n", move_num, flag1, flag2, pos1,pos2,pos); + flag2++ == 2 && (s2 = move_num); // remember start of last two loops +printf("%2d. %d-%d '%s' '%s' '%s'\n", move_num, flag1, flag2, pos1,pos2,pos); } if (flag1 >= 3 || flag2 >= 3) { if ((pend = find_pend(pp->opponent, p, PEND_DRAW)) != NULL) { delete_pending(pend); decline_withdraw_offers(p, -1, -1,DO_DECLINE); } - game_ended(g, (game_globals.garray[g].white == p) ? BLACK : WHITE, END_REPETITION); + if(game_globals.garray[g].game_state.palace) { // [HGM] in Xiangqi we have to test for perpetuals to determine the outcome + if(flag2 >= 3) result = perp_check(game_globals.garray[g], s2, numPly); + else result = perp_check(game_globals.garray[g], s1, numPly - (pos2[0] != 0)); + if(result == END_NOTENDED) { + pprintf(p, "Perpetuals can be claimed only during the turn of the winner\n"); + return 1; + } + game_ended(g, (numPly&1) ? BLACK : WHITE, result); // stm wins + return 1; + } + game_ended(g, (game_globals.garray[g].white == p) ? BLACK : WHITE, result); return 1; } else return 0;