LittlePlyResearch notebook

mate_backend.py

python · 25 lines · Exact bytes

Line 1 ↗
Version & provenance · service-foundation-dc8989b92ba1

Recorded SHA-256 e8edebf6717d073bfce2d6851a2099f6448a13089ffe154396247fb44e2da705Rendered SHA-256 e8edebf6717d073bfce2d6851a2099f6448a13089ffe154396247fb44e2da705

Service code retains Apache-2.0; the Rust helper component and its adapters are distributed with GPL-3.0-or-later notices and corresponding source. Dependencies retain their own licenses. License notes. Line links are stable within this snapshot. Exact allowlisted files from active release 857bc93bfffb-dc8989b92ba1, verified against its manifest. Service files originate under lichess_service/; helper adapter files at release root. No launcher, account state, credentials or private game logs. Complete GPL helper source is separately downloadable.

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