X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=moves.c;h=970393f3299c8901f85b04ac76151acbb3373af8;hb=3bfa1af62f41c7da05fa150d0b46ad6d09c88cca;hp=67c98ed03e1906c71e023584c90d556b864c2ce3;hpb=be7d8e737e7144bd860de497842424aa743be93f;p=xboard.git diff --git a/moves.c b/moves.c index 67c98ed..970393f 100644 --- a/moves.c +++ b/moves.c @@ -65,6 +65,7 @@ int WhitePiece P((ChessSquare)); int BlackPiece P((ChessSquare)); int SameColor P((ChessSquare, ChessSquare)); +int PosFlags(int index); extern char initialRights[BOARD_SIZE]; /* [HGM] all rights enabled, set in InitPosition */ @@ -647,7 +648,7 @@ void GenPseudoLegal(board, flags, epfile, callback, closure) case SHOGI BlackKing: case WhiteKing: case BlackKing: - walking: +// walking: for (i = -1; i <= 1; i++) for (j = -1; j <= 1; j++) { if (i == 0 && j == 0) continue; @@ -726,6 +727,7 @@ void GenLegalCallback(board, flags, kind, rf, ff, rt, ft, closure) typedef struct { int rf, ff, rt, ft; ChessMove kind; + int captures; // [HGM] losers } LegalityTestClosure; @@ -1025,6 +1027,8 @@ void LegalityTestCallback(board, flags, kind, rf, ff, rt, ft, closure) // if (appData.debugMode) { // fprintf(debugFP, "Legality test: %c%c%c%c\n", ff+AAA, rf+ONE, ft+AAA, rt+ONE); // } + if(board[rt][ft] != EmptySquare || kind==WhiteCapturesEnPassant || kind==BlackCapturesEnPassant) + cl->captures++; // [HGM] losers: count legal captures if (rf == cl->rf && ff == cl->ff && rt == cl->rt && ft == cl->ft) cl->kind = kind; } @@ -1054,7 +1058,11 @@ ChessMove LegalityTest(board, flags, epfile, castlingRights, rf, ff, rt, ft, pro cl.rt = rt; cl.ft = ft; cl.kind = IllegalMove; + cl.captures = 0; // [HGM] losers: prepare to count legal captures. GenLegal(board, flags, epfile, castlingRights, LegalityTestCallback, (VOIDSTAR) &cl); + if((flags & F_MANDATORY_CAPTURE) && cl.captures && board[rt][ft] == EmptySquare + && cl.kind != WhiteCapturesEnPassant && cl.kind != BlackCapturesEnPassant) + return(IllegalMove); // [HGM] losers: if there are legal captures, non-capts are illegal if(gameInfo.variant == VariantShogi) { /* [HGM] Shogi promotions. '=' means defer */ @@ -1137,8 +1145,9 @@ int MateTest(board, flags, epfile, castlingRights) if (cl.count > 0) { return inCheck ? MT_CHECK : MT_NONE; } else { - return inCheck || gameInfo.variant == VariantXiangqi || gameInfo.variant == VariantShatranj ? - MT_CHECKMATE : MT_STALEMATE; + return inCheck ? MT_CHECKMATE + : (gameInfo.variant == VariantXiangqi || gameInfo.variant == VariantShatranj) ? + MT_STAINMATE : MT_STALEMATE; } } @@ -1680,11 +1689,11 @@ void ProtectedCallback(board, flags, kind, rf, ff, rt, ft, closure) int rf, ff, rt, ft; VOIDSTAR closure; { // for determining if a piece (given through the closure) is protected - register ChaseClosure *cl = (ChaseClosure *) closure; // closure tells us where to recapture - - if(rt == cl->rt && ft == cl->ft) cl->recaptures++; // count legal recaptures to this square - if(appData.debugMode && board[rt][ft] != EmptySquare) - fprintf(debugFP, "try %c%c%c%c=%d\n", ff+AAA, rf+ONE,ft+AAA, rt+ONE, cl->recaptures); + register ChaseClosure *cl = (ChaseClosure *) closure; // closure tells us where to recapture + + if(rt == cl->rt && ft == cl->ft) cl->recaptures++; // count legal recaptures to this square + if(appData.debugMode && board[rt][ft] != EmptySquare) + fprintf(debugFP, "try %c%c%c%c=%d\n", ff+AAA, rf+ONE,ft+AAA, rt+ONE, cl->recaptures); } extern char moveList[MAX_MOVES][MOVE_LEN]; @@ -1749,7 +1758,7 @@ int PerpetualChase(int first, int last) cl.recaptures = 0; // prepare closure to pass recapture square and count moves to it cl.rt = chaseStack[j].rt; cl.ft = chaseStack[j].ft; - if(appData.debugMode) { int n; + if(appData.debugMode) { fprintf(debugFP, "test if we can recapture %c%c\n", cl.ft+AAA, cl.rt+ONE); } GenLegal(boards[i+1], PosFlags(i+1), EP_NONE, initialRights, ProtectedCallback, &cl); // try all moves