Simple PGN util

Discussions about Winboard/Xboard. News about engines or programs to use with these GUIs (e.g. tournament managers or adapters) belong in this sub forum.

Moderator: Andres Valverde

Simple PGN util

Postby Richard Allbert » 23 Aug 2005, 14:36

Hi,

Whilst writing the makebook functions for Lime, I wrote a function that takes a pgn file, and writes the games to a text file, line by line in the following format:

e4 e5 Nf3 Nf6 Bc4......
d4 d5 c4 c5...
Nf3 Nf6....

It isn't complicated at all, but I couldn't find a util that does this.

I'll post the .exe and source (c++, it uses vectors) on my website tonight.

http://www.limechess.homecall.co.uk

Hopefully, it will be of use to other beginners out there..

Regards,

Richard
Richard Allbert
 
Posts: 105
Joined: 27 Sep 2004, 11:56
Location: Aschaffenburg, Germany

Re: Simple PGN util

Postby Anonymous » 23 Aug 2005, 18:24

Yace can do something very similar (probably not documented)

At the yace-prompt
carlos_pgn games.pgn new.txt s n n 0 0

new.txt will look like

[TimeControl "900+3"]
e4 e5 Nf3 Nc6 Bb5 a6 Ba4 Bd6 O-O Nge7 c3 O-O d4 b5 Bc2 Bb7 Bg5 [..., everything on one line]
[TimeControl "900+3"]
e4 c5 Nf3 e6 d4 cxd4 Nxd4 Nc6 Nc3 a6 Nxc6 bxc6 Bd3 d5 O-O Nf6 ...
...

Annotations (!, ?, ...) in the original PGN will get lost. Using k instead of n in the above command will keep the annotations.

If you do

carlos_pgn games.pgn new.txt s !! n 0 30

only 30 plies will be written, and each white move will get a !! attached. You can proably see the trick - when you change the second "n" to something else, every black move will get that attached, so for example

carlos_pgn games.pgn new.txt s n ! 0 0

will attach a ! to any black move. There are many more options (most of which I forgot ...).

This can also be useful for book generation purposes, especially, when you are going to prepare a white and a black repertoire by some other (graphical) tools.

Getting rid of the [...] lines (the last PGN tag will be used) could easily be done in an automatic way by sed, for example (but because of the quoting issues, I am not prepared to show the correct command without trying).

Changing to coordinate notation instead of SAN can be done by issuing

gui ChessAcademy

first.

If you wonder about the name of the command, "carlos_pgn" - I had implemented it for Carlos Pesce, a well known book author.

Regards,
Dieter
Anonymous
 

Re: Simple PGN util

Postby Richard Allbert » 23 Aug 2005, 21:11

I had read that YACE could do all of this! :D :D

I couldn't find the list of commands.. :wink:

Anyhow, it was nice to solve the minor problem myself... although it was nothing compared with converting SAN moves to long notation (ie Nf3 to g1f3). It took a lot of debugging to get it right!!!! :shock:

Regards,

Richard
Richard Allbert
 
Posts: 105
Joined: 27 Sep 2004, 11:56
Location: Aschaffenburg, Germany

Re: Simple PGN util

Postby Jim Ablett » 24 Aug 2005, 10:13

Hi Richard,

I use Bookbuilder 3.6b by by Bas Hamstra/Michael Langeveld.

http://home.wxs.nl/~k.e.c/DreamHC/Pagina5.html

It imports pgns and epd's and outputs 'Crafty' format pgns like this >

Code: Select all
[Site '?']
b1c3! c7c5!! e2e4!! b8c6!! g2g3! g7g6!! f1g2!! f8g7!!


It can also compact your book by removing positions that occurred only
twice.

regards,
Jim.
___________________________
http://jimablett.net63.net/
Jim Ablett
 
Posts: 721
Joined: 27 Sep 2004, 10:39
Location: Essex, England

Re: Simple PGN util

Postby Richard Allbert » 24 Aug 2005, 12:23

Hi Jim,

Thanks :) - the problem I am pondering is eliminating lines that only occur once or twice.

I thought of using the STL unique() function on the

Code: Select all
vector<string> gamelines


but that will be slow...

At the moment, pgnread takes about 1 second to write 10,000 games into the line by line e4 e5 Nf3 Nf6 format.

The internal function in my engine takes about 20 seconds to convert 10,000 lines of SAN moves into long algebraic notation.

Regards,

Richard
Richard Allbert
 
Posts: 105
Joined: 27 Sep 2004, 11:56
Location: Aschaffenburg, Germany

Re: Simple PGN util

Postby Jim Ablett » 25 Aug 2005, 10:36

Pgn-extract can also create output like this >

Code: Select all
1. d2d4 d7d5 2. c1f4 b8c6 3. e2e3 e7e6


Here's the commands to use>

Code: Select all
pgn-extract -C -w4096 -Wlalg -obook.txt book.pgn


Jim.
___________________________
http://jimablett.net63.net/
Jim Ablett
 
Posts: 721
Joined: 27 Sep 2004, 10:39
Location: Essex, England


Return to Winboard and related Topics

Who is online

Users browsing this forum: No registered users and 32 guests