How to analyze position score in Stockfish

2.2k Views Asked by At

I have a FEN position and I want to analyze which position is stronger. For example, I have this position

rnbq1bnr/pp2k2N/8/2p1p2Q/4N3/8/PPPP1PPP/R1B1KB1R b KQ - 0 1

How to evaluate a position and get score value using Stockfish? (example, the white score is +9 or black -5)

1

There are 1 best solutions below

0
manlio On

With Python you could use the python-chess library:

import chess
import chess.engine

engine = chess.engine.SimpleEngine.popen_uci("stockfish")

board = chess.Board("rnbq1bnr/pp2k2N/8/2p1p2Q/4N3/8/PPPP1PPP/R1B1KB1R b KQ - 0 1")
info = engine.analyse(board, chess.engine.Limit(depth=20))
print("Score:", info["score"])
# Score: #+9

engine.quit()

Take a look at the engine module for further details.