PGN extract to FEN with best move option

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

Ray Bongalon
Posts: 20
Joined: Mon May 17, 2010 3:53 pm
Location: Christchurch, New Zealand

PGN extract to FEN with best move option

Post by Ray Bongalon »

Hi all,

Is there a tool to extract a pgn file with multiple games to fen with 'bm' for every move?
Let's say I want to extract a 40-move game from move 12 to 40 and every fen line extracted includes 'bm'.
I've was able to extract and pgn using PGNExtract but I can't find the 'bm' option to be included. Cheers.

Ray
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: PGN extract to FEN with best move option

Post by brtzsnr »

pgnextract has the option to include the FEN as comments.

https://www.cs.kent.ac.uk/people/staff/ ... encomments

From here you can get the EPDs for every position using the standard gnu text processing tools (cut, sed, awk).

I know it's not a full answer, but it's a starting point.
Norm Pollock
Posts: 1057
Joined: Thu Mar 09, 2006 4:15 pm
Location: Long Island, NY, USA

Re: PGN extract to FEN with best move option

Post by Norm Pollock »

Ray Bongalon wrote:Hi all,

Is there a tool to extract a pgn file with multiple games to fen with 'bm' for every move?
Let's say I want to extract a 40-move game from move 12 to 40 and every fen line extracted includes 'bm'.
I've was able to extract and pgn using PGNExtract but I can't find the 'bm' option to be included. Cheers.

Ray
Before I answer this, I have to make an obvious disclaimer. Namely, that a "bm" opcode value is an opinion and not an absolute truth. It is based on the analysis of a given engine within the constraints of the hardware, the GUI, and the amount of time and/or depth allowed.

Based on the above understanding, using Arena, a chosen engine (preferably Stockfish or Komodo) to do the analysis, and a couple of my tools (bmOpcode and epdInsert) from 40H-EPD Utility Suite (download from www link below), it is possible to do the following:

1. Use pgn-extract to convert all moves to fens
2. Use Arena and the engine to analyze, preferably the fens of one game at a time
3, Use the tool "bmOpcode" to extract the so-called best move for each fen from Analyses.log produced by Arena and the engine
4. Use the tool "epdInsert" to attach the "bm" opcodes to the fens.

Keep in mind that what is called the "best move" is just an opinion, not an absolute truth.

And you would have to study the readme very carefully to process all the details correctly.
Dann Corbit
Posts: 12545
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: PGN extract to FEN with best move option

Post by Dann Corbit »

pgn2fen:
http://www.7sun.com/chess/

I use -e -l on the options to output as EPD and include leaf nodes, normally.

It will decorate the EPD record the the move from the game as the pm.
If that is what you are looking for, then it is possibly a solution.

For example:
Q:\>type zza.pgn
[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]

1.e4 e5 2.Nc3 Nf6 3. f4 d5 *
Q:\>pgn2fen zza.pgn -e -l
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - fmvn 1; hmvc 0; pm e4;
rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - fmvn 1; hmvc 0; pm e5;
rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - fmvn 2; hmvc 0; pm Nc3;
rnbqkbnr/pppp1ppp/8/4p3/4P3/2N5/PPPP1PPP/R1BQKBNR b KQkq - fmvn 2; hmvc 1; pm Nf6;
rnbqkb1r/pppp1ppp/5n2/4p3/4P3/2N5/PPPP1PPP/R1BQKBNR w KQkq - fmvn 3; hmvc 2; pm f4;
rnbqkb1r/pppp1ppp/5n2/4p3/4PP2/2N5/PPPP2PP/R1BQKBNR b KQkq - fmvn 3; hmvc 0; pm d5;
rnbqkb1r/ppp2ppp/5n2/3pp3/4PP2/2N5/PPPP2PP/R1BQKBNR w KQkq - fmvn 4; hmvc 0;
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
Ray Bongalon
Posts: 20
Joined: Mon May 17, 2010 3:53 pm
Location: Christchurch, New Zealand

Re: PGN extract to FEN with best move option

Post by Ray Bongalon »

Norm Pollock wrote:
Ray Bongalon wrote:Hi all,

Is there a tool to extract a pgn file with multiple games to fen with 'bm' for every move?
Let's say I want to extract a 40-move game from move 12 to 40 and every fen line extracted includes 'bm'.
I've was able to extract and pgn using PGNExtract but I can't find the 'bm' option to be included. Cheers.

Ray
Before I answer this, I have to make an obvious disclaimer. Namely, that a "bm" opcode value is an opinion and not an absolute truth. It is based on the analysis of a given engine within the constraints of the hardware, the GUI, and the amount of time and/or depth allowed.

Based on the above understanding, using Arena, a chosen engine (preferably Stockfish or Komodo) to do the analysis, and a couple of my tools (bmOpcode and epdInsert) from 40H-EPD Utility Suite (download from www link below), it is possible to do the following:

1. Use pgn-extract to convert all moves to fens
2. Use Arena and the engine to analyze, preferably the fens of one game at a time
3, Use the tool "bmOpcode" to extract the so-called best move for each fen from Analyses.log produced by Arena and the engine
4. Use the tool "epdInsert" to attach the "bm" opcodes to the fens.

Keep in mind that what is called the "best move" is just an opinion, not an absolute truth.

And you would have to study the readme very carefully to process all the details correctly.
Thanks a heap. I will try these methods. And thank you also for pointing out the 'bm' usage.
Ray Bongalon
Posts: 20
Joined: Mon May 17, 2010 3:53 pm
Location: Christchurch, New Zealand

Re: PGN extract to FEN with best move option

Post by Ray Bongalon »

Dann Corbit wrote:pgn2fen:
http://www.7sun.com/chess/

I use -e -l on the options to output as EPD and include leaf nodes, normally.

It will decorate the EPD record the the move from the game as the pm.
If that is what you are looking for, then it is possibly a solution.

For example:
Q:\>type zza.pgn
[Event "?"]
[Site "?"]
[Date "????.??.??"]
[Round "?"]
[White "?"]
[Black "?"]
[Result "*"]

1.e4 e5 2.Nc3 Nf6 3. f4 d5 *
Q:\>pgn2fen zza.pgn -e -l
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - fmvn 1; hmvc 0; pm e4;
rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - fmvn 1; hmvc 0; pm e5;
rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - fmvn 2; hmvc 0; pm Nc3;
rnbqkbnr/pppp1ppp/8/4p3/4P3/2N5/PPPP1PPP/R1BQKBNR b KQkq - fmvn 2; hmvc 1; pm Nf6;
rnbqkb1r/pppp1ppp/5n2/4p3/4P3/2N5/PPPP1PPP/R1BQKBNR w KQkq - fmvn 3; hmvc 2; pm f4;
rnbqkb1r/pppp1ppp/5n2/4p3/4PP2/2N5/PPPP2PP/R1BQKBNR b KQkq - fmvn 3; hmvc 0; pm d5;
rnbqkb1r/ppp2ppp/5n2/3pp3/4PP2/2N5/PPPP2PP/R1BQKBNR w KQkq - fmvn 4; hmvc 0;
Cool, thank you.
Ray Bongalon
Posts: 20
Joined: Mon May 17, 2010 3:53 pm
Location: Christchurch, New Zealand

Re: PGN extract to FEN with best move option

Post by Ray Bongalon »

brtzsnr wrote:pgnextract has the option to include the FEN as comments.

https://www.cs.kent.ac.uk/people/staff/ ... encomments

From here you can get the EPDs for every position using the standard gnu text processing tools (cut, sed, awk).

I know it's not a full answer, but it's a starting point.
Thank you.