Files
chess-engine/python/python/stockfish_wrapper.py
KeshavAnandCode 334bc313b0 feat: implement HalfKAv2_hm feature extraction (352 features)
- 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)
2026-04-14 18:21:31 -05:00

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()