Need pgn utility to generate 'position startpos moves' data

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Jesse Gersenson
Posts: 593
Joined: Sat Aug 20, 2011 9:43 am

Re: Need pgn utility to generate 'position startpos moves' d

Post by Jesse Gersenson »

zullil wrote:

Code: Select all

$ i586-mingw32msvc-cc testA.cpp -o main.exe -lstdc++
!!

:D

Yes, that works.

$ i586-mingw32msvc-cc testA.cpp -o main.exe -lstdc++
$ wine main.exe
i'll kick myself in the pants if this works

$ i586-mingw32msvc-g++ testA.cpp -o main.exe -lstdc++
$ wine main.exe
i'll kick myself in the pants if this works

Thanks.

Tried the 64-bit but it failed
$ x86_64-w64-mingw32-g++ testA.cpp -o main.exe -lstdc++
$ wine main.exe
err:module:import_dll Loading library libgcc_s_sjlj-1.dll (which is needed by L"Z:\\home\\jesse\\eclipse\\testA\\src\\main.exe") failed (error c000007b).
err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\jesse\\eclipse\\testA\\src\\main.exe") not found
err:module:LdrInitializeThunk Main exe initialization for L"Z:\\home\\jesse\\eclipse\\testA\\src\\main.exe" failed, status c0000135
Jesse Gersenson
Posts: 593
Joined: Sat Aug 20, 2011 9:43 am

Re: Need pgn utility to generate 'position startpos moves' d

Post by Jesse Gersenson »

if anyone wants it, here's the analysis script I wrote.
#!/bin/bash
# expected command line arguements are $1=[file.pgn] $2=[game_id] $3=[seconds per move] $4=[motor]
# for example $ ./thisscript.sh mypgn.pgn 3 2 ./stockfish
movenumber=1
COUNTER=0
pgn="$1"
sec="$3"
gameid="$2"
motor="$4"
log="log-game-$gameid.txt"
./pgn-extract --notags -Wsan -w2000 --noresults --nomovenumbers -o movesnonumbers.txt "$pgn"
./pgn-extract --notags -Wuci --noresults -o moves.txt "$pgn"
rm $log $log".done"
for moves in $(cat moves.txt)
do
let COUNTER=COUNTER+1
#counterminusone=$((COUNTER - 1))
d=`cut -d' ' -f1-$COUNTER moves.txt`
move=`cut -d' ' -f$COUNTER movesnonumbers.txt`
oddOReven=$(( $COUNTER % 2))
# move counter
if [ $oddOReven -eq 0 ];
then
dots=""
let movenumber=movenumber+1
echo $movenumber $dots $move " (ply "$COUNTER ")"
else
dots="..."

echo $movenumber $dots $move "(ply "$COUNTER ")"
fi
echo "XXX $movenumber YYY $move YYY $COUNTER YYY $gameid YYY "|cat >>$log
(echo 'setoption name Hash value 32';sleep 0.01;echo "position startpos moves $d";sleep 0.01;echo 'go movetime 1110600';"sleep" "$sec"; echo 'quit';)|$motor|grep "cp"| tail -1|sed 's/.*cp\ /YYY /g'|sed 's/ nps.*pv.*//g'|sed 's/ upperbound//g'|sed 's/ lowerbound//g'|cat>>$log;tail -2 $log

done

cat $log|tr -d '\n'|sed 's/XXX/\n/g'|sed 's/YYY/\t/g'|awk {'print $1,"\t", $2,"\t" $5/-100'}|awk '/./{print $1, "\t" $2, "\t" $3, "\t" $3+x ;};{x=$3}'|sed '1d'|cat >$log".done";echo "analysis written to $log.done"
Angrim
Posts: 97
Joined: Mon Jun 25, 2012 10:16 pm
Location: Forks, WA
Full name: Ben Nye

Re: Need pgn utility to generate 'position startpos moves' d

Post by Angrim »

Ferdy wrote:A standard pgn format can be converted to uci format using pgn-extract. The output is like this, single line per game.

Code: Select all

e2e4 d7d5 e4d5 g8f6 d2d4 f6d5 g1f3 e7e6 f1e2 f8e7 e1g1 [...] 1-0

d2d4 g8f6 c2c4 e7e6 g1f3 d7d5 b1c3 f8e7 [...] 0-1

[...]
Command is like this, use the latest version as it supports -Wuci option.

Code: Select all

pgn-extract-17-14 --notags -Wuci -onew.pgn input.pgn
Based from above output I think outputting it to your intended format is not that difficult.
Cool, I had just been thinking that a tool that does this would be handy, since my private book code reads lines in d2d4 d7d5 type format.
Now just need to make sure that it can handle crazyhouse drop moves, and conversion to king for suicide chess, and the kings touching in atomic chess...
arturo100
Posts: 53
Joined: Thu Jun 25, 2009 10:34 am

