mate_backend.py
python · 25 lines · Exact bytes
Version & provenance · evaluation-cm7
Recorded SHA-256 e8edebf6717d073bfce2d6851a2099f6448a13089ffe154396247fb44e2da705Rendered SHA-256 e8edebf6717d073bfce2d6851a2099f6448a13089ffe154396247fb44e2da705
Apache-2.0 original project code; dependencies retain their own licenses. License notes. Line links are stable within this snapshot. CM-7 completed implementation source; original and public rendered hashes recorded. Host-specific paths use /work placeholders; inspect reproduction instructions before running. Separate Rust helper retains its GPL license.
1"""Future-only helper selection; Lichess settings come from immutable release policy."""
2import json,hashlib
3from pathlib import Path
4from mate_override import forced_mate as python_mate
5from rust_mate import forced_mate as rust_mate,BINARY
6ROOT=Path(__file__).parent
7
8def configuration():
9 path=ROOT/'mate-policy.json'
10 return json.loads(path.read_text()) if path.exists() else dict(backend='python',max_plies=3,max_nodes=50000,max_seconds=1.)
11
12def provenance(backend,depth):
13 paths=[ROOT/'mate_backend.py',ROOT/'rust_mate.py',ROOT/'mate_ipc.py',ROOT/'mate_cpu_pool.py'] if backend=='rust' else [ROOT/'mate_override.py']
14 if backend=='rust':paths.append(BINARY)
15 return dict(backend=backend,max_plies=depth,files={str(p.name):hashlib.sha256(p.read_bytes()).hexdigest() for p in paths})
16
17def forced_mate(board,*,adjudicate,max_plies=None,backend=None,**budgets):
18 config=configuration();backend=backend or config['backend'];depth=config['max_plies'] if max_plies is None else max_plies
19 if backend=='python':return python_mate(board,adjudicate=adjudicate,max_plies=depth,**budgets)
20 if backend!='rust':raise ValueError('unknown mate backend')
21 budgets.setdefault('max_nodes',config['max_nodes'])
22 budgets['seconds']=min(budgets.get('seconds',config['max_seconds']),config['max_seconds'])
23 budgets.setdefault('workers',config.get('workers',1))
24 return rust_mate(board,adjudicate=adjudicate,max_plies=depth,**budgets)
25