"""J.VIP scoped basketball restart matrix, not a general refereeing engine.""" from pathlib import Path import json,sys EVENTS=['ring_same_control','ring_other_control','no_ring_same_live','no_ring_deflected_out_same','ring_deflected_out_same','defensive_foul_front_same'] def classify(event,r): if event not in EVENTS:return {'status':'unknown','seconds':None} if not isinstance(r,int) or not 1<=r<=24:raise ValueError('Only positive whole-second test grid; expiry handled separately') return {'status':'continue_or_reset','seconds':14 if event in ['ring_same_control','ring_deflected_out_same'] else 24 if event=='ring_other_control' else max(r,14) if event=='defensive_foul_front_same' else r} def airborne_expiry(entered,ring,immediate_clear_opponent_control): if entered:return 'goal_counts' if ring:return 'continue_rim_branch' if immediate_clear_opponent_control:return 'disregard_signal_continue' return 'shot_clock_violation' INPUT=json.loads(Path(sys.argv[1] if len(sys.argv)>1 else 'input.json').read_text(encoding='utf-8-sig')) assert INPUT['events']==EVENTS and INPUT['grid']==list(range(1,25)) grid=[{'event':e,'originalSeconds':r,**classify(e,r)} for e in EVENTS for r in INPUT['grid']] f=lambda r:classify('ring_same_control',r)['seconds'] g=lambda r:classify('no_ring_deflected_out_same',r)['seconds'] h=lambda r:classify('defensive_foul_front_same',r)['seconds'] assert [r for r in INPUT['grid'] if f(r)==g(r)]==[14] assert [r for r in INPUT['grid'] if f(r)==h(r)]==list(range(1,15)) assert [f(8),g(8),h(8)]==[14,8,14] assert [f(17),g(17),h(17)]==[14,17,17] assert classify('unobserved_touch_or_control',8)['status']=='unknown' expiry=[{**c,'decision':airborne_expiry(**c)} for c in INPUT['expiryCases']] assert [r['decision'] for r in expiry]==['shot_clock_violation','disregard_signal_continue','continue_rim_branch','goal_counts'] for invalid in [0,25,-1]: try:classify('no_ring_same_live',invalid) except ValueError:pass else:raise AssertionError('Out-of-scope time was silently accepted') out={'status':'AllDeterministicChecksPassed','gridCases':len(grid),'grid':grid,'fEqualsGAt':[14],'fEqualsHAt':list(range(1,15)),'airborneExpiryCases':expiry,'unknownNotForcedToRuling':True,'integerGridCountsAreNotProbabilities':True} print(json.dumps(out,ensure_ascii=False,indent=2))