3

In python-chess you can communicate with the engine on a given position. However the method presented in https://python-chess.readthedocs.io/en/latest/uci.html using the engine.go() function with only a time parameter returns just one continuation and that continuations evaluation.

I know in most chess programs you can see the top few ranked positions and their evaluations. How can I do the same in python chess? None of the parameters in engine.go seemed to let me do that.

2 Answers 2

4

You can do this by sending out MultiPV, something like:

engine = chess.uci.popen_engine(...)
engine.setoption({ "MultiPV" : multiPV})

The module will generate multiple lines for you, as an array.

1
  • 1
    Short and simple! Gotta say, love how you and Phonon (like this recent stuff) among others are constantly providing code snippets in these answers, to encourage people to do a bit of scripting/programming on their own, and relying less on commercial-closed-source products.
    – user929304
    Apr 11, 2019 at 10:37
2

As the version of python-chess I'm running doesn't support chess.uci, here's what worked for me.

engine = chess.engine.SimpleEngine.popen_uci("/path/to/engine.exe")
board = chess.Board()
info = engine.analyse(board, chess.engine.Limit(time=10),multipv=20))

info is a list of InfoDict objects, each with the keys "pv" and "score", the list of moves in the line, and the evaluation respectively.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.