Separate games in a pgn database

Programming Topics (Computer Chess) and technical aspects as test techniques, book building, program tuning etc

Moderator: Andres Valverde

Separate games in a pgn database

Postby rigao » 26 Dec 2010, 12:41

Hello everyone.

I'm trying to make an online database viewer in a mix of javascript and php (something like Chess Tempo, but open source). I want the database viewer to be able to load a .pgn database file and ask you which game do you want to browse (in a plain html select). Once you choose the game to view, it will display it in a board (I probably will use jspgnviewer, which is released under the apache license).

So, as I have the viewer, I just need to load the database and show the user the list of games.

Here I can use your help. I've been reading the pgn standard and I was starting to think how I will get the games from the database when I realised this has already been done many times in open source programs. In particular, xboard can load .pgn databases and shows you the list of games. So there is no point in reinventing the wheel. Can someone point me to the exact code which is responsible from the load of .pgn databases in xboard? I guess it will be in C, but I can then translate it to PHP. It is just that when someone else has thought of every little detail, there is no point for me to rethink it, I may as well copy it :D

Of course any other implementation would do, there is no need to be xboard implementation, but as I'm asking in xboard forum, well, it is kind of logical to ask for the xboard implementation, isn't it?

Thanks.
rigao
 
Posts: 63
Joined: 14 Dec 2008, 17:33

Re: Separate games in a pgn database

Postby nevatre » 27 Dec 2010, 06:09

have a look at GameListBuild(f) in gamelist.c
nevatre
 
Posts: 9
Joined: 10 Jun 2009, 15:34
Location: Newport, UK

Re: Separate games in a pgn database

Postby H.G.Muller » 27 Dec 2010, 09:53

XBoard uses a parser for PGN that is automatically generated from the rules of the PGN grammar, by a utility called 'flex'. The rules (and required semantic actions to get move from and to-square) are defined in a file parser.l, which is fed to flex in the building process to produce a file parser.c. So it is parser.c (containing the low-level parser routine yylex) you would have to translate to PHP, but I am afraid it is not very suitable, as flex generates a table-driven parser, with a huge table of codes.

A source which does the parsing from scratch in C is the Lasker ICS code (the routine alg_parse_move, IIRC). Personally, I think re-inventing the wheel might not be such a bad idea. PGN is not that difficult to parse.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Separate games in a pgn database

Postby Ron Murawski » 28 Dec 2010, 07:48

There's the SanKit code by Steven J. Edwards
http://cfajohnson.com/chess/SAN/
"PGN game notation encoding is found in file sanpgn.c. PGN decoding is the file sanrdr.c"

-Ron
User avatar
Ron Murawski
 
Posts: 352
Joined: 26 Sep 2004, 21:50
Location: Schenectady, NY, USA

Re: Separate games in a pgn database

Postby moralefor » 29 Apr 2011, 12:55

That is a good feature of the website for playing games. This is a good thing to do for choosing games to play on the list. Anyway, it might work like on the GameListBuild.
moralefor
 
Posts: 1
Joined: 29 Apr 2011, 12:36

Re: Separate games in a pgn database

Postby Pablo Vazquez » 29 Apr 2011, 16:59

moralefor wrote:That is a good feature of the website for playing games. This is a good thing to do for choosing games to play on the list. Anyway, it might work like on the GameListBuild.

Turing test failed
Pablo Vazquez
 
Posts: 33
Joined: 15 Aug 2007, 15:35


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 20 guests