4

I'm working with Stockfish in Python 3.

And when I do something like this:

Enter image description here

I get just "bestmove e2e4". How can I retrieve full information?

Like this:

Enter image description here

1

Seems to be working just fine:

>>> from subprocess import Popen, PIPE
>>> p = Popen( 'stockfish', stdout=PIPE, stdin=PIPE)
>>> p.stdin.write('uci\n')
>>> p.stdin.write('go depth 10\n')
>>> print p.communicate()[0]
Stockfish 09-06-13 64bit by Tord Romstad, Marco Costalba and Joona Kiiski
id name Stockfish 09-06-13 64bit
id author Tord Romstad, Marco Costalba and Joona Kiiski

option name Use Debug Log type check default false
option name Use Search Log type check default false
option name Search Log Filename type string default SearchLog.txt
option name Book File type string default book.bin
option name Best Book Move type check default false
option name Contempt Factor type spin default 0 min -50 max 50
option name Mobility (Middle Game) type spin default 100 min 0 max 200
option name Mobility (Endgame) type spin default 100 min 0 max 200
option name Passed Pawns (Middle Game) type spin default 100 min 0 max 200
option name Passed Pawns (Endgame) type spin default 100 min 0 max 200
option name Space type spin default 100 min 0 max 200
option name Aggressiveness type spin default 100 min 0 max 200
option name Cowardice type spin default 100 min 0 max 200
option name Min Split Depth type spin default 7 min 4 max 12
option name Max Threads per Split Point type spin default 5 min 4 max 8
option name Threads type spin default 8 min 1 max 64
option name Use Sleeping Threads type check default true
option name Hash type spin default 32 min 1 max 8192
option name Clear Hash type button
option name Ponder type check default true
option name OwnBook type check default false
option name MultiPV type spin default 1 min 1 max 500
option name Skill Level type spin default 20 min 0 max 20
option name Emergency Move Horizon type spin default 40 min 0 max 50
option name Emergency Base Time type spin default 200 min 0 max 30000
option name Emergency Move Time type spin default 70 min 0 max 5000
option name Minimum Thinking Time type spin default 20 min 0 max 5000
option name Slow Mover type spin default 100 min 10 max 1000
option name UCI_Chess960 type check default false
option name UCI_AnalyseMode type check default false
uciok
info depth 1 seldepth 1 score cp 76 nodes 28 nps 28000 time 1 multipv 1 pv b1c3
info depth 2 seldepth 2 score cp 12 nodes 166 nps 166000 time 1 multipv 1 pv b1c3 b8c6
info depth 3 seldepth 3 score cp 72 nodes 300 nps 300000 time 1 multipv 1 pv b1c3 e7e5 g1f3
info depth 4 seldepth 4 score cp 12 nodes 692 nps 346000 time 2 multipv 1 pv b1c3 g8f6 g1f3 b8c6
info depth 5 seldepth 5 score cp 64 nodes 1311 nps 655500 time 2 multipv 1 pv b1c3 g8f6 g1f3 b8c6 e2e4
info depth 6 seldepth 7 score cp 12 nodes 4288 nps 857600 time 5 multipv 1 pv b1c3 g8f6 g1f3 b8c6 e2e4 d7d5
info depth 7 seldepth 7 score cp 28 nodes 5522 nps 920333 time 6 multipv 1 pv b1c3 g8f6 g1f3 b8c6 d2d4 d7d5 e2e3
info depth 8 seldepth 8 score cp 12 nodes 9003 nps 1286142 time 7 multipv 1 pv b1c3 g8f6 g1f3 b8c6 d2d4 d7d5 e2e3 e7e6
info depth 9 seldepth 13 score cp 48 nodes 21652 nps 1273647 time 17 multipv 1 pv b1c3 g8f6 g1f3 b8c6 e2e3 d7d5 f1b5 c8d7 e1g1 a7a6 b5c6 d7c6
info depth 10 seldepth 16 score cp 52 nodes 34328 nps 1373120 time 25 multipv 1 pv b1c3 g8f6 g1f3 b8c6 e2e4 e7e5 d2d4 e5d4 f3d4 d7d5 e4d5 f6d5 d4c6 b7c6
info nodes 34328 time 25
bestmove b1c3 ponder g8f6

>>>

Don't forget to send uci command after loading the engine, so it can initialize all internal stuff and get ready. This is required by UCI protocol.

  • Thank you so much!) I forgot send "uci" – MrTrushka Sep 23 '18 at 11:40
2

To get evaluation score for each legal move, you can do:

  • Set MultiPV to a high number, like in your answer
  • Play the moves, then invoke SF on each of the resulting FEN. For example, in the starting position you could start 20 SF instances, one for each possible move. This is the approach adopted by commercial companies, such as Chessable.

The first approach works but it's slow and not exactly scalable.

PS: Asking for Python code is off-topic here. We can guide you but we won't write code for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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