X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=parser.l;h=bdf11d0858cc47fa13a7a8f1c37ab9039e2ebdb5;hb=36da20342a0bc5ef6c36587944cb2f35b2ea46da;hp=46de027b7bcce1e610285166735b774c6d06d145;hpb=93077be9f3009b8eb6ad64067f31d000aaf284c3;p=xboard.git diff --git a/parser.l b/parser.l old mode 100644 new mode 100755 index 46de027..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 @@ -191,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]); @@ -297,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; } @@ -440,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)) { @@ -475,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; } @@ -543,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 || @@ -557,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; @@ -637,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); } @@ -679,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) { @@ -694,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); } @@ -995,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); }