- Create python directory with data/, model/ subdirectories - Implement LinearEval(61072->1) model - Add config, constants, feature_extractor - Add tests with 4 passing test cases
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
"""Generate training data from PGN files"""
|
|
|
|
import chess
|
|
import chess.pgn
|
|
import io
|
|
from typing import List, Tuple
|
|
from python.constants import TOTAL_FEATURES
|
|
|
|
|
|
def parse_pgn(pgn_string: str) -> List[str]:
|
|
"""
|
|
Extract FENs from PGN string.
|
|
|
|
Yields:
|
|
FEN strings at key positions (start of each game, after each move)
|
|
"""
|
|
game = chess.pgn.read_string(pgn_string)
|
|
|
|
# Yield opening position
|
|
if game.board():
|
|
yield game.board().fen()
|
|
|
|
# Yield after each move
|
|
for move in game.mainline_moves():
|
|
board = game.board().copy()
|
|
board.push(move)
|
|
yield board.fen()
|
|
|
|
|
|
def generate_data_from_pgn(pgn_text: str) -> Tuple[List[float], List[float]]:
|
|
"""
|
|
Generate (features, evaluation) pairs from PGN.
|
|
|
|
For now, returns placeholder data.
|
|
"""
|
|
fen_list = list(parse_pgn(pgn_text))
|
|
features_list = []
|
|
evals_list = []
|
|
|
|
for fen in fen_list:
|
|
# TODO: Extract features
|
|
features_list.append([0.0] * TOTAL_FEATURES)
|
|
# TODO: Get evaluation from Stockfish
|
|
evals_list.append(0.0)
|
|
|
|
return features_list, evals_list
|