- Use piece_sq * 6 + piece_type encoding - 32 active features for 32 pieces on board - Simplified from FullThreats (60,720) to HalfKAv2_hm only - All tests passing (11 tests)
31 lines
945 B
Python
31 lines
945 B
Python
"""Stockfish NNUE evaluation interface"""
|
|
|
|
import chess
|
|
import chess.engine
|
|
from python.constants import HALF_KA_V2_HM
|
|
|
|
|
|
class NNUEEvaluator:
|
|
"""Wrapper for Stockfish with NNUE evaluation"""
|
|
|
|
def __init__(self, stockfish_path: str = "/usr/bin/stockfish"):
|
|
self.engine = chess.engine.SimpleEngine.popen_uci(stockfish_path)
|
|
self.engine.configure({"Skill Level": 0, "UCI_LimitStrength": False})
|
|
|
|
def evaluate(self, fen: str) -> float:
|
|
"""
|
|
Get NNUE evaluation in centipawns.
|
|
Returns: positive for white advantage, negative for black
|
|
"""
|
|
board = chess.Board(fen)
|
|
result = self.engine.play(board, chess.engine.Limit(depth=1))
|
|
|
|
# Get relative centipawn score
|
|
score = result.info.score
|
|
if score.mate():
|
|
return 0 # Don't return mate scores
|
|
return float(score.relative().centipawns())
|
|
|
|
def close(self):
|
|
self.engine.quit()
|