X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=3605468c9b17595c0055a3bf0fb15f5e701d116d;hb=de954fa0f31cc935b5ad61819a04de2713cd98ed;hp=5fb842c22aaeb1e96c0dd22c016a785c4ee1d6f9;hpb=bf368bef696bee3555a370ac8ff88418e1f5c498;p=xboard.git diff --git a/backend.c b/backend.c index 5fb842c..3605468 100644 --- a/backend.c +++ b/backend.c @@ -5050,38 +5050,37 @@ int lastLoadGameUseList = FALSE; char lastLoadGameTitle[MSG_SIZ], lastLoadPositionTitle[MSG_SIZ]; ChessMove lastLoadGameStart = (ChessMove) 0; - ChessMove -UserMoveTest(fromX, fromY, toX, toY, promoChar) +UserMoveTest(fromX, fromY, toX, toY, promoChar, captureOwn) int fromX, fromY, toX, toY; int promoChar; + Boolean captureOwn; { ChessMove moveType; ChessSquare pdown, pup; if (fromX < 0 || fromY < 0) return ImpossibleMove; - if ((fromX == toX) && (fromY == toY)) { - return ImpossibleMove; - } /* [HGM] suppress all moves into holdings area and guard band */ if( toX < BOARD_LEFT || toX >= BOARD_RGHT || toY < 0 ) return ImpossibleMove; /* [HGM] moved to here from winboard.c */ - /* note: this code seems to exist for filtering out some obviously illegal premoves */ + /* note: capture of own piece can be legal as drag-drop premove. For click-click it is selection of new piece. */ pdown = boards[currentMove][fromY][fromX]; pup = boards[currentMove][toY][toX]; - if ( gameMode != EditPosition && + if ( gameMode != EditPosition && !captureOwn && (WhitePawn <= pdown && pdown < BlackPawn && WhitePawn <= pup && pup < BlackPawn || BlackPawn <= pdown && pdown < EmptySquare && BlackPawn <= pup && pup < EmptySquare ) && !((gameInfo.variant == VariantFischeRandom || gameInfo.variant == VariantCapaRandom) && (pup == WhiteRook && pdown == WhiteKing && fromY == 0 && toY == 0|| - pup == BlackRook && pdown == BlackKing && fromY == BOARD_HEIGHT-1 && toY == BOARD_HEIGHT-1 ) + pup == BlackRook && pdown == BlackKing && fromY == BOARD_HEIGHT-1 && toY == BOARD_HEIGHT-1 || + pup == WhiteKing && pdown == WhiteRook && fromY == 0 && toY == 0|| // also allow RxK + pup == BlackKing && pdown == BlackRook && fromY == BOARD_HEIGHT-1 && toY == BOARD_HEIGHT-1 ) ) ) - return ImpossibleMove; + return Comment; /* Check if the user is playing in turn. This is complicated because we let the user "pick up" a piece before it is his turn. So the piece he @@ -5158,12 +5157,6 @@ UserMoveTest(fromX, fromY, toX, toY, promoChar) fprintf(debugFP, "Got premove: fromX %d," "fromY %d, toX %d, toY %d\n", fromX, fromY, toX, toY); - if(!WhiteOnMove(currentMove) && gotPremove == 1) { - // [HGM] race: we must have been hit by an opponent move from the ICS while preparing the premove - if (appData.debugMode) - fprintf(debugFP, "Execute as normal move\n"); - gotPremove = 0; break; - } } return ImpossibleMove; } @@ -5185,12 +5178,6 @@ UserMoveTest(fromX, fromY, toX, toY, promoChar) fprintf(debugFP, "Got premove: fromX %d," "fromY %d, toX %d, toY %d\n", fromX, fromY, toX, toY); - if(WhiteOnMove(currentMove) && gotPremove == 1) { - // [HGM] race: we must have been hit by an opponent move from the ICS while preparing the premove - if (appData.debugMode) - fprintf(debugFP, "Execute as normal move\n"); - gotPremove = 0; break; - } } return ImpossibleMove; } @@ -5234,7 +5221,6 @@ UserMoveTest(fromX, fromY, toX, toY, promoChar) moveType = LegalityTest(boards[currentMove], PosFlags(currentMove), epStatus[currentMove], castlingRights[currentMove], fromY, fromX, toY, toX, promoChar); - /* [HGM] but possibly ignore an IllegalMove result */ if (appData.testLegality) { if (moveType == IllegalMove || moveType == ImpossibleMove) { @@ -5450,11 +5436,11 @@ UserMoveEvent(fromX, fromY, toX, toY, promoChar) FinishMove if the first part succeeded. Calls that do not need to do anything in between, can call this routine the old way. */ - ChessMove moveType = UserMoveTest(fromX, fromY, toX, toY, promoChar); + ChessMove moveType = UserMoveTest(fromX, fromY, toX, toY, promoChar, FALSE); if(appData.debugMode) fprintf(debugFP, "moveType 4 = %d, promochar = %x\n", moveType, promoChar); if(moveType == AmbiguousMove) DrawPosition(FALSE, boards[currentMove]); - else if(moveType != ImpossibleMove) + else if(moveType != ImpossibleMove && moveType != Comment) FinishMove(moveType, fromX, fromY, toX, toY, promoChar); } @@ -7488,9 +7474,6 @@ MakeMove(fromX, fromY, toX, toY, promoChar) 0, 1); return; } - SwitchClocks(); - timeRemaining[0][forwardMostMove+1] = whiteTimeRemaining; - timeRemaining[1][forwardMostMove+1] = blackTimeRemaining; if (commentList[forwardMostMove+1] != NULL) { free(commentList[forwardMostMove+1]); commentList[forwardMostMove+1] = NULL; @@ -7500,6 +7483,9 @@ MakeMove(fromX, fromY, toX, toY, promoChar) ApplyMove(fromX, fromY, toX, toY, promoChar, boards[forwardMostMove+1], castlingRights[forwardMostMove+1], &epStatus[forwardMostMove+1]); forwardMostMove++; // [HGM] bare: moved to after ApplyMove, to make sure clock interrupt finds complete board + SwitchClocks(); // uses forwardMostMove, so must be done after incrementing it ! + timeRemaining[0][forwardMostMove] = whiteTimeRemaining; + timeRemaining[1][forwardMostMove] = blackTimeRemaining; gameInfo.result = GameUnfinished; if (gameInfo.resultDetails != NULL) { free(gameInfo.resultDetails);