Re: Need pgn utility to generate 'position startpos moves' d

Post by arturo100 »

Hello Jesse.
Many thanks for sharing the shell script too. Unfortunately, it seems that the pasting didn't work very well. I tried to fix things a little bit with the text editor, but I didn't succeed. Also, does the script expect 3 or 4 parameters?

linux@unicluster003_eth0:~$ ./parser.sh prova.pgn 3 ./stockfish
Processing prova.pgn
Tal, Mihail - Zuidema, Coenraad Hoogovens Wijk aan Zee 1973.01.??
1 game matched out of 1.
Processing prova.pgn
Tal, Mihail - Zuidema, Coenraad Hoogovens Wijk aan Zee 1973.01.??
1 game matched out of 1.
rm: cannot remove `log-game-3.txt': No such file or directory
rm: cannot remove `log-game-3.txt.done': No such file or directory
./parser.sh: line 32: syntax error near unexpected token `done'
./parser.sh: line 32: `done'
zullil
Posts: 6442
Joined: Tue Jan 09, 2007 12:31 am
Location: PA USA
Full name: Louis Zulli

Re: Need pgn utility to generate 'position startpos moves' d

Post by zullil »

arturo100 wrote:Hello Jesse.
does the script expect 3 or 4 parameters?
Four. See the script!

Code: Select all

#!/bin/bash 
# expected command line arguments are $1=[file.pgn] $2=[game_id] $3=[seconds per move] $4=[motor] 
# for example $ ./thisscript.sh mypgn.pgn 3 2 ./stockfish 
zullil
Posts: 6442
Joined: Tue Jan 09, 2007 12:31 am
Location: PA USA
Full name: Louis Zulli

Re: Need pgn utility to generate 'position startpos moves' d

Post by zullil »

With code tags instead of quote tags around the script:

Jesse Gersenson wrote:if anyone wants it, here's the analysis script I wrote.

Code: Select all

#!/bin/bash
# expected command line arguements are $1=[file.pgn] $2=[game_id] $3=[seconds per move] $4=[motor]
# for example $ ./thisscript.sh mypgn.pgn 3 2 ./stockfish
movenumber=1
COUNTER=0
pgn="$1"
sec="$3"
gameid="$2"
motor="$4"
log="log-game-$gameid.txt"
./pgn-extract --notags -Wsan -w2000 --noresults --nomovenumbers -o movesnonumbers.txt "$pgn"
./pgn-extract --notags -Wuci --noresults -o moves.txt "$pgn"
rm $log $log".done"
for moves in $(cat moves.txt)
do 
let COUNTER=COUNTER+1
#counterminusone=$((COUNTER - 1))
d=`cut -d' ' -f1-$COUNTER moves.txt`
move=`cut -d' ' -f$COUNTER movesnonumbers.txt`
oddOReven=$(( $COUNTER % 2)) 
        # move counter 
        if [ $oddOReven -eq 0 ]; 
        then
	dots=""
	let movenumber=movenumber+1
	echo $movenumber $dots $move "    (ply "$COUNTER ")"
        else
dots="..."

echo $movenumber $dots $move "(ply "$COUNTER ")"
fi
echo "XXX $movenumber YYY $move YYY $COUNTER YYY $gameid YYY "|cat >>$log
(echo 'setoption name Hash value 32';sleep 0.01;echo "position startpos moves $d";sleep 0.01;echo 'go movetime 1110600';"sleep" "$sec"; echo 'quit';)|$motor|grep "cp"| tail -1|sed 's/.*cp\ /YYY    /g'|sed 's/ nps.*pv.*//g'|sed 's/ upperbound//g'|sed 's/ lowerbound//g'|cat>>$log;tail -2 $log

done

cat $log|tr -d '\n'|sed 's/XXX/\n/g'|sed 's/YYY/\t/g'|awk {'print $1,"\t", $2,"\t" $5/-100'}|awk '/./{print $1, "\t" $2, "\t" $3, "\t" $3+x ;};{x=$3}'|sed '1d'|cat >$log".done";echo "analysis written to $log.done"

arturo100
Posts: 53
Joined: Thu Jun 25, 2009 10:34 am

Re: Need pgn utility to generate 'position startpos moves' d

Post by arturo100 »

Thanks! :)
Jesse Gersenson
Posts: 593
Joined: Sat Aug 20, 2011 9:43 am

Re: Need pgn utility to generate 'position startpos moves' d

Post by Jesse Gersenson »

I stuck the code on my website
http://www.jesseo.com/chess/

current version is analyze-0.1.sh