X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=parser.l;h=bdf11d0858cc47fa13a7a8f1c37ab9039e2ebdb5;hb=ea750683ac62717dd7346de17b5ae072622ff92a;hp=da4cbc783636a34cf0b553dacc3c5533d0fd78b3;hpb=062fb2bd92324706eed1fba8d5f7b4015ef2b058;p=xboard.git diff --git a/parser.l b/parser.l old mode 100644 new mode 100755 index da4cbc7..bdf11d0 --- a/parser.l +++ b/parser.l @@ -87,6 +87,16 @@ char *yy_text = (char *) yytext; #ifdef FLEX_SCANNER /* This is flex */ +/* [AP] use prototypes in function declarations */ +#define YY_USE_PROTOS + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +#endif +/* end of [AP] fix */ + #undef YY_INPUT #define YY_INPUT(buf, result, max_size) my_yy_input(buf, &result, max_size) #undef YY_DECL @@ -172,6 +182,7 @@ extern void CopyBoard P((Board to, Board from)); int skip1 = 0, skip2 = 0, skip3 = 0, promoted = 0; ChessSquare piece; ChessMove result; + char c; if (yyskipmoves) return (int) AmbiguousMove; /* not disambiguated */ @@ -190,6 +201,11 @@ extern void CopyBoard P((Board to, Board from)); currentMoveString[3] = yytext[4+skip1+skip2]; currentMoveString[4] = NULLCHAR; + if (appData.debugMode) { + fprintf(debugFP, "Parser Qa1b2: yyleng=%d\n", + yyleng); + } + if (yyleng-skip1-skip2 > 5) { char c; if (yytext[yyleng-1] == ')') { c = currentMoveString[4] = ToLower(yytext[yyleng-2]); @@ -218,7 +234,9 @@ extern void CopyBoard P((Board to, Board from)); piece = boards[yyboardindex] [currentMoveString[1] - ONE][currentMoveString[0] - AAA]; if(promoted) piece = (ChessSquare) (DEMOTED piece); - if (ToLower(yytext[skip3]) != ToLower(PieceToChar(piece))) + c = PieceToChar(piece); + if(c == '~') c = PieceToChar((ChessSquare) (DEMOTED piece)); + if (ToLower(yytext[skip3]) != ToLower(c)) return (int) IllegalMove; result = LegalityTest(boards[yyboardindex], @@ -240,9 +258,10 @@ extern void CopyBoard P((Board to, Board from)); return (int) result; } -[a-l][0-9][xX:-]?[a-l][0-9]((=?\(?[A-Z]\)?)|=)? { +[a-l][0-9][xX:-]?[a-l][0-9]((=?\(?[A-Za-z]\)?)|=)? { /* * Simple algebraic move, possibly with promotion + * [HGM] Engine moves are received in this format, with lower-case promoChar! */ int skip = 0; ChessMove result; @@ -293,7 +312,12 @@ extern void CopyBoard P((Board to, Board from)); if (currentMoveString[4] == NULLCHAR && (result == WhitePromotionKnight || result == BlackPromotionKnight || result == WhitePromotionQueen || result == BlackPromotionQueen)) { - currentMoveString[4] = PieceToChar(BlackQueen); + if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier) + currentMoveString[4] = PieceToChar(BlackFerz); + else if(gameInfo.variant == VariantGreat) + currentMoveString[4] = PieceToChar(BlackMan); + else + currentMoveString[4] = PieceToChar(BlackQueen); currentMoveString[5] = NULLCHAR; } @@ -436,7 +460,6 @@ extern void CopyBoard P((Board to, Board from)); if (gameInfo.variant == VariantXiangqi && /* [HGM] In Xiangqi rank stays same */ currentMoveString[0] != currentMoveString[2] ) { - if (yytext[2+skip] == ONE) return (int) ImpossibleMove; currentMoveString[1] = yytext[2+skip]; } else if (WhiteOnMove(yyboardindex)) { @@ -471,6 +494,11 @@ extern void CopyBoard P((Board to, Board from)); (result == WhitePromotionQueen || result == BlackPromotionQueen || result == WhitePromotionKnight || result == BlackPromotionKnight)) { currentMoveString[4] = PieceToChar(BlackQueen); + // [HGM] shatranj: take care of variants without Queen + if(gameInfo.variant == VariantShatranj || gameInfo.variant == VariantCourier) + currentMoveString[4] = PieceToChar(BlackFerz); + if(gameInfo.variant == VariantGreat) + currentMoveString[4] = PieceToChar(BlackMan); currentMoveString[5] = NULLCHAR; } @@ -539,6 +567,12 @@ extern void CopyBoard P((Board to, Board from)); if(yyleng-skip > 3) /* [HGM] can have Shogi-style promotion */ cl.promoCharIn = yytext[yyleng-1]; + if (appData.debugMode) { + fprintf(debugFP, "Parser Qa1: yyleng=%d, %d(%d,%d)-(%d,%d) = %d (%c)\n", + yyleng, + cl.pieceIn,cl.ffIn,cl.rfIn,cl.ftIn,cl.rtIn,cl.promoCharIn,cl.promoCharIn?cl.promoCharIn:' '); + } + /* [HGM] but do not allow values beyond board size */ if(cl.rtIn >= BOARD_HEIGHT || cl.rtIn < 0 || @@ -553,7 +587,7 @@ extern void CopyBoard P((Board to, Board from)); currentMoveString[1] = cl.rf + ONE; currentMoveString[2] = cl.ft + AAA; currentMoveString[3] = cl.rt + ONE; - currentMoveString[4] = cl.promoChar; + currentMoveString[4] = cl.promoChar; currentMoveString[5] = NULLCHAR; return (int) cl.kind; @@ -633,33 +667,44 @@ extern void CopyBoard P((Board to, Board from)); ff = (BOARD_WIDTH-1)>>1; rt = 0; ft = BOARD_RGHT-3; - sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE); } else { rf = 0; ff = BOARD_WIDTH>>1; rt = 0; ft = BOARD_LEFT+2; - sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE); } } else{ - if (boards[yyboardindex][BOARD_HEIGHT-1][3] == BlackKing) { + if (boards[yyboardindex][BOARD_HEIGHT-1][(BOARD_WIDTH-1)>>1] == BlackKing) { /* ICS wild castling */ rf = BOARD_HEIGHT-1; ff = (BOARD_WIDTH-1)>>1; rt = BOARD_HEIGHT-1; ft = BOARD_RGHT-3; - sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE); } else { rf = BOARD_HEIGHT-1; ff = BOARD_WIDTH>>1; rt = BOARD_HEIGHT-1; ft = BOARD_LEFT+2; - sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE); } } + if(gameInfo.variant == VariantFischeRandom) { + if (WhiteOnMove(yyboardindex)) { + ff = initialRights[2]; + ft = initialRights[1]; + } else { + ff = initialRights[5]; + ft = initialRights[4]; + } + fprintf(debugFP, "Parser FRC long %d %d\n", ff, ft); + if(ff < 0 || ft < 0) return 0; + } + sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE); + if (appData.debugMode) { + fprintf(debugFP, "long castling %d %d\n", ff, ft); + } return (int) LegalityTest(boards[yyboardindex], PosFlags(yyboardindex), EP_UNKNOWN, - initialRights, /* [HGM] assume all castlings allowed */ + castlingRights[yyboardindex], /* [HGM] use true castling rights */ rf, ff, rt, ft, NULLCHAR); } @@ -675,13 +720,11 @@ extern void CopyBoard P((Board to, Board from)); ff = (BOARD_WIDTH-1)>>1; rt = 0; ft = BOARD_LEFT+1; - sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE); } else { rf = 0; ff = BOARD_WIDTH>>1; rt = 0; ft = BOARD_RGHT-2; - sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE); } } else { if (boards[yyboardindex][BOARD_HEIGHT-1][(BOARD_WIDTH-1)>>1] == BlackKing) { @@ -690,18 +733,34 @@ extern void CopyBoard P((Board to, Board from)); ff = (BOARD_WIDTH-1)>>1; rt = BOARD_HEIGHT-1; ft = BOARD_LEFT+1; - sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE); } else { rf = BOARD_HEIGHT-1; ff = BOARD_WIDTH>>1; rt = BOARD_HEIGHT-1; ft = BOARD_RGHT-2; - sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE); } } + if(gameInfo.variant == VariantFischeRandom) { + if (WhiteOnMove(yyboardindex)) { + ff = initialRights[2]; + ft = initialRights[0]; + } else { + ff = initialRights[5]; + ft = initialRights[3]; + } + if (appData.debugMode) { + fprintf(debugFP, "Parser FRC short %d %d\n", ff, ft); + } + if(ff < 0 || ft < 0) return 0; + } + sprintf(currentMoveString, "%c%c%c%c",ff+AAA,rf+ONE,ft+AAA,rt+ONE); + if (appData.debugMode) { + fprintf(debugFP, "short castling %d %d\n", ff, ft); + } + return (int) LegalityTest(boards[yyboardindex], - PosFlags(yyboardindex), EP_UNKNOWN, - initialRights, /* [HGM] assume all castlings allowed */ + PosFlags(yyboardindex), EP_UNKNOWN, + castlingRights[yyboardindex], /* [HGM] use true castling rights */ rf, ff, rt, ft, NULLCHAR); } @@ -991,9 +1050,9 @@ static YY_BUFFER_STATE my_file_buffer = NULL; */ int yyoffset() { - int pos = yy_c_buf_p - yy_current_buffer->yy_ch_buf; + int pos = yy_c_buf_p - YY_CURRENT_BUFFER->yy_ch_buf; - return(ftell(yy_current_buffer->yy_input_file) - + return(ftell(YY_CURRENT_BUFFER->yy_input_file) - yy_n_chars + pos); }