allow castle with move suffix and/or NAG
This commit is contained in:
@@ -188,7 +188,7 @@ class FenParser0x88
|
|||||||
{
|
{
|
||||||
$this->setFen($fen);
|
$this->setFen($fen);
|
||||||
if (!isset($move['from'])) {
|
if (!isset($move['from'])) {
|
||||||
$fromAndTo = $this->getFromAndToByNotation($move[CHESS_JSON::MOVE_NOTATION]);
|
$fromAndTo = $this->getFromAndToByNotation($move['m']);
|
||||||
$move['from'] = $fromAndTo['from'];
|
$move['from'] = $fromAndTo['from'];
|
||||||
$move['to'] = $fromAndTo['to'];
|
$move['to'] = $fromAndTo['to'];
|
||||||
|
|
||||||
@@ -556,7 +556,7 @@ class FenParser0x88
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
// Sliding pieces
|
// Sliding pieces
|
||||||
case 0x05:
|
case 0x05:
|
||||||
@@ -1206,9 +1206,9 @@ class FenParser0x88
|
|||||||
$ret = array('promoteTo' => $this->getPromoteByNotation($notation));
|
$ret = array('promoteTo' => $this->getPromoteByNotation($notation));
|
||||||
$color = $this->getColor();
|
$color = $this->getColor();
|
||||||
|
|
||||||
$offset = 0;
|
$offset = 0; /* a1 */
|
||||||
if ($color === 'black') {
|
if ($color === 'black') {
|
||||||
$offset = 112;
|
$offset = 112; /* a8 */
|
||||||
}
|
}
|
||||||
|
|
||||||
$foundPieces = array();
|
$foundPieces = array();
|
||||||
@@ -1235,7 +1235,7 @@ class FenParser0x88
|
|||||||
|
|
||||||
$ret['to'] = $this->getToSquareByNotation($notation);
|
$ret['to'] = $this->getToSquareByNotation($notation);
|
||||||
switch ($pieceType) {
|
switch ($pieceType) {
|
||||||
case 0x01:
|
case 0x01: // pawn
|
||||||
case 0x09:
|
case 0x09:
|
||||||
if ($color === 'black') {
|
if ($color === 'black') {
|
||||||
$offsets = $capture ? array(15, 17) : array(16);
|
$offsets = $capture ? array(15, 17) : array(16);
|
||||||
@@ -1256,23 +1256,21 @@ class FenParser0x88
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x03:
|
case 0x03: // king
|
||||||
case 0x0B:
|
case 0x0B:
|
||||||
|
if (!strncmp($notation, 'O-O-O', 5)) {
|
||||||
if ($notation === 'O-O') {
|
|
||||||
$foundPieces[] = ($offset + 4);
|
|
||||||
$ret['to'] = $offset + 6;
|
|
||||||
} else if ($notation === 'O-O-O') {
|
|
||||||
$foundPieces[] = ($offset + 4);
|
$foundPieces[] = ($offset + 4);
|
||||||
$ret['to'] = $offset + 2;
|
$ret['to'] = $offset + 2;
|
||||||
|
} else if (!strncmp($notation, 'O-O', 3)) {
|
||||||
|
$foundPieces[] = ($offset + 4);
|
||||||
|
$ret['to'] = $offset + 6;
|
||||||
} else {
|
} else {
|
||||||
$k = $this->getKing($color);
|
$k = $this->getKing($color);
|
||||||
$foundPieces[] = $k['s'];
|
$foundPieces[] = $k['s'];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x02:
|
case 0x02: // knight
|
||||||
case 0x0A:
|
case 0x0A:
|
||||||
|
|
||||||
$pattern = Board0x88Config::$movePatterns[$pieceType];
|
$pattern = Board0x88Config::$movePatterns[$pieceType];
|
||||||
for ($i = 0, $len = count($pattern); $i < $len; $i++) {
|
for ($i = 0, $len = count($pattern); $i < $len; $i++) {
|
||||||
$sq = $ret['to'] + $pattern[$i];
|
$sq = $ret['to'] + $pattern[$i];
|
||||||
@@ -1411,7 +1409,7 @@ class FenParser0x88
|
|||||||
|
|
||||||
function getPieceTypeByNotation($notation, $color = null)
|
function getPieceTypeByNotation($notation, $color = null)
|
||||||
{
|
{
|
||||||
if ($notation === 'O-O-O' || $notation === 'O-O') {
|
if (!strncmp($notation, 'O-O', 3)) {
|
||||||
$pieceType = 'K';
|
$pieceType = 'K';
|
||||||
} else {
|
} else {
|
||||||
$token = substr($notation, 0, 1);
|
$token = substr($notation, 0, 1);
|
||||||
@@ -1812,4 +1810,4 @@ class FenParser0x88
|
|||||||
|
|
||||||
class FenParser0x88Exception extends Exception{
|
class FenParser0x88Exception extends Exception{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user