X-Git-Url: http://winboard.nl/cgi-bin?p=capablanca.git;a=blobdiff_plain;f=lasker-2.2.3%2Fsrc%2Fgameproc.c;h=e7378d23ab772070ae9839b1cc9dd12f3c4a264c;hp=c5f5d35b3c9859df81dc141ccffee3bbbc01f892;hb=400af23d7b0fd6fdbf595afab97d09b79ed4e696;hpb=9203fbd284de0e25777d8587a6ed943686cdcb13 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;