test of problemating pgn
This commit is contained in:
@@ -1,42 +1,51 @@
|
||||
<?php
|
||||
|
||||
|
||||
class GameParser {
|
||||
class GameParser
|
||||
{
|
||||
|
||||
private $game;
|
||||
private $fen;
|
||||
|
||||
public function __construct(){
|
||||
public function __construct()
|
||||
{
|
||||
$this->moveParser = new FenParser0x88();
|
||||
}
|
||||
|
||||
public function getParsedGame($game){
|
||||
public function getParsedGame($game)
|
||||
{
|
||||
$this->game = $game;
|
||||
$this->fen = $this->getStartFen();
|
||||
|
||||
$this->moveParser->newGame($this->fen);
|
||||
|
||||
$this->parseMoves($this->game[CHESS_JSON::MOVE_MOVES]);
|
||||
$this->addParsedProperty();
|
||||
return $this->game;
|
||||
}
|
||||
|
||||
private function addParsedProperty(){
|
||||
private function addParsedProperty()
|
||||
{
|
||||
$this->game[CHESS_JSON::GAME_METADATA][CHESS_JSON::MOVE_PARSED] = 1;
|
||||
}
|
||||
|
||||
private function parseMoves(&$moves){
|
||||
foreach($moves as &$move){
|
||||
private function parseMoves(&$moves)
|
||||
{
|
||||
foreach ($moves as &$move) {
|
||||
$this->parseAMove($move);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function parseAMove(&$move){
|
||||
if(!isset($move[CHESS_JSON::MOVE_NOTATION]) || (isset($move[CHESS_JSON::FEN]) && isset($move[CHESS_JSON::MOVE_FROM]) && isset($move[CHESS_JSON::MOVE_TO]))){
|
||||
private function parseAMove(&$move)
|
||||
{
|
||||
if (!isset($move[CHESS_JSON::MOVE_NOTATION]) || (isset($move[CHESS_JSON::FEN]) && isset($move[CHESS_JSON::MOVE_FROM]) && isset($move[CHESS_JSON::MOVE_TO]))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($move[CHESS_JSON::MOVE_VARIATIONS])){
|
||||
if (strlen($move[CHESS_JSON::MOVE_NOTATION]) < 2) return;
|
||||
|
||||
if (isset($move[CHESS_JSON::MOVE_VARIATIONS])) {
|
||||
$fen = $this->moveParser->getFen();
|
||||
$this->parseVariations($move[CHESS_JSON::MOVE_VARIATIONS]);
|
||||
$this->moveParser->setFen($fen);
|
||||
@@ -44,15 +53,17 @@ class GameParser {
|
||||
$move = $this->moveParser->getParsed($move);
|
||||
}
|
||||
|
||||
private function parseVariations(&$variations){
|
||||
foreach($variations as &$variation){
|
||||
private function parseVariations(&$variations)
|
||||
{
|
||||
foreach ($variations as &$variation) {
|
||||
$fen = $this->moveParser->getFen();
|
||||
$this->parseMoves($variation);
|
||||
$this->moveParser->setFen($fen);
|
||||
}
|
||||
}
|
||||
|
||||
private function getStartFen(){
|
||||
private function getStartFen()
|
||||
{
|
||||
return $this->game[CHESS_JSON::FEN];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user