worked on premove bug
[xboard.git] / parser.l
index ca41c63..82957eb 100755 (executable)
--- a/parser.l
+++ b/parser.l
@@ -7,12 +7,12 @@
 %{\r
 /*\r
  * parser.l -- lex parser of algebraic chess moves for XBoard\r
- * $Id: parser.l,v 2.1 2003/10/27 19:21:00 mann Exp $\r
  *\r
  * Copyright 1991 by Digital Equipment Corporation, Maynard,\r
- * Massachusetts.  Enhancements Copyright\r
- * 1992-2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software\r
- * Foundation, Inc.\r
+ * Massachusetts.\r
+ *\r
+ * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005,\r
+ * 2006, 2007, 2008, 2009 Free Software Foundation, Inc.\r
  *\r
  * The following terms apply to Digital Equipment Corporation's copyright\r
  * interest in XBoard:\r
@@ -243,7 +243,8 @@ extern void CopyBoard P((Board to, Board from));
       return (int) IllegalMove;\r
 \r
     result = LegalityTest(boards[yyboardindex],\r
-                         PosFlags(yyboardindex), EP_UNKNOWN,\r
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!\r
+                         EP_UNKNOWN,\r
                           initialRights, /* [HGM] assume all castlings allowed */\r
                           currentMoveString[1] - ONE,\r
                           currentMoveString[0] - AAA,\r
@@ -304,7 +305,8 @@ extern void CopyBoard P((Board to, Board from));
       return 0;\r
 \r
     result = LegalityTest(boards[yyboardindex],\r
-                         PosFlags(yyboardindex), EP_UNKNOWN,\r
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!\r
+                         EP_UNKNOWN,\r
                           initialRights, /* [HGM] assume all castlings allowed */\r
                           currentMoveString[1] - ONE,\r
                           currentMoveString[0] - AAA,\r
@@ -468,9 +470,13 @@ extern void CopyBoard P((Board to, Board from));
     if (WhiteOnMove(yyboardindex)) {\r
         if (yytext[2+skip] == ONE) return (int) ImpossibleMove;\r
        currentMoveString[1] = yytext[2+skip] - 1;\r
+       if(boards[yyboardindex][currentMoveString[1]-ONE][currentMoveString[0]-AAA] != WhitePawn) \r
+               return ImpossibleMove;\r
     } else {\r
         currentMoveString[1] = currentMoveString[3] + 1;\r
         if (currentMoveString[3] == ONE+BOARD_HEIGHT-1) return (int) ImpossibleMove;\r
+       if(boards[yyboardindex][currentMoveString[1]-ONE][currentMoveString[0]-AAA] != BlackPawn) \r
+               return ImpossibleMove;\r
     }\r
     if (yyleng-skip > 3) {\r
        if (yytext[yyleng-1] == ')')\r
@@ -485,7 +491,8 @@ extern void CopyBoard P((Board to, Board from));
     }\r
 \r
     result = LegalityTest(boards[yyboardindex],\r
-                         PosFlags(yyboardindex), EP_UNKNOWN,\r
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!\r
+                         EP_UNKNOWN,\r
                           initialRights, /* [HGM] assume all castlings allowed */\r
                           currentMoveString[1] - ONE,\r
                           currentMoveString[0] - AAA,\r
@@ -525,7 +532,8 @@ extern void CopyBoard P((Board to, Board from));
     }\r
 \r
     result = LegalityTest(boards[yyboardindex],\r
-                         PosFlags(yyboardindex), EP_UNKNOWN,\r
+                         PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: might think we can e.p.!\r
+                         EP_UNKNOWN,\r
                           initialRights, /* [HGM] assume all castlings allowed */\r
                           currentMoveString[1] - ONE,\r
                           currentMoveString[0] - AAA,\r
@@ -706,7 +714,8 @@ extern void CopyBoard P((Board to, Board from));
         fprintf(debugFP, "long castling %d %d\n", ff, ft);\r
     }\r
     return (int) LegalityTest(boards[yyboardindex],\r
-                             PosFlags(yyboardindex), EP_UNKNOWN,\r
+                             PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: e.p.!\r
+                             EP_UNKNOWN,\r
                               castlingRights[yyboardindex], /* [HGM] use true castling rights */\r
                              rf, ff, rt, ft, NULLCHAR);\r
 }\r
@@ -762,7 +771,8 @@ extern void CopyBoard P((Board to, Board from));
     }\r
 \r
     return (int) LegalityTest(boards[yyboardindex],\r
-                              PosFlags(yyboardindex), EP_UNKNOWN,\r
+                             PosFlags(yyboardindex)&~F_MANDATORY_CAPTURE, // [HGM] losers: e.p.!\r
+                             EP_UNKNOWN,\r
                               castlingRights[yyboardindex], /* [HGM] use true castling rights */\r
                              rf, ff, rt, ft, NULLCHAR);\r
 }\r