From 8761d777fe00e0a7fcb2cb6f4e87e462dd97d183 Mon Sep 17 00:00:00 2001 From: Alf Magne Kalleland Date: Sat, 30 Jun 2018 14:03:55 +0200 Subject: [PATCH] Fix problem with en passant moves in combination with king in chess The parser did not handle fen's like 8/8/7p/5P1k/5pPp/P6K/4r2R/8 b - g3 properly. It reported pawn h4 to g3 as an invalid move. This has now been fixed --- FenParser0x88.php | 12 ++++++++++++ PgnParser.php | 3 --- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/FenParser0x88.php b/FenParser0x88.php index 87c121c..e925c48 100755 --- a/FenParser0x88.php +++ b/FenParser0x88.php @@ -556,6 +556,7 @@ class FenParser0x88 } } } + break; // Sliding pieces case 0x05: @@ -922,17 +923,28 @@ class FenParser0x88 $king = $this->cache['king' . $color]; $pieces = $this->cache[$color === 'white' ? 'black' : 'white']; + $enPassantSquare = $this->getEnPassantSquare(); + if ($enPassantSquare) { + $enPassantSquare = Board0x88Config::$mapping[$enPassantSquare]; + } + for ($i = 0, $len = count($pieces); $i < $len; $i++) { $piece = $pieces[$i]; switch ($piece['t']) { case 0x01: if ($king['s'] === $piece['s'] + 15 || $king['s'] === $piece['s'] + 17) { + if($enPassantSquare === $piece['s'] - 16){ + return array($piece['s'], $enPassantSquare); + } return array($piece['s']); } break; case 0x09: if ($king['s'] === $piece['s'] - 15 || $king['s'] === $piece['s'] - 17) { + if($enPassantSquare === $piece['s'] + 16){ + return array($piece['s'], $enPassantSquare); + } return array($piece['s']); } break; diff --git a/PgnParser.php b/PgnParser.php index 7e6b812..3205337 100755 --- a/PgnParser.php +++ b/PgnParser.php @@ -205,9 +205,6 @@ class PgnParser if (isset($move["from"])) { $move["n"] = $move["from"] . $move["to"]; - - #$move["n"] = $move["from"] . $move["to"]; - #unset($move["m"]); unset($move["fen"]); unset($move["from"]); unset($move["to"]);