I am trying to evaluate a FEN position with stockfish.
Given this position:
rnbqkbnr/pppp1p1p/8/4p3/P3P1p1/5N2/1PPP1PPP/RNBQKB1R b KQkq - 0 4
and stockfish 16.
This is the position board picture:
I do this :
./stockfish
ucinewgame
position fen rnbqkbnr/pppp1p1p/8/4p3/P3P1p1/5N2/1PPP1PPP/RNBQKB1R b KQkq - 0 4
go movetime 1000
Very last lines of the output reads:
info depth 26 seldepth 33 multipv 1 score cp 361 nodes 3134961 nps 1566697 hashfull 910 tbhits 0 time 2001 pv g4f3 d2d4 f3g2 f1g2 d7d6 a4a5 g8f6 a1a3 e5d4 c1g5 f8e7 e1g1 h7h6 g5h4 b8c6 a5a6 a8b8 f2f4 h8g8 a3g3 e8f8 e4e5 d6e5 f4e5 c6e5 g3g8 f6g8
bestmove g4f3 ponder d2d4
So, the position evaluation is like +3.6. which is absolutely wrong.
I have tried to feed the FEN with quotes and double quotes with no luck.
I also tried to use python to evaluate the position with the chess module:
import chess
import chess.engine
import re
def extract_numerical_score(stockfish_output):
# Define a regex pattern to match numbers
pattern = r"[-+]?\d+"
# Use re.findall to extract all numbers from the string
numbers = re.findall(pattern, stockfish_output)
return numbers[0] if numbers else None
board = chess.Board("rnbqkbnr/pppp1p1p/8/4p3/P3P1p1/5N2/1PPP1PPP/RNBQKB1R b KQkq - 0 4")
stockfish_path = r"Z:\Tools\stockfish-windows-x86-64-avx2.exe"
# Open the Stockfish engine
engine = chess.engine.SimpleEngine.popen_uci(stockfish_path)
# Analyze the position using Stockfish for 5.0 seconds
analysis = engine.analyse(board, chess.engine.Limit(time=5.0))
# Extract numerical score from Stockfish output
numerical_score = extract_numerical_score(str(analysis["score"]))
print(numerical_score)
But the result is the same.
Interestingly Lichess and Chess.com both shows the correct evaluation when I pasted the FEN position there.
It seems the engine is not understand the colors correctly because the evaluation is almost true but with wrong sign! The position is like -3.6 or so. It can also find the best move which is to take the knight in this position.
From my understanding FEN positions should have everything needed to know for a single chess position.
Am I missing something here ?
Because it's black's turn.
cp
is computed from the perspective of the player about to move. Black is winning, and it's black's turn, so thecp
score is positive.See also: https://chess.stackexchange.com/questions/21845/why-does-stockfish-give-a-negative-score-in-a-theoretical-win-for-white/