This script is distributed under the LGPL open source license. Commercial licenses are also available. Some of these licenses also includes personal e-mail support for up to 1 year.
Download files
You can download the the chess parser from this zip file or from
GitHub.
Classes:
PgnParser: Converts pgn files/strings to JSON format.
FenParser0x88: Parser for a chess game. Can be used to make
moves, get notations, valid moves, fen position etc.
Key features of the PgnParser:
Unlimited variations
Supports custom startup position
Creates FEN position for all the moves.
This is the chess parser used in DHTML Chess at dhtmlchess.com
Example of use:
<?php
$parser = new PgnParser('my-games.pgn');
echo json_encode($parser->getGames());
?>
Here, the king on g8 can move to the squares f7, h7, f8, h8.
In this position, there's a black knight on e6 which is
pinned by a white bishop on a2. That's why it doesn't have
any squares to move to ("e6": []).
Comments
Hi, I tried 3 days installing dhtml chess but cant succeed. Please can you publish a manual or tutorial about this. I put the folder in xampp and test from chrome. I cant succed to load a pgn file for tactics training
Nick,This problem has been resolved.It was caused by the 1k15 rank.When I first made this script, I noticed that some programs allowed fen strings like:rnbqkbnr/pppppppp/32/PPPPPPPP/RNBQKBNR w KQkq - 0 1instead ofrnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1i.e. 32 empty squares. So in your example, the parser looked for 15 empty squares and not 6(1+5).I tested with some chess programs today and they reported rnbqkbnr/pppppppp/32/PPPPPPPP/RNBQKBNR w KQkq - 0 1as invalid fen. As a result of this, I have changed the script today to only supports one digit numbers for empty squares. Your example parsed correctly after that modification.Best regards,AlfDHTMLGoodies.com
DHTMLGoodiesat 12:24AM, 2015/12/24.
Good morning!! Thanks!!!!!
Guterkraftlicht19!at 05:54PM, 2016/02/16.
Fatal error: Call to undefined method FenParser0x88::getValidMovesBoardCoordinates() in C:\xampp\htdocs\Testovi\chess-parser\test.php on line 30I can't find function getValidMovesBoardCoordinates() in Class FenParser0x88
Nenadat 08:53AM, 2016/11/20.
Fatal error: Uncaught exception 'Exception' with message 'Fen: 5rk1/5p1p/1q4p1/8/8/8/6PP/Q3R2K b - - 0 48 color: black notation: bxa1... FenParser0x88.php on line 101248. ... bxa1=Q trigered exception.
Nenadat 04:31PM, 2016/11/20.
Notice: Undefined offset: 120 in C:\xampp\htdocs\Testovi\chess-parser\FenParser0x88.php on line 291This notice is allways present.
Nenadat 07:32PM, 2016/11/20.
Nenad,The zip has been updated with a bugfix for this.
[Event "ProofOfConcept"]
[Site "Exploit"]
[Date "2015.??.??"]
[Round "?"]
[White "N.N."]
[Black "N.N."]
[Result "1-0"]
[Annotator ""]
[SetUp "1"]
[FEN "8/7P/8/8/1k15/8/P7/K7 w - - 0 1"]
[PlyCount "1"]
[EventDate "2015.??.??"]
[EventType "game"]
[EventCountry "GER"]
1. a3+
Post your comment
Comment preview: