LittlePlyResearch notebook

multi_game.py

python · 23 lines · Exact bytes

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

Recorded SHA-256 fa8a0dc6371b1da5e89e2a9bcf5910c2bf4e17fa9768405fa215e5d4bd215fecRendered SHA-256 fa8a0dc6371b1da5e89e2a9bcf5910c2bf4e17fa9768405fa215e5d4bd215fec

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"""Same authoritative PGN/journal logic with all real-time clock validation."""
2import json,re
3from pathlib import Path
4import chess
5from core import Game,identity,reconstruct
6from scheduler import realtime_reason
7from rating_policy import ALLOW_RATED
8
9class RealtimeGame(Game):
10    def __init__(self,full,bot,directory):
11        if full.get('variant',{}).get('key')!='standard' or type(full.get('rated')) is not bool or (full['rated'] and not ALLOW_RATED):raise ValueError('unsupported rating or variant game')
12        if full.get('initialFen') not in ('startpos',chess.STARTING_FEN):raise ValueError('nonstandard start')
13        players=[identity(full[x]) for x in ('white','black')]
14        if players.count(bot.lower())!=1:raise ValueError('wrong bot identity')
15        clock=full.get('clock',{})
16        if realtime_reason({'type':'clock','limit':clock.get('initial',-1000)//1000,'increment':clock.get('increment',-1000)//1000}):raise ValueError('unsupported clock')
17        self.id=full['id']
18        if not re.fullmatch('[A-Za-z0-9]{8}',self.id):raise ValueError('invalid game id')
19        self.color=players[0]==bot.lower();self.full=full
20        self.directory=Path(directory)/self.id;self.directory.mkdir(parents=True,exist_ok=True)
21        path=self.directory/'journal.json';self.journal=json.loads(path.read_text()) if path.exists() else {'decisions':{},'events':[]}
22        self.state=full['state'];self.board=reconstruct(self.state['moves']);self.save()
23