X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=baead2fc60713babf4c73e141f7d556edefb7565;hb=07a436432ceac681e3e06f8a035d4f4d6413fb15;hp=37929713badf534efd4f20f21392efc44d98aaeb;hpb=d1638304f504ca6cbfa36eb7a951b530f374bd10;p=xboard.git diff --git a/backend.c b/backend.c index 3792971..baead2f 100644 --- a/backend.c +++ b/backend.c @@ -4209,6 +4209,12 @@ read_from_ics (InputSourceRef isr, VOIDSTAR closure, char *data, int count, int parse, currentMove); if (sscanf(parse, " game %d", &gamenum) == 1) { if(gamenum == ics_gamenum) { // [HGM] bughouse: old code if part of foreground game + new_piece[0] = NULLCHAR; + sscanf(parse, "game %d white [%s black [%s <- %s", + &gamenum, white_holding, black_holding, + new_piece); + white_holding[strlen(white_holding)-1] = NULLCHAR; + black_holding[strlen(black_holding)-1] = NULLCHAR; if (gameInfo.variant == VariantNormal) { /* [HGM] We seem to switch variant during a game! * Presumably no holdings were displayed, so we have @@ -4219,7 +4225,10 @@ read_from_ics (InputSourceRef isr, VOIDSTAR closure, char *data, int count, int switch(gameInfo.boardWidth) { // base guess on board width case 9: newVariant = VariantShogi; break; case 10: newVariant = VariantGreat; break; - default: newVariant = VariantCrazyhouse; break; + default: newVariant = VariantCrazyhouse; + if(strchr(white_holding, 'E') || strchr(black_holding, 'E') || + strchr(white_holding, 'H') || strchr(black_holding, 'H') ) + newVariant = VariantSChess; } VariantSwitch(boards[currentMove], newVariant); /* temp guess */ /* Get a move list just to see the header, which @@ -4230,12 +4239,6 @@ read_from_ics (InputSourceRef isr, VOIDSTAR closure, char *data, int count, int SendToICS(str); } } - new_piece[0] = NULLCHAR; - sscanf(parse, "game %d white [%s black [%s <- %s", - &gamenum, white_holding, black_holding, - new_piece); - white_holding[strlen(white_holding)-1] = NULLCHAR; - black_holding[strlen(black_holding)-1] = NULLCHAR; /* [HGM] copy holdings to board holdings area */ CopyHoldings(boards[forwardMostMove], white_holding, WhitePawn); CopyHoldings(boards[forwardMostMove], black_holding, BlackPawn); @@ -6451,6 +6454,7 @@ InitPosition (int redraw) initialPosition[1][1] = initialPosition[2][1] = initialPosition[6][BOARD_WIDTH-2] = initialPosition[5][BOARD_WIDTH-2] = 1; } + initialPosition[CHECK_COUNT] = (gameInfo.variant == Variant3Check ? 0x303 : 0); if (appData.debugMode) { fprintf(debugFP, "shuffleOpenings = %d\n", shuffleOpenings); } @@ -7462,7 +7466,7 @@ MarkTargetSquares (int clear) if(PosFlags(0) & F_MANDATORY_CAPTURE) { for(x=0; x1) capt++; if(capt) - for(x=0; x> 8; board[EP_STATUS] = EP_NONE; - board[EP_FILE] = board[EP_RANK] = board[LAST_FILE] = board[LAST_RANK] = 100; + board[EP_FILE] = board[EP_RANK] = 100, board[LAST_TO] = 0x4040; if (fromY == DROP_RANK) { /* must be first */ @@ -10278,7 +10285,7 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) if(toX fromX) board[EP_STATUS] = toX; - board[LAST_FILE] = toX; board[LAST_RANK] = toY; + board[LAST_TO] = toX + 256*toY; } } else if( pawn == BlackPawn ) { @@ -10292,7 +10299,7 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) if(toX fromX) board[EP_STATUS] = toX; - board[LAST_FILE] = toX; board[LAST_RANK] = toY; + board[LAST_TO] = toX + 256*toY; } } @@ -10589,7 +10596,7 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) void MakeMove (int fromX, int fromY, int toX, int toY, int promoChar) { - int x = toX, y = toY; + int x = toX, y = toY, mask; char *s = parseList[forwardMostMove]; ChessSquare p = boards[forwardMostMove][toY][toX]; // forwardMostMove++; // [HGM] bare: moved downstream @@ -10685,15 +10692,18 @@ MakeMove (int fromX, int fromY, int toX, int toY, int promoChar) } CoordsToComputerAlgebraic(fromY, fromX, toY, toX, promoChar, moveList[forwardMostMove - 1]); + mask = (WhiteOnMove(forwardMostMove) ? 0xFF : 0xFF00); switch (MateTest(boards[forwardMostMove], PosFlags(forwardMostMove)) ) { case MT_NONE: case MT_STALEMATE: default: break; case MT_CHECK: - if(!IS_SHOGI(gameInfo.variant)) - strcat(parseList[forwardMostMove - 1], "+"); - break; + if(boards[forwardMostMove][CHECK_COUNT]) boards[forwardMostMove][CHECK_COUNT] -= mask & 0x101; + if(!boards[forwardMostMove][CHECK_COUNT] || boards[forwardMostMove][CHECK_COUNT] & mask) { + if(!IS_SHOGI(gameInfo.variant)) strcat(parseList[forwardMostMove - 1], "+"); + break; + } case MT_CHECKMATE: case MT_STAINMATE: strcat(parseList[forwardMostMove - 1], "#"); @@ -18435,13 +18445,15 @@ PositionToFEN (int move, char *overrideCastling, int moveCounts) fromY = moveList[move - 1][1] - ONE; toX = moveList[move - 1][2] - AAA; toY = moveList[move - 1][3] - ONE; - if (fromY == (whiteToPlay ? BOARD_HEIGHT-2 : 1) && - toY == (whiteToPlay ? BOARD_HEIGHT-4 : 3) && - boards[move][toY][toX] == (whiteToPlay ? BlackPawn : WhitePawn) && - fromX == toX) { + if ((whiteToPlay ? toY < fromY - 1 : toY > fromY + 1) && + boards[move][toY][toX] == (whiteToPlay ? BlackPawn : WhitePawn) ) { /* 2-square pawn move just happened */ - *p++ = toX + AAA; - *p++ = whiteToPlay ? '6'+BOARD_HEIGHT-8 : '3'; + *p++ = (3*toX + 5*fromX + 4)/8 + AAA; + *p++ = (3*toY + 5*fromY + 4)/8 + ONE; + if(gameInfo.variant == VariantBerolina) { + *p++ = toX + AAA; + *p++ = toY + ONE; + } } else { *p++ = '-'; } @@ -18460,6 +18472,12 @@ PositionToFEN (int move, char *overrideCastling, int moveCounts) } } + i = boards[move][CHECK_COUNT]; + if(i) { + sprintf(p, "%d+%d ", i&255, i>>8); + while(*p) p++; + } + if(moveCounts) { int i = 0, j=move; @@ -18812,18 +18830,38 @@ ParseFEN (Board board, int *blackPlaysFirst, char *fen, Boolean autoSize) if(*p=='-') { p++; board[EP_STATUS] = EP_NONE; } else { - char c = *p++ - AAA; - - if(c < BOARD_LEFT || c >= BOARD_RGHT) return TRUE; - if(*p >= '0' && *p <='9') p++; - board[EP_STATUS] = c; + int d, r, c = *p - AAA; + + if(c >= BOARD_LEFT && c < BOARD_RGHT) { + p++; + board[EP_STATUS] = board[EP_FILE] = c; r = 0; + if(*p >= '0' && *p <='9') r = board[EP_RANK] = *p++ - ONE; + d = (r < BOARD_HEIGHT << 1 ? 1 : -1); // assume double-push (P next to e.p. square nearer center) + if(board[r+d][c] == EmptySquare) d *= 2; // but if no Pawn there, triple push + board[LAST_TO] = 256*(r + d) + c; + c = *p++ - AAA; + if(c >= BOARD_LEFT && c < BOARD_RGHT) { // mover explicitly mentioned + if(*p >= '0' && *p <='9') r = board[EP_RANK] = *p++ - ONE; + board[LAST_TO] = 256*r + c; + if(!(board[EP_RANK]-r & 1)) board[EP_RANK] |= 128; + } + } } } + while(*p == ' ') p++; + + board[CHECK_COUNT] = 0; // [HGM] 3check: check-count field + if(sscanf(p, "%d+%d", &i, &j) == 2) { + board[CHECK_COUNT] = i + 256*j; + while(*p && *p != ' ') p++; + } - if(sscanf(p, "%d", &i) == 1) { + c = sscanf(p, "%d%*d +%d+%d", &i, &j, &k); + if(c > 0) { FENrulePlies = i; /* 50-move ply counter */ /* (The move number is still ignored) */ + if(c == 3 && !board[CHECK_COUNT]) board[CHECK_COUNT] = (3 - j) + 256*(3 - k); // SCIDB-style check count } return TRUE;