From: H.G. Muller Date: Mon, 23 Apr 2012 12:12:10 +0000 (+0200) Subject: Keep track of virginity of back-rank pieces in variant seirawan X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=2d0f4769e69d228d9593c574014c634706edea97;p=xboard.git Keep track of virginity of back-rank pieces in variant seirawan The forelast rank of the Board array is now used in VariantSChess to contain flags that indicate virginity of the back-rank pieces, one bit for white, the other for black. Legality checking of gatings now makes use of this info. FENs mention all virgin pieces not implied by castling rights in the castling field, by printing the corresponding file IDs, as long as holdings are non-empty. The FEN reader now also understands this format. EditPositionDone fakes virginity for all pieces that are on their starting square. --- diff --git a/backend.c b/backend.c index 20e5efc..c346231 100644 --- a/backend.c +++ b/backend.c @@ -5866,6 +5866,7 @@ InitPosition (int redraw) case VariantSChess: SetCharTable(pieceToChar, "PNBRQ..HEKpnbrq..hek"); gameInfo.holdingsSize = 7; + for(i=0; i>1; - if(boards[0][0][BOARD_WIDTH>>1] == king) { + if(boards[0][0][BOARD_WIDTH>>1] == king) { boards[0][CASTLING][1] = boards[0][0][BOARD_LEFT] == WhiteRook ? BOARD_LEFT : NoRights; boards[0][CASTLING][0] = boards[0][0][BOARD_RGHT-1] == WhiteRook ? BOARD_RGHT-1 : NoRights; } else boards[0][CASTLING][2] = NoRights; - if(boards[0][BOARD_HEIGHT-1][BOARD_WIDTH>>1] == WHITE_TO_BLACK king) { + if(boards[0][BOARD_HEIGHT-1][BOARD_WIDTH>>1] == WHITE_TO_BLACK king) { boards[0][CASTLING][4] = boards[0][BOARD_HEIGHT-1][BOARD_LEFT] == BlackRook ? BOARD_LEFT : NoRights; boards[0][CASTLING][3] = boards[0][BOARD_HEIGHT-1][BOARD_RGHT-1] == BlackRook ? BOARD_RGHT-1 : NoRights; } else boards[0][CASTLING][5] = NoRights; + if(gameInfo.variant = VariantSChess) { + int i; + for(i=BOARD_LEFT; i=BOARD_LEFT+q && j; i--) + if((boards[move][0][i] != WhiteKing || k+q == 0) && + boards[move][VIRGIN][i] & VIRGIN_W) *p++ = i + AAA + 'A' - 'a'; + } + if(q) *p++ = 'Q'; + k = 0; if(boards[move][CASTLING][3] == BOARD_RGHT-1 && - boards[move][CASTLING][5] != NoRights ) *p++ = 'k'; - if(boards[move][CASTLING][4] == BOARD_LEFT && - boards[move][CASTLING][5] != NoRights ) *p++ = 'q'; + boards[move][CASTLING][5] != NoRights ) k = 1, *p++ = 'k'; + q = (boards[move][CASTLING][4] == BOARD_LEFT && + boards[move][CASTLING][5] != NoRights ); + if(gameInfo.variant = VariantSChess) { + for(i=j=0; i=BOARD_LEFT+q && j; i--) + if((boards[move][BOARD_HEIGHT-1][i] != BlackKing || k+q == 0) && + boards[move][VIRGIN][i] & VIRGIN_B) *p++ = i + AAA; + } + if(q) *p++ = 'q'; } } if (q == p) *p++ = '-'; /* No castling rights */ @@ -16732,7 +16764,7 @@ ParseFEN (Board board, int *blackPlaysFirst, char *fen) { int i, j; char *p, c; - int emptycount; + int emptycount, virgin[BOARD_FILES]; ChessSquare piece; p = fen; @@ -16861,14 +16893,15 @@ ParseFEN (Board board, int *blackPlaysFirst, char *fen) while(*p==' ') p++; if(nrCastlingRights) { - if(*p=='K' || *p=='Q' || *p=='k' || *p=='q' || *p=='-') { + if(gameInfo.variant == VariantSChess) for(i=0; i= 'A' && *p <= 'Z' || *p >= 'a' && *p <= 'z' || *p=='-') { /* castling indicator present, so default becomes no castlings */ for(i=0; i= 'a' && *p < 'a' + gameInfo.boardWidth) || ( *p >= 'A' && *p < 'A' + gameInfo.boardWidth) ) { int c = *p++, whiteKingFile=NoRights, blackKingFile=NoRights; @@ -16888,25 +16921,34 @@ ParseFEN (Board board, int *blackPlaysFirst, char *fen) for(i=BOARD_RGHT-1; board[0][i]!=WhiteRook && i>whiteKingFile; i--); board[CASTLING][0] = i != whiteKingFile ? i : NoRights; board[CASTLING][2] = whiteKingFile; + if(board[CASTLING][0] != NoRights) virgin[board[CASTLING][0]] |= VIRGIN_W; + if(board[CASTLING][2] != NoRights) virgin[board[CASTLING][2]] |= VIRGIN_W; break; case'Q': for(i=BOARD_LEFT; iblackKingFile; i--); board[CASTLING][3] = i != blackKingFile ? i : NoRights; board[CASTLING][5] = blackKingFile; + if(board[CASTLING][3] != NoRights) virgin[board[CASTLING][3]] |= VIRGIN_B; + if(board[CASTLING][5] != NoRights) virgin[board[CASTLING][5]] |= VIRGIN_B; break; case'q': for(i=BOARD_LEFT; i= 'a') { /* black rights */ + if(gameInfo.variant == VariantSChess) { virgin[c-AAA] |= VIRGIN_B; break; } // in S-Chess castlings are always kq, so just virginity for(i=BOARD_LEFT; i9)) /* [HGM] foremost board rank */ #define AAA ('a'-BOARD_LEFT) /* [HGM] leftmost board file */ +#define VIRGIN_W 1 /* [HGM] flags in Board[VIRGIN][X] */ +#define VIRGIN_B 2 #define DROP_RANK -3 #define MAX_MOVES 1000 #define MSG_SIZ 512 diff --git a/moves.c b/moves.c index a458a84..5f4b3f9 100644 --- a/moves.c +++ b/moves.c @@ -146,7 +146,8 @@ CopyBoard (Board to, Board from) for (i = 0; i < BOARD_HEIGHT; i++) for (j = 0; j < BOARD_WIDTH; j++) to[i][j] = from[i][j]; - for (j = 0; j < BOARD_FILES-1; j++) // [HGM] gamestate: copy castling rights and ep status + for (j = 0; j < BOARD_FILES; j++) // [HGM] gamestate: copy castling rights and ep status + to[VIRGIN][j] = from[VIRGIN][j], to[CASTLING][j] = from[CASTLING][j]; to[HOLDINGS_SET] = 0; // flag used in ICS play } @@ -1127,9 +1128,11 @@ LegalityTest (Board board, int flags, int rf, int ff, int rt, int ft, int promoC if(gameInfo.variant == VariantSChess && promoChar && promoChar != '=' && board[rf][ff] != WhitePawn && board[rf][ff] != BlackPawn) { if(board[rf][ff] < BlackPawn) { // white if(rf != 0) return IllegalMove; // must be on back rank + if(!(board[VIRGIN][ff] & VIRGIN_W)) return IllegalMove; // non-virgin if(board[PieceToNumber(CharToPiece(ToUpper(promoChar)))][BOARD_WIDTH-2] == 0) return ImpossibleMove;// must be in stock } else { if(rf != BOARD_HEIGHT-1) return IllegalMove; + if(!(board[VIRGIN][ff] & VIRGIN_B)) return IllegalMove; // non-virgin if(board[BOARD_HEIGHT-1-PieceToNumber(CharToPiece(ToLower(promoChar)))][1] == 0) return ImpossibleMove; } } else @@ -1356,9 +1359,11 @@ Disambiguate (Board board, int flags, DisambiguateClosure *closure) if(gameInfo.variant == VariantSChess && c && c != '=' && closure->piece != WhitePawn && closure->piece != BlackPawn) { if(closure->piece < BlackPawn) { // white if(closure->rf != 0) closure->kind = IllegalMove; // must be on back rank + if(!(board[VIRGIN][closure->ff] & VIRGIN_W)) closure->kind = IllegalMove; // non-virgin if(board[PieceToNumber(CharToPiece(ToUpper(c)))][BOARD_WIDTH-2] == 0) closure->kind = ImpossibleMove;// must be in stock } else { if(closure->rf != BOARD_HEIGHT-1) closure->kind = IllegalMove; + if(!(board[VIRGIN][closure->ff] & VIRGIN_B)) closure->kind = IllegalMove; // non-virgin if(board[BOARD_HEIGHT-1-PieceToNumber(CharToPiece(ToLower(c)))][1] == 0) closure->kind = ImpossibleMove; } } else