Chess Game Analyzer

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

Moderators: hgm, Rebel, chrisw

giovanni
Posts: 142
Joined: Wed Jul 08, 2015 12:30 pm

Re: Chess Game Analyzer

Post by giovanni »

Ferdy wrote:Can be found at upper part of the code.

Code: Select all

"""
I About the script

1. It takes a pgn file with games in it and analyze those
   games there one by one if there are more than one game
2. It mainly uses Stockfish uci engine during development.
   Other uci engines can be used provided those engines support
   multipv mode

   
II. Application references and dependencies

1. Developed under python 2.7.6
2. Using python-chess library version 0.13.0
   site: http://python-chess.readthedocs.org/en/v0.13.0/


III Release notes

1. Release date: January 4, 2016
2. Files: 
   a. game_analyzer_v38.py
   b. python-chess-0.13.0.tar
   c. book.bin 


IV. Chess Game Analyzer Development log

A. Notes:
1. Interesting positions are saved in puzzle.epd
2. Existing comments in the original pgn will not be copied to the analyzed game
3. Original pgn file will not be changed by the script
4. Installation of python 2.7.6 or later (not tested though) and
   python-chess v0.13.0 on your computer are needed for the script to work

B. Changes:
v38
1. Use command line options instead of interactive user input

v37
1. Copy the original headers completely into analyzedGame.pgn
2. Tested using Stockfish 7 under OS windows 7
3. Calculation of position complexity by "pv move changes"
   starts at iteration depth equal to 9
4. Print statements are now converted to function for python 3.0 and later
   compatibility
Download:
https://app.box.com/s/hmle0vhi3xho06yu7oead13ef59bo49d

Hello, Ferdinand. Thanks for the update. I tried to run it on my linux box, but it complains about I/O operations.



giovanni@giovanni-System-Product-Name:~/Downloads$ python game_analyzer_v38.py --file "Francesco_Carnevale_2016.pgn" --engine "/home/giovanni/Downloads/stockfish_16072409_x64" --eoption "Hash value 128, Threads value 1" --movetime 2000 --startmove 8 --endmove 30 --blundermargincp 15 --bookfile "book.bin" --outfile "anagames.pgn"
Chess Game Analyzer v38

Traceback (most recent call last):
File "game_analyzer_v38.py", line 1389, in <module>
main(sys.argv[1:])
File "game_analyzer_v38.py", line 897, in main
engine_id = get_engine_id(sEngine)
File "game_analyzer_v38.py", line 820, in get_engine_id
p.communicate()
File "/usr/lib/python2.7/subprocess.py", line 800, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1412, in _communicate
self.stdin.flush()
ValueError: I/O operation on closed file
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Chess Game Analyzer

Post by Ferdy »

giovanni wrote:Hello, Ferdinand. Thanks for the update. I tried to run it on my linux box, but it complains about I/O operations.



giovanni@giovanni-System-Product-Name:~/Downloads$ python game_analyzer_v38.py --file "Francesco_Carnevale_2016.pgn" --engine "/home/giovanni/Downloads/stockfish_16072409_x64" --eoption "Hash value 128, Threads value 1" --movetime 2000 --startmove 8 --endmove 30 --blundermargincp 15 --bookfile "book.bin" --outfile "anagames.pgn"
Chess Game Analyzer v38

Traceback (most recent call last):
File "game_analyzer_v38.py", line 1389, in <module>
main(sys.argv[1:])
File "game_analyzer_v38.py", line 897, in main
engine_id = get_engine_id(sEngine)
File "game_analyzer_v38.py", line 820, in get_engine_id
p.communicate()
File "/usr/lib/python2.7/subprocess.py", line 800, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1412, in _communicate
self.stdin.flush()
ValueError: I/O operation on closed file
Thanks for reporting. I develop and tested this tool in windows.
What python version did you have?

Be sure that stockfish_16072409_x64 is able to run by itself, by executing it and you then send the uci command, check its output if there is.

I am not familiar with Linux, try to place the engine in the directory where this tools is. Then modify your --engine value. Run the tool again if it will work.
giovanni
Posts: 142
Joined: Wed Jul 08, 2015 12:30 pm

Re: Chess Game Analyzer

Post by giovanni »

Ferdy wrote:
giovanni wrote:Hello, Ferdinand. Thanks for the update. I tried to run it on my linux box, but it complains about I/O operations.



giovanni@giovanni-System-Product-Name:~/Downloads$ python game_analyzer_v38.py --file "Francesco_Carnevale_2016.pgn" --engine "/home/giovanni/Downloads/stockfish_16072409_x64" --eoption "Hash value 128, Threads value 1" --movetime 2000 --startmove 8 --endmove 30 --blundermargincp 15 --bookfile "book.bin" --outfile "anagames.pgn"
Chess Game Analyzer v38

Traceback (most recent call last):
File "game_analyzer_v38.py", line 1389, in <module>
main(sys.argv[1:])
File "game_analyzer_v38.py", line 897, in main
engine_id = get_engine_id(sEngine)
File "game_analyzer_v38.py", line 820, in get_engine_id
p.communicate()
File "/usr/lib/python2.7/subprocess.py", line 800, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1412, in _communicate
self.stdin.flush()
ValueError: I/O operation on closed file
Thanks for reporting. I develop and tested this tool in windows.
What python version did you have?

Be sure that stockfish_16072409_x64 is able to run by itself, by executing it and you then send the uci command, check its output if there is.

I am not familiar with Linux, try to place the engine in the directory where this tools is. Then modify your --engine value. Run the tool again if it will work.
Hi Ferdinand. Thanks for your help in troubleshooting. The engine is in the directory where the tool is and I passed the full path to the script. It works fine standalone.

Python version is: Python 2.7.12 (default, Jul 1 2016, 15:12:24)

I'll try to find a window machine to see if I can reproduce the bug. Just in case: do you happen to have handy the exe file, so that I can run it on linux through the emulator?
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Chess Game Analyzer

Post by Ferdy »

giovanni wrote:
Ferdy wrote:
giovanni wrote:Hello, Ferdinand. Thanks for the update. I tried to run it on my linux box, but it complains about I/O operations.



giovanni@giovanni-System-Product-Name:~/Downloads$ python game_analyzer_v38.py --file "Francesco_Carnevale_2016.pgn" --engine "/home/giovanni/Downloads/stockfish_16072409_x64" --eoption "Hash value 128, Threads value 1" --movetime 2000 --startmove 8 --endmove 30 --blundermargincp 15 --bookfile "book.bin" --outfile "anagames.pgn"
Chess Game Analyzer v38

Traceback (most recent call last):
File "game_analyzer_v38.py", line 1389, in <module>
main(sys.argv[1:])
File "game_analyzer_v38.py", line 897, in main
engine_id = get_engine_id(sEngine)
File "game_analyzer_v38.py", line 820, in get_engine_id
p.communicate()
File "/usr/lib/python2.7/subprocess.py", line 800, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1412, in _communicate
self.stdin.flush()
ValueError: I/O operation on closed file
Thanks for reporting. I develop and tested this tool in windows.
What python version did you have?

Be sure that stockfish_16072409_x64 is able to run by itself, by executing it and you then send the uci command, check its output if there is.

I am not familiar with Linux, try to place the engine in the directory where this tools is. Then modify your --engine value. Run the tool again if it will work.
Hi Ferdinand. Thanks for your help in troubleshooting. The engine is in the directory where the tool is and I passed the full path to the script. It works fine standalone.

Python version is: Python 2.7.12 (default, Jul 1 2016, 15:12:24)

I'll try to find a window machine to see if I can reproduce the bug. Just in case: do you happen to have handy the exe file, so that I can run it on linux through the emulator?
Try without path.
--engine <engine_name>

I will be releasing a new version with exe soon under GPLv3.
giovanni
Posts: 142
Joined: Wed Jul 08, 2015 12:30 pm

Re: Chess Game Analyzer

Post by giovanni »

Ferdy wrote:
giovanni wrote:
Ferdy wrote:
giovanni wrote:Hello, Ferdinand. Thanks for the update. I tried to run it on my linux box, but it complains about I/O operations.



giovanni@giovanni-System-Product-Name:~/Downloads$ python game_analyzer_v38.py --file "Francesco_Carnevale_2016.pgn" --engine "/home/giovanni/Downloads/stockfish_16072409_x64" --eoption "Hash value 128, Threads value 1" --movetime 2000 --startmove 8 --endmove 30 --blundermargincp 15 --bookfile "book.bin" --outfile "anagames.pgn"
Chess Game Analyzer v38

Traceback (most recent call last):
File "game_analyzer_v38.py", line 1389, in <module>
main(sys.argv[1:])
File "game_analyzer_v38.py", line 897, in main
engine_id = get_engine_id(sEngine)
File "game_analyzer_v38.py", line 820, in get_engine_id
p.communicate()
File "/usr/lib/python2.7/subprocess.py", line 800, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1412, in _communicate
self.stdin.flush()
ValueError: I/O operation on closed file
Thanks for reporting. I develop and tested this tool in windows.
What python version did you have?

Be sure that stockfish_16072409_x64 is able to run by itself, by executing it and you then send the uci command, check its output if there is.

I am not familiar with Linux, try to place the engine in the directory where this tools is. Then modify your --engine value. Run the tool again if it will work.
Hi Ferdinand. Thanks for your help in troubleshooting. The engine is in the directory where the tool is and I passed the full path to the script. It works fine standalone.

Python version is: Python 2.7.12 (default, Jul 1 2016, 15:12:24)

I'll try to find a window machine to see if I can reproduce the bug. Just in case: do you happen to have handy the exe file, so that I can run it on linux through the emulator?
Try without path.
--engine <engine_name>

I will be releasing a new version with exe soon under GPLv3.

I tried to use the single name without path, but simply with or without "./" prefix, which in linux indicate to look in the current directory. In the first case, I get the same error, whereas in the second case the script doesn't find the engine.

giovanni@giovanni-System-Product-Name:~/Downloads$ python /home/giovanni/Downloads/game_analyzer_v38.py --file "Francesco_Carnevale_2016.pgn" --engine "./stockfish_16072409_x64" --eoption "Hash value 128, Threads value 1" --movetime 2000 --startmove 8 --endmove 30 --blundermargincp 15 --bookfile "book.bin" --outfile "anagames.pgn"
Chess Game Analyzer v38

Traceback (most recent call last):
File "/home/giovanni/Downloads/game_analyzer_v38.py", line 1389, in <module>
main(sys.argv[1:])
File "/home/giovanni/Downloads/game_analyzer_v38.py", line 897, in main
engine_id = get_engine_id(sEngine)
File "/home/giovanni/Downloads/game_analyzer_v38.py", line 820, in get_engine_id
p.communicate()
File "/usr/lib/python2.7/subprocess.py", line 800, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1412, in _communicate
self.stdin.flush()
ValueError: I/O operation on closed file
giovanni@giovanni-System-Product-Name:~/Downloads$ ^C
giovanni@giovanni-System-Product-Name:~/Downloads$ python /home/giovanni/Downloads/game_analyzer_v38.py --file "Francesco_Carnevale_2016.pgn" --engine "stockfish_16072409_x64" --eoption "Hash value 128, Threads value 1" --movetime 2000 --startmove 8 --endmove 30 --blundermargincp 15 --bookfile "book.bin" --outfile "anagames.pgn"
Chess Game Analyzer v38

Traceback (most recent call last):
File "/home/giovanni/Downloads/game_analyzer_v38.py", line 1389, in <module>
main(sys.argv[1:])
File "/home/giovanni/Downloads/game_analyzer_v38.py", line 897, in main
engine_id = get_engine_id(sEngine)
File "/home/giovanni/Downloads/game_analyzer_v38.py", line 808, in get_engine_id
p = subprocess.Popen(enginefn, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
User avatar
gbtami
Posts: 389
Joined: Wed Sep 26, 2012 1:29 pm
Location: Hungary

Re: Chess Game Analyzer

Post by gbtami »

Ferdy wrote:
giovanni wrote:Hello, Ferdinand. Thanks for the update. I tried to run it on my linux box, but it complains about I/O operations.



giovanni@giovanni-System-Product-Name:~/Downloads$ python game_analyzer_v38.py --file "Francesco_Carnevale_2016.pgn" --engine "/home/giovanni/Downloads/stockfish_16072409_x64" --eoption "Hash value 128, Threads value 1" --movetime 2000 --startmove 8 --endmove 30 --blundermargincp 15 --bookfile "book.bin" --outfile "anagames.pgn"
Chess Game Analyzer v38

Traceback (most recent call last):
File "game_analyzer_v38.py", line 1389, in <module>
main(sys.argv[1:])
File "game_analyzer_v38.py", line 897, in main
engine_id = get_engine_id(sEngine)
File "game_analyzer_v38.py", line 820, in get_engine_id
p.communicate()
File "/usr/lib/python2.7/subprocess.py", line 800, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1412, in _communicate
self.stdin.flush()
ValueError: I/O operation on closed file
Thanks for reporting. I develop and tested this tool in windows.
What python version did you have?

Be sure that stockfish_16072409_x64 is able to run by itself, by executing it and you then send the uci command, check its output if there is.

I am not familiar with Linux, try to place the engine in the directory where this tools is. Then modify your --engine value. Run the tool again if it will work.
The problem is not with --engine but using communicate() on closed STDIN.
If you remove p.communicate() from lines #535, #763, #820 it will work ok.
Using communicate() unnecessary at these points.

We use communicate() in PyChess this way: https://github.com/pychess/pychess/blob ... command.py
User avatar
Kirk
Posts: 5699
Joined: Sat Mar 11, 2006 3:44 am

Re: Chess Game Analyzer

Post by Kirk »

Ferdy wrote:
Kirk wrote:Hi,

Any plans to make a Windows GUI to run this instead of using batch?

Thanks!
I am trying to make one.

Image
Awesome! Thanks! :)
“He knew all the tricks, dramatic irony, metaphor, pathos, puns, parody, litotes and... satire. He was vicious”
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Chess Game Analyzer

Post by Ferdy »

gbtami wrote:
Ferdy wrote:
giovanni wrote:Hello, Ferdinand. Thanks for the update. I tried to run it on my linux box, but it complains about I/O operations.



giovanni@giovanni-System-Product-Name:~/Downloads$ python game_analyzer_v38.py --file "Francesco_Carnevale_2016.pgn" --engine "/home/giovanni/Downloads/stockfish_16072409_x64" --eoption "Hash value 128, Threads value 1" --movetime 2000 --startmove 8 --endmove 30 --blundermargincp 15 --bookfile "book.bin" --outfile "anagames.pgn"
Chess Game Analyzer v38

Traceback (most recent call last):
File "game_analyzer_v38.py", line 1389, in <module>
main(sys.argv[1:])
File "game_analyzer_v38.py", line 897, in main
engine_id = get_engine_id(sEngine)
File "game_analyzer_v38.py", line 820, in get_engine_id
p.communicate()
File "/usr/lib/python2.7/subprocess.py", line 800, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1412, in _communicate
self.stdin.flush()
ValueError: I/O operation on closed file
Thanks for reporting. I develop and tested this tool in windows.
What python version did you have?

Be sure that stockfish_16072409_x64 is able to run by itself, by executing it and you then send the uci command, check its output if there is.

I am not familiar with Linux, try to place the engine in the directory where this tools is. Then modify your --engine value. Run the tool again if it will work.
The problem is not with --engine but using communicate() on closed STDIN.
If you remove p.communicate() from lines #535, #763, #820 it will work ok.
Using communicate() unnecessary at these points.

We use communicate() in PyChess this way: https://github.com/pychess/pychess/blob ... command.py
It works on windows, but not in linux.
Also according to the documentation, communicate() will

Code: Select all

Wait for process to terminate
This would guarantee that the process I started is going to be terminated.
User avatar
gbtami
Posts: 389
Joined: Wed Sep 26, 2012 1:29 pm
Location: Hungary

Re: Chess Game Analyzer

Post by gbtami »

Ferdy wrote:
gbtami wrote:
Ferdy wrote:
giovanni wrote:Hello, Ferdinand. Thanks for the update. I tried to run it on my linux box, but it complains about I/O operations.



giovanni@giovanni-System-Product-Name:~/Downloads$ python game_analyzer_v38.py --file "Francesco_Carnevale_2016.pgn" --engine "/home/giovanni/Downloads/stockfish_16072409_x64" --eoption "Hash value 128, Threads value 1" --movetime 2000 --startmove 8 --endmove 30 --blundermargincp 15 --bookfile "book.bin" --outfile "anagames.pgn"
Chess Game Analyzer v38

Traceback (most recent call last):
File "game_analyzer_v38.py", line 1389, in <module>
main(sys.argv[1:])
File "game_analyzer_v38.py", line 897, in main
engine_id = get_engine_id(sEngine)
File "game_analyzer_v38.py", line 820, in get_engine_id
p.communicate()
File "/usr/lib/python2.7/subprocess.py", line 800, in communicate
return self._communicate(input)
File "/usr/lib/python2.7/subprocess.py", line 1412, in _communicate
self.stdin.flush()
ValueError: I/O operation on closed file
Thanks for reporting. I develop and tested this tool in windows.
What python version did you have?

Be sure that stockfish_16072409_x64 is able to run by itself, by executing it and you then send the uci command, check its output if there is.

I am not familiar with Linux, try to place the engine in the directory where this tools is. Then modify your --engine value. Run the tool again if it will work.
The problem is not with --engine but using communicate() on closed STDIN.
If you remove p.communicate() from lines #535, #763, #820 it will work ok.
Using communicate() unnecessary at these points.

We use communicate() in PyChess this way: https://github.com/pychess/pychess/blob ... command.py
It works on windows, but not in linux.
Also according to the documentation, communicate() will

Code: Select all

Wait for process to terminate
This would guarantee that the process I started is going to be terminated.
The primary function of communicate() (as the name suggests) is to send/receive data to subprocess. It will not guarantee termination. Just waiting for it. I suggest to use terminate() instead.
swami
Posts: 6640
Joined: Thu Mar 09, 2006 4:21 am

Re: Chess Game Analyzer

Post by swami »

Ferdy wrote:
Kirk wrote:Hi,

Any plans to make a Windows GUI to run this instead of using batch?

Thanks!
I am trying to make one.

Image
Perfect! Just awesome.

Keep up the good work, Ferdinand. :-)