diff --git a/CHESS_JSON.php b/CHESS_JSON.php index e3b4143..81001e8 100755 --- a/CHESS_JSON.php +++ b/CHESS_JSON.php @@ -23,7 +23,7 @@ class CHESS_JSON { const GAME_ECO = 'black'; const PGN_KEY_ACTION_ARROW = "ar"; - const PGN_KEY_ACTION_HIGHLIGHT = "hl"; + const PGN_KEY_ACTION_HIGHLIGHT = "sq"; protected static $jsKeys = array('MOVE_FROM', 'MOVE_TO', 'MOVE_NOTATION', 'FEN','MOVE_COMMENT', diff --git a/FenParser0x88.php b/FenParser0x88.php index 41c2115..831391b 100755 --- a/FenParser0x88.php +++ b/FenParser0x88.php @@ -667,6 +667,10 @@ class FenParser0x88 return $this->validMoves; } + private function validMoves(){ + $validMovesAndResult = $this->getValidMovesAndResult(); + return $validMovesAndResult["moves"]; + } private function excludeInvalidSquares($squares, $validSquares) { @@ -1324,7 +1328,7 @@ class FenParser0x88 if (!isset($ret['from'])) { $msg = "Fen: " . $this->fen . "\ncolor: " . $color . "\nnotation: " . $notation . "\nRank:" . $fromRank . "\nFile:" . $fromFile . "\n" . count($foundPieces) . ", " . implode(",", $foundPieces); - throw new Exception($msg); + throw new FenParser0x88Exception($msg); } $ret['from'] = Board0x88Config::$numberToSquareMapping[$ret['from']]; $ret['to'] = Board0x88Config::$numberToSquareMapping[$ret['to']]; @@ -1443,6 +1447,10 @@ class FenParser0x88 $move = $this->getFromAndToByNotation($move); } + if(!$this->canMoveFromTo($move["from"], $move["to"])){ + throw new FenParser0x88Exception("Invalid move " . json_encode($move)); + } + $this->fen = null; $this->validMoves = null; $this->piecesInvolved = $this->getPiecesInvolvedInMove($move); @@ -1458,7 +1466,19 @@ class FenParser0x88 $this->notation .= '+'; } } + } + private function canMoveFromTo($from, $to){ + $validMoves = $this->validMoves(); + + $from = Board0x88Config::$mapping[$from]; + $to = Board0x88Config::$mapping[$to]; + + if(empty($validMoves[$from]) || !in_array($to, $validMoves[$from])){ + return false; + } + + return true; } @@ -1776,3 +1796,8 @@ class FenParser0x88 return $fen . " " . $this->getColorCode() . " " . $this->getCastle() . " " . $this->fenParts['enPassant'] . " " . $this->getHalfMoves() . " " . $this->getFullMoves(); } } + + +class FenParser0x88Exception extends Exception{ + +} \ No newline at end of file diff --git a/composer.phar b/composer.phar deleted file mode 100755 index 85d2149..0000000 Binary files a/composer.phar and /dev/null differ diff --git a/test/pgn/pgn-with-arrows.pgn b/test/pgn/pgn-with-arrows.pgn index f04a629..6c51a57 100644 --- a/test/pgn/pgn-with-arrows.pgn +++ b/test/pgn/pgn-with-arrows.pgn @@ -10,9 +10,9 @@ [LiveChessVersion "1.4.8"] [ECO "A04"] -{[%ar e2e4,e4e5] [%hl e2,e4]}1. Nf3 c5 2. c4 Nc6 +{[%ar e2e4,e4e5] [%sq e2,e4]}1. Nf3 c5 2. c4 Nc6 3. Nc3 e5 4. e3 {[%ar a1a8,a8h8]} - Nf6 5. Be2 d5 {[%ar h1h8;#f00,h4a4] [%hl h1,h8,h4]} + Nf6 5. Be2 d5 {[%ar h1h8;#f00,h4a4] [%sq h1,h8,h4]} 6. d4 cxd4 7. exd4 e4 8. Ne5 dxc4 9. Bxc4 Nxe5 10. dxe5 Qxd1+