]> git.sesse.net Git - stockfish/commitdiff
Fix en-passant parsing from fen string
authorMarco Costalba <mcostalba@gmail.com>
Wed, 6 Jan 2010 08:58:41 +0000 (09:58 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Wed, 6 Jan 2010 09:07:07 +0000 (10:07 +0100)
According to standard en-passant is recorded in fen string regardless
of whether there is a pawn in position to make an en passant capture.

Instead internally we set ep square only if the pawn can be captured.
So teach from_fen() to correctly handle this difference.

Bug reported and fixed by Justin Blanchard.

No functional change.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/position.cpp

index b4ccff5df3c053d1753934150f1c86deb0eb1232..fb17f209e3e4d24adeb9a45542f77f0b4fa8a3ba 100644 (file)
@@ -204,11 +204,16 @@ void Position::from_fen(const string& fen) {
   while (fen[i] == ' ')
       i++;
 
-  // En passant square
+  // En passant square -- ignore if no capture is possible
   if (    i <= fen.length() - 2
       && (fen[i] >= 'a' && fen[i] <= 'h')
       && (fen[i+1] == '3' || fen[i+1] == '6'))
-      st->epSquare = square_from_string(fen.substr(i, 2));
+  {
+      Square fenEpSquare = square_from_string(fen.substr(i, 2));
+      Color them = opposite_color(sideToMove);
+      if (attacks_from<PAWN>(fenEpSquare, them) & this->pieces(PAWN, sideToMove))
+          st->epSquare = square_from_string(fen.substr(i, 2));
+  }
 
   // Various initialisation
   for (Square sq = SQ_A1; sq <= SQ_H8; sq++)