python-chess icon indicating copy to clipboard operation
python-chess copied to clipboard

Write high level documentation or recipes

Open niklasf opened this issue 6 years ago • 11 comments

Currently the documentation is built like a reference. Some kind of overview or collection of recipes might be helpful.


Prompted by this email (in German), with some suggestions: image

niklasf avatar Mar 06 '19 17:03 niklasf

some more bits of sample source code would be very useful

ChrisWhittington avatar Mar 08 '19 18:03 ChrisWhittington

I've started a bit of this at http://wiki.bitplan.com/index.php/Python-chess

WolfgangFahl avatar Dec 27 '19 06:12 WolfgangFahl

At this time I've got four engines to try things with with on my mac: gnuchess, stockfish, crafty and xboard. For gnuchess and stockfish I successfully let the engines play against themselves. crafty doesn't seem to support any of the python-chess protocols uci or xboard so I am not pursuing anything with that engine yet.

Now I'd like to use xboard just as a GUI and I don't know how to do that I'd like to do simple session command like http://wiki.bitplan.com/index.php/XBoard#Session_example but when I open xboard with the XBoardProtocol with a SimpleEngine I get <XBoardProtocol (pid=9460)>: Timeout during initialization - is that a separate bug or do i just need some sample code here?

WolfgangFahl avatar Dec 28 '19 08:12 WolfgangFahl

I found the same. Most stuff works except Crafty (and different Craftys don’t work in different ways). However some people do manage to overcome the problems, Ferdinand Mosca, I think, being one.

One Crafty problem is declined to send any PV before one million nodes done, and quite often declines to send a PV anyway. I gave up with it.

Sent from my iPhone

On 28 Dec 2019, at 08:10, Wolfgang Fahl [email protected] wrote:

 At this time I've got four engines to try things with with on my mac: gnuchess, stockfish, crafty and xboard. For gnuchess and stockfish I successfully let the engines play against themselves. crafty doesn't seem to support any of the python-chess protocols uci or xboard so I am not pursuing anything with that engine yet.

Now I'd like to use xboard just as a GUI and I don't know how to do that I'd like to do simple session command like http://wiki.bitplan.com/index.php/XBoard#Session_example but when I open xboard with the XBoardProtocol with a SimpleEngine I get <XBoardProtocol (pid=9460)>: Timeout during initialization - is that a separate bug or do i just need some sample code here?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

ChrisWhittington avatar Dec 28 '19 10:12 ChrisWhittington

@WolfgangFahl To investigate the issue, can you please share the exact Python code and engine version that leads to <XBoardProtocol (pid=9460)>: Timeout during initialization?

niklasf avatar Dec 28 '19 10:12 niklasf

@niklasf:

see https://github.com/WolfgangFahl/play-chess-with-a-webcam/blob/master/tests/test_chessengine.py

I am currently experimenting with this on linux and mac and also get different other issues like Threads hanging

On mac with only calling test_engines

i get: found /Users/wf/bin - prepending it to PATH found crafty engine at /Users/wf/bin/crafty found gnuchess engine at /Users/wf/bin/gnuchess found stockfish engine at /Users/wf/bin/stockfish found xboard engine at /Users/wf/bin/xboard chess engine Crafty Computer Chess called via crafty at /Users/wf/bin/crafty chess engine GNU Chess called via gnuchess at /Users/wf/bin/gnuchess chess engine Stockfish Chess called via stockfish at /Users/wf/bin/stockfish chess engine XBoard called via xboard at /Users/wf/bin/xboard <XBoardProtocol (pid=13124)>: Timeout during initialization Close running child process: kill <_UnixSubprocessTransport closed pid=13124 running stdin=<_UnixWritePipeTransport closing fd=19 idle bufsize=0> stdout=<_UnixReadPipeTransport closing fd=20 idle> stderr=<_UnixReadPipeTransport closing fd=22 idle>>

with using

GNU Chess 6.2.5 installed with macports 2.6.2 $HOME/bin/gnuchess

#!/bin/bash
# WF 2019-12-26
/opt/local/bin/gnuchess --uci

xboard 4.9.1 installed with macports 2.6.2 see http://wiki.bitplan.com/index.php/XBoard $HOME/bin/xboard

#!/bin/bash
# WF 2019-12-26
# call xboard with proper parameters
# Locale
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

export PATH="/opt/local/bin:/opt/local/sbin:$PATH"

# start xboard with no chess program as a passive board
/opt/local/bin/xboard -ncp \
  -blackPieceColor darkred \
  -whitePieceColor lightyellow \
  -clockFont -misc-fixed-bold-r-normal--13-120-75-75-c-80-iso8859-15 \
  -font -misc-fixed-bold-r-normal--13-120-75-75-c-80-iso8859-15 \
  -size Bulky \
  "$@"

Stockfish 240314 SSE4.2 $HOME/bin/stockfish

#!/bin/bash
/Users/wf/source/cpp/Stockfish-240414/osx/stockfish

using the stockfish zip file from http://julien.marcel.free.fr/macchess/Chess_on_Mac/Engines.html

WolfgangFahl avatar Dec 28 '19 10:12 WolfgangFahl

I have now added some code to show the hanging issue add the end see https://github.com/WolfgangFahl/play-chess-with-a-webcam/commit/bcaafe3

WolfgangFahl avatar Dec 28 '19 10:12 WolfgangFahl

  • For the hanging threads: It looks like test_engines is starting some engines, but never closing them. When using SimpleEngine (as opposed to asyncio), the background thread will live as long as the engine.

  • For the timeout: Afaik xboard itself is not an XBoard engine, so it does not declare itself as an XBoard engine within the allotted time.

niklasf avatar Dec 28 '19 11:12 niklasf

How do i close the engines? When calling quit() i get another error:

chess engine GNU Chess called via gnuchess at /Users/wf/bin/gnuchess
Close running child process: kill <_UnixSubprocessTransport closed pid=18268 running stdin=<_UnixWritePipeTransport closing fd=7 idle bufsize=0> stdout=<_UnixReadPipeTransport closing fd=8 idle> stderr=<_UnixReadPipeTransport closing fd=10 idle>>
Traceback (most recent call last):
  File "/Users/wf/Documents/pyworkspace/PlayChessWithAWebCam/tests/test_chessengine.py", line 85, in <module>
    test_engines()
  File "/Users/wf/Documents/pyworkspace/PlayChessWithAWebCam/tests/test_chessengine.py", line 46, in test_engines
    chessEngine.close()    
  File "/Users/wf/Documents/pyworkspace/PlayChessWithAWebCam/pcwawc/chessengine.py", line 76, in close
    self.engine.quit()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/chess/engine.py", line 2350, in quit
    return future.result()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py", line 435, in result
    return self.__get_result()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/tasks.py", line 449, in wait_for
    raise futures.TimeoutError()
concurrent.futures._base.TimeoutError

Do i have to echo some commands into xboard to make xboard behave properly? Is there a gitter chat or something similar for this project?

WolfgangFahl avatar Dec 28 '19 14:12 WolfgangFahl

There wasn't so far, but why not? Created https://gitter.im/python-chess/community.

It looks like gnuchess does not even support the standard quit command. You can do engine.close() to shut it down forcefully. I did not anticipate that, but after 95aade7e46724126bd0a2a7a66c5697c9a5e0f22 the next version of python-chess will support doing

try:
    engine.quit()  # Ask nicely
except asyncio.TimeoutError:
    engine.close()  # Force close

I don't know what you're trying to achieve with xboard. It's a GUI, not an engine.

niklasf avatar Dec 28 '19 16:12 niklasf