REE / tasks /chess_mate_distance /solution /reference /source_protocol.py
zzqsb's picture
Release the REE tasks and dataset card.
7f50cd1
Raw History Blame Contribute Delete
1.55 kB
"""Task adapter for the unmodified Crystal v1.1 engine.
Use matetrack's one-million-node evaluation protocol and preserve input order.
"""
import json
import os
import sys
from multiprocessing import Pool
from pathlib import Path
import chess
import chess.engine
sys.path.insert(0, str(Path(os.environ["CORE_DIR"]) / "interface"))
from positions import read_positions
def analyse_many(rows):
results = []
with chess.engine.SimpleEngine.popen_uci(
str(Path(__file__).with_name("engine"))
) as engine:
for index, fen in rows:
board = chess.Board(fen)
mate = None
with engine.analysis(
board, chess.engine.Limit(nodes=1_000_000), game=board
) as analysis:
for info in analysis:
if "score" in info and info.get("multipv", 1) == 1:
mate = None
if "upperbound" not in info and "lowerbound" not in info:
mate = info["score"].pov(board.turn).mate()
results.append((index, mate))
engine.quit()
return results
if __name__ == "__main__":
rows = list(enumerate(read_positions(sys.argv[1])))
with Pool(4) as pool:
chunks = pool.map(analyse_many, [rows[i::4] for i in range(4)])
predictions = [mate for _, mate in sorted(row for chunk in chunks for row in chunk)]
output = Path(sys.argv[2])
output.mkdir(parents=True, exist_ok=True)
(output / "mates.json").write_text(json.dumps(predictions) + "\n")