#!/usr/bin/env python3 """Summarise pw2 runs: DP$27 lifetime, DP$28 trajectory, pieces spawned by each player while active. usage: pw2_summary.py RUNDIR [RUNDIR...]""" import sys, os def load(d): rows=[l.split() for l in open(os.path.join(d,'log.txt'))] hdr=rows[0]; return hdr,[dict(zip(hdr,r)) for r in rows[1:]] for d in sys.argv[1:]: hdr,R=load(d) act=[int(r['rel']) for r in R if r['P1pw']!='FF'] name=os.path.basename(d) if not act: print(f'{name}: P1 $27 never set; P2pw vals {sorted({r["P2pw"] for r in R})}'); continue a0,a1=act[0],act[-1] gaps=[x for x,y in zip(act,act[1:]) if y!=x+1] # pieces: count transitions into state 05 def spawns(key,lo,hi): n=0;prev=None for r in R: t=int(r['rel']) if lo<=t<=hi and r[key]=='05' and prev!='05': n+=1 prev=r[key] return n d28=[]; last=None for r in R: t=int(r['rel']) if a0-1<=t<=a1+1 and (r['P1d28'],r['P2d28'])!=last: last=(r['P1d28'],r['P2d28']); d28.append(f'{t}:{last[0]}/{last[1]}') ends=[r['rel']+':'+r['P1st']+'/'+r['P2st'] for r in R if r['P1st'] in('FE','FF') or r['P2st'] in ('FE','FF')][:1] lv=sorted({(r['lvF6'],r['lvF7']) for r in R if a0<=int(r['rel'])<=a1}) print(f'{name}: $27 {R[a0]["P1pw"]} active {a0}-{a1} ({a1-a0+1}f){" gaps "+str(gaps) if gaps else ""}; spawns P1 {spawns("P1st",a0,a1)} P2 {spawns("P2st",a0,a1)}; ' f'P2pw {sorted({r["P2pw"] for r in R})}; d28 {" ".join(d28[:12])}{" ..." if len(d28)>12 else ""}; lv {lv}; roundend {ends}')