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
This commit is contained in:
@@ -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;
|
||||
|
@@ -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"]);
|
||||
|
Reference in New Issue
Block a user