Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions CHESS_JSON.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class CHESS_JSON {
const MOVE_ACTIONS = 'actions';
const MOVE_VARIATIONS = 'variations';
const MOVE_MOVES = 'moves';
const MOVE_MOVES_STRING = 'movesStr';
const MOVE_CAPTURE = 'capture';
const MOVE_PROMOTE_TO = 'promoteTo';
const MOVE_CASTLE = 'castle';
Expand All @@ -29,10 +30,12 @@ class CHESS_JSON {
const PGN_KEY_ACTION_CLR_ARROW = "cal";


protected static $jsKeys = array('MOVE_FROM', 'MOVE_TO', 'MOVE_NOTATION', 'FEN','MOVE_COMMENT',
'MOVE_ACTION', 'MOVE_VARIATIONS', 'MOVE_MOVES','MOVE_CAPTURE','MOVE_PROMOTE_TO','MOVE_CASTLE',
'GAME_METADATA', 'GAME_EVENT', 'GAME_WHITE','GAME_BLACK', 'GAME_ECO',

protected static $jsKeys = array(
'MOVE_FROM', 'MOVE_TO', 'MOVE_NOTATION', 'FEN',
'MOVE_COMMENT', 'MOVE_ACTION', 'MOVE_VARIATIONS', 'MOVE_MOVES',
'MOVE_MOVES_STRING', 'MOVE_CAPTURE', 'MOVE_PROMOTE_TO', 'MOVE_CASTLE',
'GAME_METADATA', 'GAME_EVENT', 'GAME_WHITE', 'GAME_BLACK',
'GAME_ECO',
);

public static function toJavascript(){
Expand All @@ -42,4 +45,4 @@ public static function toJavascript(){
}
return 'ludo.CHESS_JSON_KEY = ' . json_encode($ret) .';';
}
}
}
3 changes: 2 additions & 1 deletion PgnGameParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function setPgn($pgnGame){

public function getParsedData(){
$this->gameData = $this->getMetadata();
$this->gameData[CHESS_JSON::MOVE_MOVES_STRING] = $this->getMoveString();
$this->gameData[CHESS_JSON::MOVE_MOVES] = $this->getMoves();
return $this->gameData;
}
Expand Down Expand Up @@ -140,4 +141,4 @@ private function getMoveString() {
$gameData = preg_replace("/(\s+)/", " ", $gameData);
return trim($gameData);
}
}
}
6 changes: 1 addition & 5 deletions PgnParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ public function setPgnContent($content)
private function cleanPgn()
{
$c = $this->pgnContent;

$c = preg_replace('/"\]\s{0,10}\[/s', "]\n[", $c);
$c = preg_replace('/"\]\s{0,10}\[/s', "\"]\n[", $c);
$c = preg_replace('/"\]\s{0,10}([\.0-9]|{)/s', "\"]\n\n$1", $c);

$c = preg_replace("/{\s{0,6}\[%emt[^\}]*?\}/", "", $c);

$c = preg_replace("/\\$[0-9]+/s", "", $c);
$c = str_replace("({", "( {", $c);
$c = preg_replace("/{([^\[]*?)\[([^}]?)}/s", '{$1-SB-$2}', $c);
$c = preg_replace("/\r/s", "", $c);
Expand Down Expand Up @@ -104,8 +102,6 @@ private function getPgnGamesAsArray($pgn)
$content = "\n\n" . $pgn;
$games = preg_split("/\n\n\[/s", $content, -1, PREG_SPLIT_DELIM_CAPTURE);

file_put_contents("parsed.pgn", $content);

for ($i = 1, $count = count($games); $i < $count; $i++) {
$gameContent = trim("[" . $games[$i]);
if (strlen($gameContent) > 10) {
Expand Down