X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=a612db1d1eb5ddc0f089ec5f0d63a958afb0cba7;hb=98aa02bda540f17f1f50be00e494efafe439b004;hp=47c76871a414921180c6085c19b40a2066c53f5a;hpb=acbc3cdad54dc2dcb7075cfc48a3956e137a2f1d;p=xboard.git diff --git a/backend.c b/backend.c index 47c7687..a612db1 100644 --- a/backend.c +++ b/backend.c @@ -2124,7 +2124,8 @@ read_from_ics(isr, closure, data, count, error) if(buf_len >= 5 && buf[buf_len-5]=='\n' && buf[buf_len-4]=='\\' && buf[buf_len-3]==' ' && buf[buf_len-2]==' ' && buf[buf_len-1]==' ') { buf_len -= 5; // [HGM] ICS: join continuation line of Lasker 2.2.3 server with previous - buf[buf_len++] = ' '; // replace by space (assumes ICS does not break lines within word) + if(buf_len == 0 || buf[buf_len-1] != ' ') + buf[buf_len++] = ' '; // add space (assumes ICS does not break lines within word) } } @@ -2444,7 +2445,7 @@ read_from_ics(isr, closure, data, count, error) } } if(chattingPartner<0) // if not, look if there is a chatbox for this indivdual - for(p=0; p= 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 @@ -5223,7 +5222,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) { @@ -5439,11 +5437,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); } @@ -6379,6 +6377,29 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. } #endif if (pausing) PauseEvent(); + if(appData.forceIllegal) { + // [HGM] illegal: machine refused move; force position after move into it + SendToProgram("force\n", cps); + if(!cps->useSetboard) { // hideous kludge on kludge, because SendBoard sucks. + // we have a real problem now, as SendBoard will use the a2a3 kludge + // when black is to move, while there might be nothing on a2 or black + // might already have the move. So send the board as if white has the move. + // But first we must change the stm of the engine, as it refused the last move + SendBoard(cps, 0); // always kludgeless, as white is to move on boards[0] + if(WhiteOnMove(forwardMostMove)) { + SendToProgram("a7a6\n", cps); // for the engine black still had the move + SendBoard(cps, forwardMostMove); // kludgeless board + } else { + SendToProgram("a2a3\n", cps); // for the engine white still had the move + CopyBoard(boards[forwardMostMove+1], boards[forwardMostMove]); + SendBoard(cps, forwardMostMove+1); // kludgeless board + } + } else SendBoard(cps, forwardMostMove); // FEN case, also sets stm properly + if(gameMode == MachinePlaysWhite || gameMode == MachinePlaysBlack || + gameMode == TwoMachinesPlay) + SendToProgram("go\n", cps); + return; + } else if (gameMode == PlayFromGameFile) { /* Stop reading this game file */ gameMode = EditGame; @@ -7454,9 +7475,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; @@ -7466,6 +7484,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); @@ -7552,7 +7573,7 @@ void SendEgtPath(ChessProgramState *cps) while(*r && *r != ',') r++; // path info is everything upto next ';' or end of string c = *r; *r = 0; // temporarily null-terminate path info *--q = 0; // strip of trailig ':' from name - sprintf(buf, "egtbpath %s %s\n", name+1, s); + sprintf(buf, "egtpath %s %s\n", name+1, s); *r = c; SendToProgram(buf,cps); // send egtbpath command for this format } @@ -8281,6 +8302,7 @@ Reset(redraw, init) gameMode = BeginningOfGame; ModeHighlight(); if(appData.icsActive) gameInfo.variant = VariantNormal; + currentMove = forwardMostMove = backwardMostMove = 0; InitPosition(redraw); for (i = 0; i < MAX_MOVES; i++) { if (commentList[i] != NULL) {