X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=4249d7c7a70b5753c781c1dab1bcd2ebaba1d360;hb=fa1ce90bbcd27d332afebd9ecbd4e0ed662c4940;hp=aea15b58bda448bee0a5cfbdf826beef25be693f;hpb=90cc6b8204d671bde9f59382c94729271c3d5e23;p=xboard.git diff --git a/backend.c b/backend.c index aea15b5..4249d7c 100644 --- a/backend.c +++ b/backend.c @@ -646,8 +646,23 @@ ChessSquare CourierArray[2][BOARD_FILES] = { { BlackRook, BlackKnight, BlackAlfil, BlackBishop, BlackMan, BlackKing, BlackFerz, BlackWazir, BlackBishop, BlackAlfil, BlackKnight, BlackRook } }; +ChessSquare ChuArray[6][BOARD_FILES] = { + { WhiteLance, WhiteUnicorn, WhiteMan, WhiteFerz, WhiteWazir, WhiteKing, + WhiteAlfil, WhiteWazir, WhiteFerz, WhiteMan, WhiteUnicorn, WhiteLance }, + { BlackLance, BlackUnicorn, BlackMan, BlackFerz, BlackWazir, BlackAlfil, + BlackKing, BlackWazir, BlackFerz, BlackMan, BlackUnicorn, BlackLance }, + { WhiteCannon, EmptySquare, WhiteBishop, EmptySquare, WhiteNightrider, WhiteMarshall, + WhiteAngel, WhiteNightrider, EmptySquare, WhiteBishop, EmptySquare, WhiteCannon }, + { BlackCannon, EmptySquare, BlackBishop, EmptySquare, BlackNightrider, BlackAngel, + BlackMarshall, BlackNightrider, EmptySquare, BlackBishop, EmptySquare, BlackCannon }, + { WhiteFalcon, WhiteSilver, WhiteRook, WhiteCardinal, WhiteDragon, WhiteLion, + WhiteQueen, WhiteDragon, WhiteCardinal, WhiteRook, WhiteSilver, WhiteFalcon }, + { BlackFalcon, BlackSilver, BlackRook, BlackCardinal, BlackDragon, BlackQueen, + BlackLion, BlackDragon, BlackCardinal, BlackRook, BlackSilver, BlackFalcon } +}; #else // !(BOARD_FILES>=12) #define CourierArray CapablancaArray +#define ChuArray CapablancaArray #endif // !(BOARD_FILES>=12) @@ -1150,6 +1165,7 @@ InitBackEnd1 () case VariantCapablanca: /* [HGM] should work */ case VariantCourier: /* [HGM] initial forced moves not implemented */ case VariantShogi: /* [HGM] could still mate with pawn drop */ + case VariantChu: /* [HGM] experimental */ case VariantKnightmate: /* [HGM] should work */ case VariantCylinder: /* [HGM] untested */ case VariantFalcon: /* [HGM] untested */ @@ -5861,7 +5877,7 @@ void InitPosition (int redraw) { ChessSquare (* pieces)[BOARD_FILES]; - int i, j, pawnRow, overrule, + int i, j, pawnRow=1, pieceRows=1, overrule, oldx = gameInfo.boardWidth, oldy = gameInfo.boardHeight, oldh = gameInfo.holdingsWidth; @@ -5985,6 +6001,14 @@ InitPosition (int redraw) nrCastlingRights = 0; SetCharTable(pieceToChar, "PNBRLS...G.++++++Kpnbrls...g.++++++k"); break; + case VariantChu: + pieces = ChuArray; pieceRows = 3; + gameInfo.boardWidth = 12; + gameInfo.boardHeight = 12; + nrCastlingRights = 0; + SetCharTable(pieceToChar, "P.BRQSEXOGCATHD.VMLIFN+.+++++++++++++.+++++K" + "p.brqsexogcathd.vmlifn+.+++++++++++++.+++++k"); + break; case VariantCourier: pieces = CourierArray; gameInfo.boardWidth = 12; @@ -6054,6 +6078,7 @@ InitPosition (int redraw) pawnRow = gameInfo.boardHeight - 7; /* seems to work in all common variants */ if(pawnRow < 1) pawnRow = 1; if(gameInfo.variant == VariantMakruk || gameInfo.variant == VariantASEAN || gameInfo.variant == VariantGrand) pawnRow = 2; + if(gameInfo.variant == VariantChu) pawnRow = 3; /* User pieceToChar list overrules defaults */ if(appData.pieceToCharTable != NULL) @@ -6080,6 +6105,15 @@ InitPosition (int redraw) } } } + if(gameInfo.variant == VariantChu) { + if(j == (BOARD_WIDTH-2)/3 || j == BOARD_WIDTH - (BOARD_WIDTH+1)/3) + initialPosition[pawnRow+1][j] = WhiteCobra, + initialPosition[BOARD_HEIGHT-pawnRow-2][j] = BlackCobra; + for(i=1; i=BOARD_RGHT-1) { initialPosition[0][j] = WhiteRook; @@ -8564,7 +8598,7 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. if(*buf) SetCharTable(pieceToChar, buf); // do again, for it was spoiled by InitPosition } } - ParseFEN(boards[0], &dummy, message+s); + ParseFEN(boards[0], &dummy, message+s, FALSE); DrawPosition(TRUE, boards[0]); startedFromSetupPosition = TRUE; return; @@ -8577,7 +8611,7 @@ if(appData.debugMode) fprintf(debugFP, "nodes = %d, %lld\n", (int) programStats. GameEnds(GameUnfinished, "Engine aborts game", GE_XBOARD); - if (!ParseFEN(initial_position, &blackPlaysFirst, message + 9)) { + if (!ParseFEN(initial_position, &blackPlaysFirst, message + 9, FALSE)) { DisplayError(_("Bad FEN received from engine"), 0); return ; } else { @@ -10030,6 +10064,8 @@ NonStandardBoardSize () overruled = gameInfo.boardWidth != 8 || gameInfo.boardHeight != 8 || gameInfo.holdingsSize != 7; if( gameInfo.variant == VariantGrand ) overruled = gameInfo.boardWidth != 10 || gameInfo.boardHeight != 10 || gameInfo.holdingsSize != 7; + if( gameInfo.variant == VariantChu ) + overruled = gameInfo.boardWidth != 12 || gameInfo.boardHeight != 12 || gameInfo.holdingsSize != 0; return overruled; } @@ -12081,7 +12117,7 @@ GameContainsPosition (FILE *f, ListGame *lg) for(next = WhitePawn; next>8 ^ random()<<6 ^random()<<20; initDone = TRUE; } - if(lg->gameInfo.fen) ParseFEN(boards[scratch], &btm, lg->gameInfo.fen); + if(lg->gameInfo.fen) ParseFEN(boards[scratch], &btm, lg->gameInfo.fen, FALSE); else CopyBoard(boards[scratch], initialPosition); // default start position if(lg->moves) { turn = btm + 1; @@ -12403,7 +12439,7 @@ LoadGame (FILE *f, int gameNumber, char *title, int useList) if (gameInfo.fen != NULL) { Board initial_position; startedFromSetupPosition = TRUE; - if (!ParseFEN(initial_position, &blackPlaysFirst, gameInfo.fen)) { + if (!ParseFEN(initial_position, &blackPlaysFirst, gameInfo.fen, TRUE)) { Reset(TRUE, TRUE); DisplayError(_("Bad FEN position in file"), 0); return FALSE; @@ -12740,7 +12776,7 @@ LoadPosition (FILE *f, int positionNumber, char *title) } if (fenMode) { - if (!ParseFEN(initial_position, &blackPlaysFirst, line)) { + if (!ParseFEN(initial_position, &blackPlaysFirst, line, TRUE)) { DisplayError(_("Bad FEN position in file"), 0); return FALSE; } @@ -14593,7 +14629,8 @@ EditPositionMenuEvent (ChessSquare selection, int x, int y) { char buf[MSG_SIZ]; ChessSquare piece = boards[0][y][x]; - static Board erasedBoard, currentBoard, menuBoard; + static Board erasedBoard, currentBoard, menuBoard, nullBoard; + static int lastVariant; if (gameMode != EditPosition && gameMode != IcsExamining) return; @@ -14632,13 +14669,16 @@ EditPositionMenuEvent (ChessSquare selection, int x, int y) p = menuBoard[BOARD_HEIGHT-1][x]; for(y = x + 1; y < BOARD_RGHT; y++) if(menuBoard[BOARD_HEIGHT-1][y] == p) menuBoard[BOARD_HEIGHT-1][y] = EmptySquare; } + DisplayMessage("Clicking clock again restores position", ""); + if(gameInfo.variant != lastVariant) lastVariant = gameInfo.variant, CopyBoard(erasedBoard, boards[0]); if(!nonEmpty) { // asked to clear an empty board CopyBoard(boards[0], menuBoard); } else if(CompareBoards(currentBoard, menuBoard)) { // asked to clear an empty board CopyBoard(boards[0], initialPosition); } else - if(CompareBoards(currentBoard, initialPosition) && !CompareBoards(currentBoard, erasedBoard)) { + if(CompareBoards(currentBoard, initialPosition) && !CompareBoards(currentBoard, erasedBoard) + && !CompareBoards(nullBoard, erasedBoard)) { CopyBoard(boards[0], erasedBoard); } else CopyBoard(erasedBoard, currentBoard); @@ -16514,7 +16554,7 @@ TypeInDoneEvent (char *move) ChessMove moveType; // [HGM] FENedit - if(gameMode == EditPosition && ParseFEN(board, &n, move) ) { + if(gameMode == EditPosition && ParseFEN(board, &n, move, TRUE) ) { EditPositionPasteFEN(move); return; } @@ -17403,34 +17443,31 @@ PositionToFEN (int move, char *overrideCastling, int moveCounts) } Boolean -ParseFEN (Board board, int *blackPlaysFirst, char *fen) +ParseFEN (Board board, int *blackPlaysFirst, char *fen, Boolean autoSize) { - int i, j; + int i, j, k, w=0; char *p, c; int emptycount, virgin[BOARD_FILES]; ChessSquare piece; p = fen; - /* [HGM] by default clear Crazyhouse holdings, if present */ - if(gameInfo.holdingsWidth) { - for(i=0; i= 0; i--) { j = 0; for (;;) { - if (*p == '/' || *p == ' ' || (*p == '[' && i == 0) ) { - if (*p == '/') p++; + if (*p == '/' || *p == ' ' || *p == '[' ) { + if(j > w) w = j; emptycount = gameInfo.boardWidth - j; while (emptycount--) board[i][(j++)+gameInfo.holdingsWidth] = EmptySquare; + if (*p == '/') p++; + else if(autoSize) { // we stumbled unexpectedly into end of board + for(k=i; k= 10) } else if(*p=='x' || *p=='X') { /* [HGM] X means 10 */ @@ -17470,6 +17507,18 @@ ParseFEN (Board board, int *blackPlaysFirst, char *fen) } while (*p == '/' || *p == ' ') p++; + if(autoSize) appData.NrFiles = w, InitPosition(TRUE); + + /* [HGM] by default clear Crazyhouse holdings, if present */ + if(gameInfo.holdingsWidth) { + for(i=0; i