From 545c9779f7df75b584e19417fa24f82479e10c11 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Mon, 24 Oct 2011 19:20:13 +0200 Subject: [PATCH] Use other interpretation of Asia rules for chase detection The detection of perpetual chases now ignores pre-existing checks. --- moves.c | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/moves.c b/moves.c index a8f55b6..0d8d146 100644 --- a/moves.c +++ b/moves.c @@ -717,6 +717,7 @@ typedef struct { } GenLegalClosure; int rFilter, fFilter; // [HGM] speed: sorry, but I get a bit tired of this closure madness +Board xqCheckers, nullBoard; extern void GenLegalCallback P((Board board, int flags, ChessMove kind, int rf, int ff, int rt, int ft, @@ -785,14 +786,15 @@ int GenLegal(board, flags, callback, closure, filter) int ff, ft, k, left, right, swap; int ignoreCheck = (flags & F_IGNORE_CHECK) != 0; ChessSquare wKing = WhiteKing, bKing = BlackKing, *castlingRights = board[CASTLING]; + int inCheck = !ignoreCheck && CheckTest(board, flags, -1, -1, -1, -1, FALSE); // kludge alert: this would mark pre-existing checkers if status==1 cl.cb = callback; cl.cl = closure; + xqCheckers[EP_STATUS] *= 2; // quasi: if previous CheckTest has been marking, we now set flag for suspending same checkers if(filter == EmptySquare) rFilter = fFilter = -1; // [HGM] speed: do not filter on square if we do not filter on piece GenPseudoLegal(board, flags, GenLegalCallback, (VOIDSTAR) &cl, filter); - if (!ignoreCheck && - CheckTest(board, flags, -1, -1, -1, -1, FALSE)) return TRUE; + if (inCheck) return TRUE; /* Generate castling moves */ if(gameInfo.variant == VariantKnightmate) { /* [HGM] Knightmate */ @@ -971,7 +973,11 @@ void CheckTestCallback(board, flags, kind, rf, ff, rt, ft, closure) { register CheckTestClosure *cl = (CheckTestClosure *) closure; - if (rt == cl->rking && ft == cl->fking) cl->check++; + if (rt == cl->rking && ft == cl->fking) { + if(xqCheckers[EP_STATUS] >= 2 && xqCheckers[rf][ff]) return; // checker is piece with suspended checking power + cl->check++; + xqCheckers[rf][ff] = xqCheckers[EP_STATUS] & 1; // remember who is checking (if status == 1) + } } @@ -1841,7 +1847,9 @@ int PerpetualChase(int first, int last) cl.ff = moveList[i][0]-AAA+BOARD_LEFT; cl.rt = moveList[i][3]-ONE; cl.ft = moveList[i][2]-AAA+BOARD_LEFT; + CopyBoard(xqCheckers, nullBoard); xqCheckers[EP_STATUS] = 1; // giant kludge to make GenLegal ignore pre-existing checks GenLegal(boards[i], PosFlags(i), ExistingAttacksCallback, &cl, EmptySquare); + xqCheckers[EP_STATUS] = 0; // disable the generation of quasi-legal moves again if(appData.debugMode) { int n; for(n=0; n