"""Replay the immutable 38-base scenes, with explicit native keeper-change scope.

Default mode retains r2's exact-trajectory requirement. A keeper behavior change
cannot claim that invariant: --keeper-reference freshly reruns the exact r2
control, permits only the declared keeper ROM regions and records every current
trajectory and difference. No old successes approve the new image.
"""
from pathlib import Path
from fixture_readiness import coherent_fixture_source
from replay_trajectory_checks import compare as compare_replay,observer_source,negative_controls,compare_live,verify_state_abi
from concurrent.futures import ThreadPoolExecutor
import argparse,json,hashlib,subprocess,os
ap=argparse.ArgumentParser();ap.add_argument('rom',type=Path);ap.add_argument('output',type=Path);ap.add_argument('--reference',type=Path,required=True);ap.add_argument('--state',type=Path,required=True);ap.add_argument('--keeper-reference',type=Path);ap.add_argument('--outlet-reference',type=Path);ap.add_argument('--menu-reference',type=Path);ap.add_argument('--control-reference',type=Path);ap.add_argument('--icing-reference',type=Path);ap.add_argument('--rules-reference',type=Path);ap.add_argument('--mini-reference',type=Path);ap.add_argument('--contact-reference',type=Path);ap.add_argument('--penalty-reference',type=Path);ap.add_argument('--seven-reference',type=Path);ap.add_argument('--manual-reference',type=Path);ap.add_argument('--net-reference',type=Path);ap.add_argument('--shootout-reference',type=Path);ap.add_argument('--receiver-reference',type=Path);ap.add_argument('--height-reference',type=Path);ap.add_argument('--speed-reference',type=Path);ap.add_argument('--pickup-reference',type=Path);ap.add_argument('--directional-reference',type=Path);ap.add_argument('--penalty-rate-reference',type=Path);ap.add_argument('--easy-reference',type=Path);ap.add_argument('--charge-reference',type=Path);ap.add_argument('--pickup-delay-reference',type=Path);ap.add_argument('--alt-goalies-reference',type=Path);ap.add_argument('--strict-so-reference',type=Path);ap.add_argument('--shot-plan-reference',type=Path);ap.add_argument('--faceoff-dots-reference',type=Path)
ap.add_argument('--presentation-reference',type=Path)
ap.add_argument('--quickgame-reference',type=Path)
ap.add_argument('--allstar-reference',type=Path)
ap.add_argument('--replay-hud-reference',type=Path)
ap.add_argument('--transfers-reference',type=Path,help='exact qualified Nov2 before preseason transfers')
ap.add_argument('--refinements-reference',type=Path,help='exact runtime18 transfer implementation before requested presentation/defaults/Allstar-CPU refinements')
a=ap.parse_args();h=Path(__file__).resolve().parent;o=a.output.resolve();o.mkdir(exist_ok=False,parents=True);ref=a.reference.resolve();report=json.loads((ref.parent/'qa_report.json').read_text());assert report['rom_sha256']=='fdf88b7f1933304dd08917b88e1b2e4805072355c1538ff41d876e6e015688c4';assert next(c for c in report['checks'] if c['test']=='ai_playbook_gameplay')['returncode']==0;sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest();assert report['test_sources']['experimental/ai_playbook_gameplay_hook.py']==sha(h/'ai_playbook_gameplay_hook.py'),'The immutable original setup/observer must be used';specs=[json.loads((ref/f'new-{i}/spec.json').read_text()) for i in range(40)]
if a.keeper_reference:
 assert sha(a.keeper_reference)=='f2a6d2ee40f4ac6c7bfe3277fe1859930fc1c579f1cb15aed742c1798f8fd9a3','exact r2 keeper reference required'
 before=a.keeper_reference.read_bytes();after=(a.outlet_reference or a.rom).read_bytes();assert len(before)==len(after)
 code=o/'keeper.bin'
 subprocess.run([str(h.parent/'m68kasm.sh'),str(h/'goalie_anticipation.s'),'2DB800',str(code)],check=True,stdout=subprocess.DEVNULL)
 module=code.read_bytes();assert 0<len(module)<=0x400
 assert after[0x2db800:0x2db800+len(module)]==module
 assert before[0x2db800:0x2db800+len(module)]==b'\xff'*len(module)
 assert before[0xd648:0xd650]==after[0xd648:0xd650] and after[0xd650:0xd652]==(0x14be6-0xd650).to_bytes(2,'big',signed=True)
 assert before[0x14be6:0x14bec]==bytes.fromhex('4e714e714e71') and after[0x14be6:0x14bec]==bytes.fromhex('4ef9002db800')
 assert before[0xd8f8:0xd8fa]==bytes.fromhex('e240') and after[0xd8f8:0xd8fa]==bytes.fromhex('4e71')
 assert before[0xaf92:0xaf9a]==after[0xaf92:0xaf9a],'no general animation-update hook allowed'
 ranges=[(0x120,0x180),(0x18e,0x190),(0xd650,0xd652),(0xd8f8,0xd8fa),(0x14be6,0x14bec),(0x2db800,0x2db800+len(module))]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'unrelated AI/native code or assets changed'
 (o/'scope-proof.json').write_text(json.dumps(dict(keeper_only_ROM_regions=ranges,changed_bytes=len(changed),ordinary_branch_instructions_preserved=True,general_animation_update_exact=True),indent=2)+'\n')
if a.outlet_reference:
 assert a.keeper_reference,'outlet comparison requires the retained r2 keeper control'
 assert sha(a.outlet_reference)=='3453b3fba1a4e3b76c8f859311a499f3f2bf8d9a493280f43ad41eca8b784057','exact r3 input reference required'
 before=a.outlet_reference.read_bytes();after=(a.menu_reference or a.rom).read_bytes();assert len(before)==len(after)
 code=o/'outlet-deadline.bin';subprocess.run([str(h.parent/'m68kasm.sh'),str(h/'outlet_deadline.s'),'2DB400',str(code)],check=True,stdout=subprocess.DEVNULL);module=code.read_bytes();assert after[0x2db400:0x2db400+len(module)]==module and before[0x2db400:0x2db400+len(module)]==b'\xff'*len(module)
 ranges=[(0x120,0x180),(0x18e,0x190),(0x2db400,0x2db400+len(module)),(0x2ea600,0x2eb000),(0x2fdc00,0x2fe000)];changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'changes outside declared input modules/deadline helper'
 for lo,hi in [(0x2ea600,0x2eb000),(0x2fdc00,0x2fe000)]:assert after[lo:hi].count(bytes.fromhex('4eb9002db400'))==1,'one first-publication helper call required per input module'
 (o/'outlet-scope-proof.json').write_text(json.dumps(dict(input_ROM_regions=ranges,changed_bytes=len(changed),no_global_frame_animation_or_physics_hook=True),indent=2)+'\n')


if a.menu_reference:
 assert a.outlet_reference and sha(a.menu_reference)=='4dd53440a7a4b4b7920a432b1e70a18e0ddb43e2a57a553b65cd052a0a0dca50','exact r4 menu reference required'
 before=a.menu_reference.read_bytes();after=(a.control_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0x101ee,0x101f6),(0x17c92,0x17c94),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0x2aa000,0x2aa800),(0x2dba00,0x2dbc00),(0x2de000,0x2df000),(0x2eb000,0x2ec000)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'changes outside declared menu/settings/icing modules'
 assert before[0x101ee:0x101f6]==bytes.fromhex('303c000c61001d38') and after[0x101ee:0x101f6]==bytes.fromhex('4ef9002dba004e71')
 code=o/'icing.bin';subprocess.run([str(h.parent/'m68kasm.sh'),str(h/'icing.s'),'2DBA00',str(code)],check=True,stdout=subprocess.DEVNULL);module=code.read_bytes();assert after[0x2dba00:0x2dba00+len(module)]==module and set(before[0x2dba00:0x2dba00+len(module)])=={255}
 (o/'menu-scope-proof.json').write_text(json.dumps(dict(menu_settings_icing_ROM_regions=ranges,changed_bytes=len(changed),native_award_only_hook=True,no_general_frame_or_physics_hook=True),indent=2)+'\n')


if a.control_reference:
 assert a.menu_reference and sha(a.control_reference)=='a7e8bef0e8c78da6d37eacb432769af3f6d4b99e0196e451875c7991656ca182','exact r5 catch/default control required'
 before=a.control_reference.read_bytes();after=(a.icing_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0x2aa000,0x2aa800),(0x2dbc00,0x2dc000),(0x2de000,0x2de800),(0x2e0000,0x2e0800),(0x2eb000,0x2ec000),(0x2fdc00,0x2fe000),(0x2fe400,0x2fe500)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside declared catch/input/default modules'
 code=o/'goalie-catch-control.bin';subprocess.run([str(h.parent/'m68kasm.sh'),str(h/'goalie_catch_control.s'),'2DBC00',str(code)],check=True,stdout=subprocess.DEVNULL);module=code.read_bytes();assert after[0x2dbc00:0x2dbc00+len(module)]==module and set(before[0x2dbc00:0x2dbc00+len(module)])=={255}
 assert after[0x2fe400:0x2fe500].count(bytes.fromhex('4eb9002dbc00'))==1
 (o/'catch-default-scope-proof.json').write_text(json.dumps(dict(catch_input_defaults_ROM_regions=ranges,changed_bytes=len(changed),accepted_keeper_catch_hook_only=True,no_global_frame_or_physics_hook=True),indent=2)+'\n')


if a.icing_reference:
 assert a.control_reference and sha(a.icing_reference)=='74f099b10459e000b4b50870e41617983641445f83c813328dba019b6b02fd7d','exact r6 default control required'
 before=a.icing_reference.read_bytes();after=(a.rules_reference or a.rom).read_bytes();changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];body=[i for i in changed if not(0x120<=i<0x180 or 0x18e<=i<0x190)]
 assert len(body)==3 and all(before[i]==1 and after[i]==0 and before[i-3:i+3]==bytes.fromhex('31fc0001f0ee') for i in body),'only the three Icing default immediates may change'
 (o/'icing-default-scope-proof.json').write_text(json.dumps(dict(default_immediate_addresses=body,changed_bytes=len(changed),only_three_default_words_change=True,all_other_game_code_exact=True),indent=2)+'\n')

if a.rules_reference:
 assert a.icing_reference and sha(a.rules_reference)=='48af31f9f7c85766951bf42745360571d6e7bf025bdce936363a58a178ab05f6','exact r7 OT/momentum control required'
 before=a.rules_reference.read_bytes();after=(a.mini_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0x2ac000,0x2ae000),(0x2e0000,0x2e0800)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'changes outside the overtime and crowd modules'
 (o/'rules-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),only_overtime_and_momentum_modules=True),indent=2)+'\n')

if a.mini_reference:
 assert a.rules_reference and sha(a.mini_reference)=='083f45ffbfff3986d55fbe2ea13384916c4c5b4f1d0b6c5e21e39aa80af80e02','exact r8 Mini control required'
 before=a.mini_reference.read_bytes();after=(a.contact_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0x1732c,0x17332),(0xf75c2,0xf75c8),(0xf7c72,0xf7c78),(0xf80bc,0xf80c2),(0x2dbe00,0x2dc000),(0x2f8000,0x2f9000),(0x2f9800,0x2fa000),(0x2fd000,0x2fd500),(0x2fd600,0x2fdc00)]
 bindings=[0x2d8cdb,0x2d8d29,0x2df457,0x2e2167,0x2e2171,0x2e21ad,0x2e21bd,0x2e21d7,0x2e21eb]
 pointers=[]
 for at in bindings:
  old=int.from_bytes(before[at-3:at+1],'big');new=int.from_bytes(after[at-3:at+1],'big')
  assert new==old+20 and before[at-5:at-3]==after[at-5:at-3]
  assert before[old:old+16]==after[new:new+16],'referenced stats routine/table changed'
  ranges.append((at-3,at+1));pointers.append(dict(operand=at-3,before=old,after=new))
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside season scheduling and linked season-stat operands'
 (o/'mini-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),linked_stats_operands=pointers,referenced_routine_table_prefixes_exact=True,no_AI_physics_input_or_menu_default_code_change=True),indent=2)+'\n')

if a.contact_reference:
 assert a.mini_reference and sha(a.contact_reference)=='29672052309b0bcad831716cd0edf35b498a265f0063d99173c70dff4df47c3a','exact r9 human-contact control required'
 before=a.contact_reference.read_bytes();after=(a.penalty_reference or a.rom).read_bytes();ranges=[(0x120,0x180),(0x18e,0x190),(0xb810,0xb816),(0x2e1000,0x2e1200)]
 assert before[0xb810:0xb816]==bytes.fromhex('4eb9000fee60') and after[0xb810:0xb816]==bytes.fromhex('4ef9002e100c')
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside human one-timer and owned fresh-C dispatch'
 (o/'human-contact-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),normal_native_shot_physics_pickup_tables_and_AI_exact=True,owned_C_guard_only_on_fresh_human_shoot_press=True),indent=2)+'\n')

if a.penalty_reference:
 assert a.contact_reference and sha(a.penalty_reference)=='b28fa2c8f42bd792f3118bc3d71df2fed5f959957d4adc60f372f2d4863c2038','exact r10 penalty controller reference required'
 before=a.penalty_reference.read_bytes();after=(a.seven_reference or a.rom).read_bytes();ranges=[(0x120,0x180),(0x18e,0x190),(0x121c2,0x121cc),(0xf20c,0xf214),(0x2da800,0x2db000)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside accepted penalty award capture and penalty-shot setup'
 assert before[0x121c2:0x121cc]==bytes.fromhex('31c0d406227cffffb04a') and after[0x121c2:0x121cc]==bytes.fromhex('4eb9002da8004e714e71')
 assert before[0xf20c:0xf214]==bytes.fromhex('61000b143038d408') and after[0xf20c:0xf214]==bytes.fromhex('4eb9002da8044e71')
 (o/'penalty-owner-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),no_per_frame_hook=True,physics_RNG_passing_pickup_AI_menu_and_season_code_exact=True),indent=2)+'\n')

if a.seven_reference:
 assert a.penalty_reference and sha(a.seven_reference)=='8f84f537ab945ea849ffc69eeba6794e9e1651556d3f878648ed846f8ebc4703','exact r11 Mini length reference required'
 before=a.seven_reference.read_bytes();after=(a.manual_reference or a.rom).read_bytes();ranges=[(0x120,0x180),(0x18e,0x190),(0x2aa000,0x2ab000),(0x2dbe00,0x2dc000),(0x2f8000,0x2f9000),(0x2f9800,0x2fa000),(0x2fd600,0x2fdc00),(0x2fc800,0x2fd000)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside Mini count/new-slot/menu/schedule modules'
 (o/'mini-seven-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),AI_physics_input_defaults_and_full_light_schedules_exact=True),indent=2)+'\n')

if a.manual_reference:
 assert a.seven_reference and sha(a.manual_reference)=='2ca0be4ef69f1d875c5a25e1ef91e42bda6b87396c5471fa8a417eb652ec8d60','exact r12 manual keeper reference required'
 before=a.manual_reference.read_bytes();after=(a.net_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0x2ea600,0x2eb000),(0x2db000,0x2db400)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside manual keeper early B dispatch modules'
 (o/'manual-keeper-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),no_new_RAM_or_hook=True,native_pass_physics_AI_season_settings_exact=True),indent=2)+'\n')

if a.net_reference:
 assert a.manual_reference and sha(a.net_reference)=='3070c2bbac4ec9fe6cf578c7fd0a3260869371a232b05ed76f33e44ca71ea899','exact r13 net reference required'
 before=a.net_reference.read_bytes();after=(a.shootout_reference or a.rom).read_bytes();changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];body=[i for i in changed if not(0x120<=i<0x180 or 0x18e<=i<0x190)]
 assert body==[0x14b6c,0x14b74,0x14b7c,0x14b84],('only four net threshold immediate bytes may change',body)
 assert all(before[i:i+2] in [bytes.fromhex('2000'),bytes.fromhex('e000')] and after[i:i+2] in [bytes.fromhex('3000'),bytes.fromhex('d000')] for i in body)
 (o/'net-contact-scope-proof.json').write_text(json.dumps(dict(threshold_immediate_addresses=body,body_changed_bytes=4,all_other_game_code_exact=True,no_new_RAM_or_hook=True,instruction_timing_unchanged=True),indent=2)+'\n')

if a.shootout_reference:
 assert a.net_reference and sha(a.shootout_reference)=='aa035e55db8b43d1d38f3b178a739cc0edfab1fb8ef7837de718248fde5721f1','exact2026-10-31 shootout reference required'
 before=a.shootout_reference.read_bytes();after=(a.receiver_reference or a.rom).read_bytes();ranges=[(0x120,0x180),(0x18e,0x190),(0xf280,0xf286),(0xf298,0xf29a),(0xf2f4,0xf2fc),(0x2daa00,0x2db000)];changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside attempt watcher/countdown helper and hooks'
 assert before[0xf280:0xf286]==bytes.fromhex('31fc0190c31a') and after[0xf280:0xf286]==bytes.fromhex('4eb9002daa04')
 assert before[0xf298:0xf29a]==bytes.fromhex('0064') and after[0xf298:0xf29a]==bytes.fromhex('003c')
 assert before[0xf2f4:0xf2fc]==bytes.fromhex('48a780003038b7aa') and after[0xf2f4:0xf2fc]==bytes.fromhex('4ef9002daa004e71')
 (o/'shootout-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),attempt_watch_and_start_hooks_only=True,private_transient_RAM='F65C-F66F',ordinary_game_physics_AI_season_input_and_assets_exact=True),indent=2)+'\n')

if a.receiver_reference:
 assert a.shootout_reference and sha(a.receiver_reference)=='dc279e63f35b2607ebba4eb5fb439eeb47f36239bddcfaae7c3d24e29f99cb08','exact shootout r2 receiver reference required'
 before=a.receiver_reference.read_bytes();after=(a.height_reference or a.rom).read_bytes();ranges=[(0x120,0x180),(0x18e,0x190),(0xbd06,0xbd0c),(0x2ff1b0,0x2ff1b6),(0x150f6,0x150fc),(0x2dae00,0x2db000)];changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside downed pass/stick-contact guards'
 assert after[0xbd06:0xbd0c]==after[0x2ff1b0:0x2ff1b6]==bytes.fromhex('4eb9002dae00')
 assert before[0x150f6:0x150fc]==bytes.fromhex('4eb9002ff380') and after[0x150f6:0x150fc]==bytes.fromhex('4ef9002dae04')
 (o/'downed-receiver-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),pass_scans_and_actual_stick_contact_only=True,no_RAM_or_SRAM_fields=True,ordinary_AI_physics_scoring_animation_and_random_routines_byte_exact=True),indent=2)+'\n')

if a.height_reference:
 assert a.receiver_reference and sha(a.height_reference)=='40b3a5700ae7c3ce6f0536b878a22b2e7284a8e418231ed6a6ea4ce891fb3548','exact r3 height reference required'
 before=a.height_reference.read_bytes();after=(a.speed_reference or a.rom).read_bytes();ranges=[(0x120,0x180),(0x18e,0x190),(0xbf5e,0xbf70),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0x2aa000,0x2aa800),(0x2de000,0x2df000),(0x2eb000,0x2ec000),(0x2fc800,0x2fd000)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside targeted-pass lift/menu/preference modules'
 assert before[0xbf5e:0xbf70]==bytes.fromhex('11c2b776b47c000c6d00000811fc000cb776') and after[0xbf5e:0xbf70]==bytes.fromhex('4ef9002de4004e714e714e714e714e714e71')
 assert before[0xbf70:0xbfb0]==after[0xbf70:0xbfb0],'horizontal intercept solver changed'
 (o/'pass-height-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),targeted_B_pass_vertical_cap_only=True,horizontal_intercept_A_flips_C_shots_and_blind_pass_code_exact=True,persistent_RAM='F0DC-F0DD',per_season_logical_SRAM='1EEE-1EEF',standalone_logical_SRAM='2E20-2E21',default='Normal'),indent=2)+'\n')

if a.speed_reference:
 assert a.height_reference and sha(a.speed_reference)=='0f7f080a30b52e536d7107ffc75044c21c1c617aa5d0007ad6203349604e2a69','exact r4 speed reference required'
 before=a.speed_reference.read_bytes();after=(a.pickup_reference or a.rom).read_bytes();ranges=[(0x120,0x180),(0x18e,0x190),(0xbf54,0xbf5a),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0x2aa000,0x2aa800),(0x2de000,0x2df000),(0x2eb000,0x2ec000)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside targeted-pass timing/menu/preference modules'
 assert before[0xbf54:0xbf5a]==bytes.fromhex('4eb9002ef00c') and after[0xbf54:0xbf5a]==bytes.fromhex('4eb9002de600')
 assert before[0xbf5a:0xbfb6]==after[0xbf5a:0xbfb6],'native height seam/horizontal solver changed'
 (o/'pass-speed-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),targeted_B_pass_timing_only=True,A_flips_C_shots_blind_pass_code_and_global_gravity_exact=True,active_RAM='F0E8-F0E9',transient_original_time_RAM='F0EA-F0EB',per_season_logical_SRAM='1EEE-1EEF',standalone_logical_SRAM='4D20-4D21',old_standalone_goalie_alias_corrected=True,default='Normal'),indent=2)+'\n')

if a.pickup_reference:
 assert a.speed_reference and sha(a.pickup_reference)=='40f388dc0beaedbd0883fdd4101a30debfb0fbbe62aab9d7a382e61476d513e0','exact r5 pickup reference required'
 before=a.pickup_reference.read_bytes();after=(a.directional_reference or a.rom).read_bytes();ranges=[(0x120,0x180),(0x18e,0x190),(0x1538a,0x15390),(0x2efc00,0x2f0000)];changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside accepted-pickup arbitration hook/module'
 assert before[0x1538a:0x15390]==bytes.fromhex('b07c00065dc1') and after[0x1538a:0x15390]==bytes.fromhex('4ef9002efc00')
 (o/'fair-pickup-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),accepted_native_pickup_only=True,no_RAM_or_SRAM_fields=True,general_controller_switching_physics_AI_and_assets_byte_exact=True,native_rng_draw='one for 2+ eligible, zero for one/none'),indent=2)+'\n')

if a.directional_reference:
 assert a.pickup_reference and sha(a.directional_reference)=='548615ad01079d6a93fc62a0409b4a8d6ec4e53676f8a629081f8cc34da712fa','exact r6 Directional reference required'
 before=a.directional_reference.read_bytes();after=(a.penalty_rate_reference or a.rom).read_bytes();ranges=[(0x120,0x180),(0x18e,0x190),(0xbc40,0xbc48),(0x2ff034,0x2ff044),(0x2ff1d8,0x2ff1e4),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf79ba,0xf79be),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0xf807c,0xf8080),(0x2aa000,0x2aa800),(0x2de000,0x2df000),(0x2e1200,0x2e1600),(0x2e6800,0x2e7000),(0x2eb000,0x2ec000)];changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside human pass-input/cone/menu/preference modules'
 assert before[0xbc40:0xbc48]==bytes.fromhex('080200046600001e') and after[0xbc40:0xbc48]==bytes.fromhex('4ef9002e68004e71')
 exact_regions=[(0xbc64,0xbe26),(0x2ff02a,0x2ff034),(0x2ff044,0x2ff04c),(0x2ff180,0x2ff1d8),(0x2ff1e4,0x2ff208),(0x2fdc00,0x2fe000)]
 for lo,hi in exact_regions:assert before[lo:hi]==after[lo:hi],('CPU path instructions changed',hex(lo),hex(hi))
 assert after[0x2ff034:0x2ff03a]==bytes.fromhex('4ef9002e6804') and after[0x2ff1d8:0x2ff1de]==bytes.fromhex('4ef9002e6818')
 (o/'pass-mode-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),active_RAM='F0FC-F0FF',no_additional_SRAM_fields=True,combined_record='existing1EEE/4D20 with legacy50..53 and new80..9F',human_optional_mode_and_cone_only=True,CPU_pass_and_scan_instruction_regions_exact=exact_regions,CPU_AI_and_global_physics_byte_exact=True,default='Assisted/Default',A_flips_and_C_shots_code_exact=True),indent=2)+'\n')

if a.penalty_rate_reference:
 assert a.directional_reference and sha(a.penalty_rate_reference)=='8172a7e4b3d55754076d4f31de2def263d423bad832b2057538fa3b5c1ca86c7','exact r7 penalty-rate reference required'
 before=a.penalty_rate_reference.read_bytes();after=(a.easy_reference or a.rom).read_bytes();ranges=[(0x120,0x180),(0x18e,0x190),(0x11f78,0x11f7e),(0x2004f0,0x2004fa),(0x2ec800,0x2ed000),(0x2e1000,0x2e1200),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0x2aa000,0x2aa800),(0x2de000,0x2de400),(0x2de900,0x2def80),(0x2e1200,0x2e1600),(0x2e6800,0x2e7000),(0x2eb000,0x2ec000)];changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside penalty admission/whole-fight/menu/combined-preference regions'
 assert before[0x11f78:0x11f7e]==bytes.fromhex('067800c8b89c') and after[0x11f78:0x11f7e]==bytes.fromhex('4ef9002ec800')
 assert before[0x2004f0:0x2004fa]==bytes.fromhex('284b7005267cffffb04a') and after[0x2004f0:0x2004fa]==bytes.fromhex('4ef9002ec8044e714e71')
 exact=[(0x776e,0x777e),(0x11f2c,0x11f78),(0x11f7e,0x11ff2),(0x12174,0x1221c),(0x1013e,0x101fc),(0xbc64,0xbe26),(0x2001de,0x2004f0)]
 for lo,hi in exact:assert before[lo:hi]==after[lo:hi],('native rules/PS/icing/pass/fight-eligibility instructions changed',hex(lo),hex(hi))
 (o/'penalty-rate-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),atomic_human_contact_window='native buffered owned branch only, prior IRQ mask and native post-shot CCR restored',active_RAM='F006 word',no_additional_SRAM_fields=True,record='existing1EEE/4D20, bits5..6 with reserved3 rejected',native_rules_D056_unchanged=True,ordinary_events=['12','16','18','1A','1C','1E','20','22','24'],suppressed_injury='native zero-duration14 report',fight='gate entire incident after original HV chance;26/28/2A awards unchanged',default='100%, no filter RNG',native_instruction_regions_exact=exact),indent=2)+'\n')

if a.easy_reference:
 assert sha(a.easy_reference)=='501da8aaf8fc1fb4f5fdd22f4d8f8d893a8fe06de9ec28cb4ecaf0a6e18297eb','exact r8 Easy reference required'
 before=a.easy_reference.read_bytes();after=(a.charge_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0x8e46,0x8e4c),(0x2e0000,0x2e0800),(0x2ee400,0x2eec00),(0x59956,0x59958),(0x5995a,0x5995c),(0x5995e,0x59960),(0x205744,0x205746),(0x20574c,0x20574e),(0x2085da,0x2085dc),(0x2085e2,0x2085e4),(0x7c1c4,0x7c244),(0x2085fc,0x2085fe),(0x208604,0x208606),(0x9e624,0x9e6a4)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside declared Easy ratings/energy and marker rendering regions'
 (o/'easy-colors-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),no_new_RAM_or_SRAM=True,no_new_Hard_win_rate_search=True),indent=2)+'\n')

if a.charge_reference:
 assert sha(a.charge_reference)=='443c96a23923e96529120cd19c486db1483101896787c76a8d2082e5836e6186','exact r9 charge/color repair reference required'
 before=a.charge_reference.read_bytes();after=(a.pickup_delay_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0xb760,0xb766),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0x2aa000,0x2aa800),(0x2de000,0x2df000),(0x2e1200,0x2e1600),(0x2e6800,0x2e7000),(0x2e8200,0x2e9a00),(0x2eb000,0x2ec000),(0x2fd600,0x2fdc00),(0x4004,0x4084),(0x59956,0x59960),(0x7c1c4,0x7c244),(0x9e624,0x9e6a4),(0x2085da,0x2085dc),(0x2085e2,0x2085e4),(0x2085fc,0x2085fe),(0x208604,0x208606)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside declared charge/menu/storage and marker repair regions'
 for lo,hi in [(0xbc64,0xbdd8),(0xbe26,0xbfb6),(0x15774,0x15790),(0x2dc000,0x2dc800)]:assert before[lo:hi]==after[lo:hi],('shared native CPU pass/physics/energy/Hard gap changed',hex(lo),hex(hi))
 (o/'pass-charge-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),human_B_press_hook='B760',CPU_native_pass_and_solver_exact=True,active_RAM='F008',transient_RAM='F110..F12F',logical_SRAM='4D22..4D29 within Light excluded shared profile gap',native_and_three_seasons_separate=True,no_Hard_win_rate_search=True),indent=2)+'\n')

if a.pickup_delay_reference:
 assert sha(a.pickup_delay_reference)=='5e3d4aedcf006f2c92dacdae965f79b15dfd078fae6a0862f77b6520a60d1eee','exact r10 pickup-delay reference required'
 before=a.pickup_delay_reference.read_bytes();after=(a.alt_goalies_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0x220000,0x221000),(0x2aa000,0x2aa800),(0x2de000,0x2df000),(0x2e1200,0x2e1600),(0x2e6800,0x2e7000),(0x2eb000,0x2ec000)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),'outside declared pickup-delay/menu/storage regions'
 for lo,hi in [(0xbc64,0xbdd8),(0xbe26,0xbfb6),(0x14e10,0x15466),(0xabaa,0xabb6),(0x2dc000,0x2dc800),(0x2fd600,0x2fdc00),(0x2ff500,0x2ff800)]:assert before[lo:hi]==after[lo:hi],('native CPU pass/physics/collision/countdown/energy/render code changed',hex(lo))
 (o/'pickup-delay-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),CPU_native_pass_solver_collision_countdown_exact=True,active_RAM='F010',logical_SRAM='4D2A..4D31 within Light excluded shared profile gap',native_and_three_seasons_separate=True,no_Hard_win_rate_search=True),indent=2)+'\n')


if a.alt_goalies_reference:
 assert sha(a.alt_goalies_reference)=='3d1f54ae96b0308163474b8c138be9ed880fa96d2213e871a8e77e71bdbcccc5','exact r11 alternate keeper reference required'
 before=a.alt_goalies_reference.read_bytes();after=(a.strict_so_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0xc408,0xc410),(0x2ff354,0x2ff360),(0x15288,0x15290),(0x15580,0x15588),(0x155fc,0x15604),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0x221000,0x222000),(0x2aa000,0x2aa800),(0x2ac000,0x2ad000),(0x2de000,0x2df000),(0x2e1200,0x2e1600),(0x2e6800,0x2e7000),(0x2eb000,0x2ec000)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),('outside declared alternate keeper/shot provenance/SOG/menu/storage regions',[hex(i) for i in changed if not any(lo<=i<hi for lo,hi in ranges)][:32])
 for lo,hi in [(0xbc64,0xbdd8),(0xbe26,0xbfb6),(0xabaa,0xabb6),(0x2dc000,0x2dc800),(0x2fd600,0x2fdc00),(0x2ff500,0x2ff800)]:assert before[lo:hi]==after[lo:hi],('CPU passes/solver/native countdown/Hard gap/controller rendering changed',hex(lo))
 (o/'alt-goalies-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),active_RAM='F012..F01F',logical_SRAM='4D32..4D39 within Light excluded shared gap',default='Off',native_and_three_seasons_separate=True,no_Hard_win_rate_search=True),indent=2)+'\n')


if a.strict_so_reference:
 assert sha(a.strict_so_reference)=='331a12164cd1102d4dbbaecea21d7ea12d7f710b79d9c6eaa971cb7d31bc1840','exact Nov1 OT SO reference required'
 before=a.strict_so_reference.read_bytes();after=(a.shot_plan_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0x222000,0x223000),(0x2aa000,0x2aa800),(0x2ac000,0x2ad000),(0x2de000,0x2df000),(0x2e1200,0x2e1600),(0x2e6800,0x2e7000),(0x2eb000,0x2ec000),(0x2daa00,0x2db000)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),('outside declared OT SO roster/spin/menu/storage regions',[hex(i) for i in changed if not any(lo<=i<hi for lo,hi in ranges)][:32])
 for lo,hi in [(0xbc64,0xbdd8),(0xbe26,0xbfb6),(0xabaa,0xabb6),(0x2dc000,0x2dc800),(0x2fd600,0x2fdc00),(0x2ff500,0x2ff800),(0x221000,0x222000)]:assert before[lo:hi]==after[lo:hi],('ordinary pass/Hard/controller/keeper module changed',hex(lo))
 (o/'strict-so-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),active_RAM='F046;F820..F83F',logical_SRAM='4D3A..4D41 within Light excluded shared gap',default='Off',native_and_three_seasons_separate=True,no_normal_frame_hook=True,no_Hard_win_rate_search=True),indent=2)+'\n')

if a.shot_plan_reference:
 assert sha(a.shot_plan_reference)=='984854649bb9528f9dfc2200d43237cb2a3ab2cbe5cc847fde1ef10d375e660f','exact Nov1r2 shot plan reference required'
 before=a.shot_plan_reference.read_bytes();after=(a.faceoff_dots_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0xe10c,0xe116),(0xe412,0xe418),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0x223000,0x224000),(0x2aa000,0x2aa800),(0x2de000,0x2df000),(0x2e1200,0x2e1600),(0x2e6800,0x2e7000),(0x2eb000,0x2ec000)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),('outside declared Hard shot-plan/menu/storage regions',[hex(i) for i in changed if not any(lo<=i<hi for lo,hi in ranges)][:32])
 assert before[0xe412:0xe418]==bytes.fromhex('584f3038b75e') and after[0xe412:0xe418]==bytes.fromhex('4ef900223000')
 assert before[0xe10c:0xe116]==bytes.fromhex('41fa001e08380002c2f2') and after[0xe10c:0xe116]==bytes.fromhex('4ef9002230044e714e71')
 exact=[(0xbc64,0xbdd8),(0xbe26,0xbfb6),(0xc2f2,0xc408),(0xabaa,0xabb6),(0xe0b4,0xe10c),(0xe418,0xe494),(0x2dc000,0x2dc800),(0x2fd600,0x2fdc00),(0x2ff500,0x2ff800),(0x221000,0x223000)]
 for lo,hi in exact:assert before[lo:hi]==after[lo:hi],('native passes/shot physics/caller/Hard/keepers/SO changed',hex(lo))
 (o/'shot-plan-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),native_exact_regions=exact,active_RAM='F810 option;F840..F847 bounded transient',logical_SRAM='4D42..4D49 within Light excluded shared gap',default='Off',no_frame_hook_or_RNG_stat_physics_writes=True,no_Hard_win_rate_search=True),indent=2)+'\n')

if a.faceoff_dots_reference:
 assert sha(a.faceoff_dots_reference)=='0b4b104cf31e3b78d5f686349bbaad73ed54ba491c23c6ac661aca02eca396ca','exact Nov1r3 Faceoff Dots reference required'
 before=a.faceoff_dots_reference.read_bytes();after=(a.presentation_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0x1255a,0x12562),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0x224000,0x225000),(0x2aa000,0x2aa800),(0x2de000,0x2df000),(0x2e1200,0x2e1600),(0x2e6800,0x2e7000),(0x2eb000,0x2ec000)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),('outside declared painted-dot/menu/storage regions',[hex(i) for i in changed if not any(lo<=i<hi for lo,hi in ranges)][:32])
 assert before[0x1255a:0x12562]==bytes.fromhex('610000224278c3e6') and after[0x1255a:0x12562]==bytes.fromhex('4eb9002240004e71')
 exact=[(0xbc64,0xbdd8),(0xbe26,0xbfb6),(0xc2f2,0xc408),(0xabaa,0xabb6),(0xe0b4,0xe494),(0x124b0,0x1255a),(0x12562,0x12600),(0xf9f6,0xfad4),(0x2dc000,0x2dc800),(0x2fd600,0x2fdc00),(0x2ff500,0x2ff800),(0x221000,0x224000),(0x2ac000,0x2ad000)]
 for lo,hi in exact:assert before[lo:hi]==after[lo:hi],('native movement/pass/shot/formation/Hard/keeper/SO changed',hex(lo))
 (o/'faceoff-dots-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),native_exact_regions=exact,active_RAM='F848 option; only BF94/BF96 geometric point when enabled',logical_SRAM='4D4A..4D51 within Light excluded shared gap',default='Off',no_normal_frame_hook_or_RNG_stat_physics_writes=True,no_Hard_win_rate_search=True),indent=2)+'\n')

if a.presentation_reference:
 assert sha(a.presentation_reference)=='c32a79e34127757b52cd488c124c9247bf7b875088bac89956a6b7ca2b132cf6','exact Nov1r4 presentation/receiver reference required'
 before=a.presentation_reference.read_bytes();after=(a.quickgame_reference or a.rom).read_bytes()
 ranges=[(0x2dc000,0x2dc280),(0x120,0x180),(0x18e,0x190),(0xf7758,0xf775a),(0xf7762,0xf7764),(0xf777a,0xf777c),(0xf7b44,0xf7b46),(0xf7bba,0xf7bbe),(0xf7c08,0xf7c0a),(0x225000,0x229000),(0x260000,0x28ee00),(0x2aa000,0x2aa800),(0x2dd000,0x2dd400),(0x2de000,0x2df000),(0x2e0000,0x2e0800),(0x2e1200,0x2e1600),(0x2e6800,0x2e7000),(0x2eb000,0x2ec000),(0x2ed000,0x2ed800)]
 changed=[i for i,(x,y) in enumerate(zip(before,after)) if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges) for i in changed),('outside declared receiver/Momentum/HUD/menu/storage regions',[hex(i) for i in changed if not any(lo<=i<hi for lo,hi in ranges)][:32])
 exact=[(0xbc64,0xbdd8),(0xbe26,0xbfb6),(0xc2f2,0xc408),(0xabaa,0xabb6),(0xe0b4,0xe494),(0x103c8,0x1090a),(0x113e4,0x114e0),(0x14b00,0x15466),(0x221000,0x225000),(0x2da000,0x2dc000),(0x2dc280,0x2dd000),(0x2ea000,0x2eb000),(0x2ed800,0x2ee000),(0x2f0000,0x300000)]
 for lo,hi in exact:assert before[lo:hi]==after[lo:hi],('native passing/physics/steering/DMA/keeper/controller/prior option/critical velocity code changed',hex(lo))
 assert before[0x225000:0x229000]==b'\xff'*0x4000 and before[0x260000:0x28ee00]==b'\xff'*192000
 (o/'presentation-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),native_exact_regions=exact,active_RAM='F84A option;E8F6..E8F9 font keys;existing receiver/cache/HUD fields',logical_SRAM='4D52..4D59 independent native/Full/Light/Mini pairs',default='Momentum On; existing up-to10percent; Easy independent',native_movement_pass_shot_DMA_keeper_controller_critical_velocity_unchanged=True,defensive_target_and_arrival_callback_changed=True,no_Hard_win_rate_search=True),indent=2)+'\n')

def qualify_net_change(before,after,before_net,after_net):
 assert len(before)==len(after)==len(before_net)==len(after_net)==600,'incomplete native replay'
 raw_exact=before==after
 event=next((i for i,(b,n) in enumerate(zip(before_net,after_net)) if b!=n),None)
 if event is None:
  assert raw_exact,'native gameplay differs without a net impact'
  return dict(raw_exact=True,verified_impact=None,exact_prefix_frames=600)
 assert event>0 and before[:event]==after[:event],'gameplay differs before the verified net impact'
 b,n=before_net[event],after_net[event];changed=[]
 for k,(old,new) in enumerate(zip(b['nets'],n['nets'])):
  if old==new:continue
  assert before_net[event-1]['nets'][k]['pos']==new['pos'] and before_net[event-1]['nets'][k]['velocity']==new['velocity']==[0,0],('net was moving before the candidate impact',event,k)
  displacement=[x-y for x,y in zip(old['pos'],new['pos'])]
  assert all(abs(delta)<=(abs(v)+1023)//1024 and delta*v>=0 for delta,v in zip(displacement,old['velocity'])),('first-frame net movement is not consistent with its native impulse',event,k,displacement,old['velocity'])
  quarter=max(map(abs,old['velocity']));assert old['velocity']!=[0,0] and 8192<4*quarter+3 and 4*quarter<=12291,('impact outside changed threshold band',event,k,old,new)
  changed.append(dict(net=k,old_velocity=old['velocity'],new_velocity=new['velocity'],first_frame_net_displacement=displacement,old_speed_component_interval=[4*quarter-3,4*quarter+3]))
 assert changed,'first divergence is not a net release'
 colliders=[i for i,(old,new) in enumerate(zip(b['actors'],n['actors'])) if old['velocity']==[0,0] and new['velocity']!=[0,0] and old['pos']==new['pos']]
 assert colliders,('no native stopped-collider versus solid-net response',event)
 return dict(raw_exact=raw_exact,verified_impact=dict(frame=event+1,nets=changed,colliders=colliders,control_stop_flags=b['stop'],candidate_stop_flags=n['stop']),exact_prefix_frames=event,differing_raw_frames=sum(x!=y for x,y in zip(before,after)))

if a.quickgame_reference:
 assert sha(a.quickgame_reference)=='db244dd005f960a9923c44f0dc4168fb938af227a5e9aa97f24d376fd295291e','exact Nov1r5 Quickgame parent required'
 before=a.quickgame_reference.read_bytes();after=(a.allstar_reference or a.rom).read_bytes()
 ranges=[(0x120,0x180),(0x18e,0x190),(0x7c2e,0x7c34),(0x7c68,0x7c6e),(0x13134,0x1313a),(0x1732c,0x1733c),(0xf75c2,0xf75c8),(0xf7c72,0xf7c78),(0xf80bc,0xf80c2),(0xf280,0xf286),(0x229000,0x22c000),(0x2ea400,0x2ec000),(0x2f9800,0x2fa000)]
 linked=[]
 changed=[i for i,(x,y)in enumerate(zip(before,after))if x!=y]
 assert all(any(lo<=i<hi for lo,hi in ranges)for i in changed),('outside declared Quickgame menu/input/season dispatch',[hex(i)for i in changed if not any(lo<=i<hi for lo,hi in ranges)][:32])
 exact=[(0x2aa000,0x2ab000),(0x2f8000,0x2f9000),(0x2fc000,0x2fc800),(0x2fd000,0x2fd500),(0x2e2000,0x2e2800),(0xbc64,0xbdd8),(0xbe26,0xbfb6),(0xc2f2,0xc408),(0xabaa,0xabb6),(0xe0b4,0xe494),(0x103c8,0x1090a),(0x113e4,0x114e0),(0x14b00,0x15466),(0x225000,0x229000),(0x2da000,0x2dc000),(0x2dc280,0x2dd000),(0x2ed000,0x2ee000)]
 for lo,hi in exact:assert before[lo:hi]==after[lo:hi],('unrelated native physics/AI/HUD changed',hex(lo))
 (o/'quickgame-scope-proof.json').write_text(json.dumps(dict(ROM_regions=ranges,changed_bytes=len(changed),linked_season_operands=linked,native_exact_regions=exact,active_RAM='F84C exhibition flag/F84E choice; no new SRAM namespace',scope='Explicit human-only menu/controller and isolated season dispatch. Added input admission may affect HV timing; every ordinary scene compared and retained.'),indent=2)+'\n')

decoder_abi=verify_state_abi(a.rom,h,o/'native-state-abi')if a.replay_hud_reference else None
fixture_hook=o/'coherent-fixture-hook.py';fixture_hook.write_text(coherent_fixture_source((h/'ai_playbook_gameplay_hook.py').read_text())+observer_source())

if a.allstar_reference:
 assert sha(a.allstar_reference)=='49c8b23b940a9c5368580dfcad11626a3ffbd4a51cdcae10ca8c9ce01f642487','exact R6 Allstar parent required'
 before=a.allstar_reference.read_bytes();after=(a.replay_hud_reference or a.rom).read_bytes();assert len(before)==len(after)
 from allstar import ENTRY,TABLE,PHOTO_TABLE,RECORDS
 ranges=[(0x120,0x180),(0x18e,0x190),(0x22a000,0x22b000),(0x22c000,0x22f000)]
 # Menu-linked symbols only; native scene/physics/statistics algorithms stay exact.
 ranges += [(at,at+6)for at in[0xf7c72,0xf80bc,0xf75c2,0x1732c]]
 for at,size in[(0xFE172,8),(0x8078,8),(0xf8a3e,6),(0xf99f8,6),(0xf9a2c,6),(0xfa370,6),(0xfa888,6),(0xfa952,6),(0xfae56,6),(0xfb152,6),(0xfc58c,6),(0xfc600,6),(0xfcc62,6),(0x8250,6),(0x1345e,6),(0x171c2,6),(0xf7c7c,6),(0x132e4,8),(0x1330a,8),(0x17c1e,6),(0xf8948,6),(0xfae2a,6)]:ranges.append((at,at+size))
 for pattern,lo,hi in[('41f9002ff800',0x2ff400,0x2ff800),('41f8030e226a001e',0x2ff400,0x2ff800),('41f8030ebab00000',0x222000,0x223000),('41f9002f8f24',0x222000,0x223000),('41f9002f8f24',0x2d8c80,0x2d8d40),('43f9002f8f24',0x2df400,0x2df800)]:
  blob=bytes.fromhex(pattern);at=before.find(blob,lo,hi);assert at>=0 and before.find(blob,at+len(blob),hi)<0;(ranges.append((at,at+len(blob))))
 changed=[i for i,(x,y)in enumerate(zip(before,after))if x!=y];assert all(any(lo<=i<hi for lo,hi in ranges)for i in changed),'outside declared conditional Allstar/menu/getter regions'
 exact=[(0x30e,0x180e),(0xa000,0x11200),(0x2f0000,0x2f8000),(0x260000,0x28ee00),(0x2ff800,0x2ffb40),(0x2aa000,0x2aa800),(0x2fc000,0x2fc800)]
 for lo,hi in exact:assert before[lo:hi]==after[lo:hi],('ordinary roster/physics/slot/table/assets changed',hex(lo))
 assert before[0x22c000:0x22f000]==b'\xff'*0x3000
 (o/'allstar-scope-proof.json').write_text(json.dumps(dict(allowed_regions=ranges,changed_bytes=len(changed),ordinary_native_exact_regions=exact,active_RAM='F850 Allstar flag,F858/F85A previous clubs; no new SRAM',scope='Native conditional record/photo/Crit/keeper metadata selection, menu mode and fixed virtual clubs. No general frame/AI/physics hook. Actual current/freshR6 scenes and full earlier chain retained.'),indent=2)+'\n')

if a.replay_hud_reference:
 assert sha(a.replay_hud_reference)=='6e66c0afe2496eb3f6a688c29888ca62b17aee0b0f51efec96d11dce5e842b31'
 before=a.replay_hud_reference.read_bytes();after=(a.transfers_reference or a.rom).read_bytes();assert before[0xa68c:0xa79c]==after[0xa68c:0xa79c],'native replay decoder changed';ranges=[(0x120,0x180),(0x18e,0x190),(0x227000,0x228000),(0x229000,0x22b000),(0x2e5000,0x2e5400),(0x2ec000,0x2ec800),(0x2ed000,0x2ed800),(0x2ea000,0x2ea400),(0x240000,0x250000),(0x5995a,0x5995c)]
 changes=[i for i,(x,y)in enumerate(zip(before,after))if x!=y];assert changes and all(any(lo<=i<hi for lo,hi in ranges)for i in changes),('outside replay title/panel helper regions',[hex(i)for i in changes if not any(lo<=i<hi for lo,hi in ranges)][:32])
 (o/'replay-hud-scope-proof.json').write_text(json.dumps(dict(changed_bytes=len(changes),allowed_regions=ranges,transient_RAM='F670-F673 stack snapshot pointer only during automatic replay;94bytes stack allocation',native_VCR_tile_allocation=76,title_VCR_tiles=[14,40],ordinary_game_code_and_assets_exact=True),indent=2)+'\n')

if a.transfers_reference:
 from transfers_scope import verify as verify_transfers_scope
 (o/'transfers-scope-proof.json').write_text(json.dumps(verify_transfers_scope(a.transfers_reference.read_bytes(),(a.refinements_reference or a.rom).read_bytes()),indent=2)+'\n')
if a.refinements_reference:
 assert a.transfers_reference,'refinements require the complete retained transfer/reference chain'
 from refinements_scope import verify as verify_refinements_scope
 (o/'refinements-scope-proof.json').write_text(json.dumps(verify_refinements_scope(a.refinements_reference.read_bytes(),a.rom.read_bytes()),indent=2)+'\n')

def audit_actual_pair(case,current_rom,parent_rom,pairs):
 """Retain every native sample/difference without asserting trajectory equality."""
 audits=[]
 for mode,npath,bpath in pairs:
  nr=json.loads(npath.read_text());br=json.loads(bpath.read_text());assert len(nr)==len(br)==600
  for label,rows in [('current',nr),('parent',br)]:
   assert rows[-1]['clock']<rows[0]['clock'] and all(len(row['positions'])==12 and len(row['jobs'])==12 and len(row['score'])==2 and all(0<=g<256 for g in row['score'])and all(-400<=point[1]<=400 for point in row['positions'])and(row['owner']<12 or row['owner']>=0x8000)for row in rows),('invalid actual native scene',case,mode,label)
  differences=[dict(frame=j+1,fields={k:dict(current=n[k],parent=b[k])for k in n if n[k]!=b[k]})for j,(n,b)in enumerate(zip(nr,br))if n!=b]
  audits.append(dict(mode=mode,samples=600,raw_exact=npath.read_bytes()==bpath.read_bytes(),different_samples=len(differences),differences=differences,current_SHA256=sha(npath),parent_SHA256=sha(bpath)))
 return dict(case=case,current_rom_sha256=sha(current_rom),parent_rom_sha256=sha(parent_rom),actual_current_comparisons=audits,scope='Actual native paths and every difference retained; added dispatch/defaults can change native timing and outcomes. No trajectory-equivalence or Hard strength claim.')

def run(i):
 p=o/str(i);p.mkdir();expected=ref/f'new-{i}/trajectory.json'
 def replay(rom,directory,disable_auto=False):
  directory.mkdir(exist_ok=True);(directory/'spec.json').write_text(json.dumps(specs[i]));(directory/'commands.txt').write_text(f'100 load {a.state.resolve()}\n709 exit\n');env={k:v for k,v in os.environ.items() if not k.startswith('GPGX_')};env.update(GPGX_DEV='513',GPGX_HOOK=str(h/'testcases/net_contact_audit_hook.py') if a.net_reference else str(fixture_hook),NET_ORIGINAL_HOOK=str(fixture_hook),MAINTENANCE_NO_AUTOREPLAY=str(int(disable_auto)))
  with (directory/'log.txt').open('w') as log:subprocess.run(['python3',str(h/'test_core.py'),str(rom.resolve()),str(directory/'commands.txt'),str(directory)],env=env,stdout=log,stderr=log,check=True,timeout=30)
  return directory/'trajectory.json'
 actual=replay(a.rom,p/'current')
 if a.refinements_reference:
  refinement_parent=replay(a.refinements_reference,p/'refinements-runtime18-control')
  refinement_off=replay(a.rom,p/'refinements-Off-current',True)
  refinement_parent_off=replay(a.refinements_reference,p/'refinements-Off-runtime18-control',True)
  (p/'refinements-comparison.json').write_text(json.dumps(audit_actual_pair(i,a.rom,a.refinements_reference,[('AutoOn',actual,refinement_parent),('AutoOff',refinement_off,refinement_parent_off)]),indent=2)+'\n')
  actual=refinement_parent
 if a.transfers_reference:
  # New native roster hooks execute conditional Off paths and add CPU work.
  # Retain every actual current sample and difference; never label this an
  # unchanged trajectory. The immutable replay repair's strict contract is
  # freshly rechecked on its exact Nov2 image below, including all40 AutoOff
  # pairs. Transfer Off native semantics/ABI are independently mandatory.
  transfer_actual=actual;transfer_parent=replay(a.transfers_reference,p/'transfers-Nov2-control')
  transfer_rom=a.refinements_reference or a.rom
  transfer_off=replay(transfer_rom,p/'transfers-Off-current',True);parent_off=replay(a.transfers_reference,p/'transfers-Off-Nov2-control',True)
  (p/'transfers-comparison.json').write_text(json.dumps(audit_actual_pair(i,transfer_rom,a.transfers_reference,[('AutoOn',transfer_actual,transfer_parent),('AutoOff',transfer_off,parent_off)]),indent=2)+'\n')
  actual=transfer_parent
 if a.replay_hud_reference:
  control=replay(a.replay_hud_reference,p/'replay-hud-r7-control')
  comparison=compare_replay(json.loads(actual.read_text()),json.loads(control.read_text()),json.loads((actual.parent/'presentation_trace.json').read_text()),json.loads((control.parent/'presentation_trace.json').read_text()))
  strict_current=replay(a.transfers_reference or a.rom,p/'strict-live-current',True);strict_parent=replay(a.replay_hud_reference,p/'strict-live-r7-control',True)
  compare_live(json.loads(strict_current.read_text()),json.loads(strict_parent.read_text()));assert strict_current.read_bytes()==strict_parent.read_bytes(),'strict live raw bytes changed'
  comparison['strict_auto_off']=dict(raw_exact=True,samples=600,current_trajectory_sha256=sha(strict_current),reference_trajectory_sha256=sha(strict_parent),declared_fixture='F0DE1 only during100..108 setup; no live outcome/position/RNG forcing')
  (p/'replay-hud-comparison.json').write_text(json.dumps(dict(case=i,**comparison,current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(control)),indent=2)+'\n')
  actual=control
 if a.allstar_reference:
  control=replay(a.allstar_reference,p/'allstar-r6-control');current=json.loads(actual.read_text());parent=json.loads(control.read_text());assert len(current)==len(parent)==600
  (p/'allstar-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==control.read_bytes(),first_differing_frame=next((j+1 for j,(b,n)in enumerate(zip(current,parent))if b!=n),None),differing_frames=sum(b!=n for b,n in zip(current,parent)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(control)),indent=2)+'\n')
  actual=control
 if a.quickgame_reference:
  control=replay(a.quickgame_reference,p/'quickgame-r5-control');current=json.loads(actual.read_text());parent=json.loads(control.read_text());assert len(current)==len(parent)==600
  assert current[-1]['clock']<current[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions'])for x in current),('invalid ordinary native scene after Quickgame dispatch',i)
  (p/'quickgame-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==control.read_bytes(),first_differing_frame=next((j+1 for j,(b,n)in enumerate(zip(current,parent))if b!=n),None),differing_frames=sum(b!=n for b,n in zip(current,parent)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(control)),indent=2)+'\n')
  actual=control
 if a.presentation_reference:
  control=replay(a.presentation_reference,p/'presentation-r4-control');current=json.loads(actual.read_text());parent=json.loads(control.read_text());assert len(current)==len(parent)==600
  assert current[-1]['clock']<current[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in current),('invalid native receiver/Momentum/HUD scene',i)
  (p/'presentation-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==control.read_bytes(),first_differing_frame=next((j+1 for j,(b,n) in enumerate(zip(current,parent)) if b!=n),None),differing_frames=sum(b!=n for b,n in zip(current,parent)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(control)),indent=2)+'\n')
  actual=control
 if a.faceoff_dots_reference:
  control=replay(a.faceoff_dots_reference,p/'faceoff-dots-r3-control');current=json.loads(actual.read_text());parent=json.loads(control.read_text());assert len(current)==len(parent)==600
  assert current[-1]['clock']<current[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in current),('invalid native Faceoff Dots Off scene',i)
  (p/'faceoff-dots-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==control.read_bytes(),first_differing_frame=next((j+1 for j,(b,n) in enumerate(zip(current,parent)) if b!=n),None),differing_frames=sum(b!=n for b,n in zip(current,parent)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(control)),indent=2)+'\n')
  actual=control
 if a.shot_plan_reference:
  control=replay(a.shot_plan_reference,p/'shot-plan-r2-control');current=json.loads(actual.read_text());parent=json.loads(control.read_text());assert len(current)==len(parent)==600
  assert current[-1]['clock']<current[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in current),('invalid native plan-Off scene',i)
  (p/'shot-plan-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==control.read_bytes(),first_differing_frame=next((j+1 for j,(b,n) in enumerate(zip(current,parent)) if b!=n),None),differing_frames=sum(b!=n for b,n in zip(current,parent)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(control)),indent=2)+'\n')
  actual=control
 if a.strict_so_reference:
  control=replay(a.strict_so_reference,p/'strict-so-Nov1-control');current=json.loads(actual.read_text());parent=json.loads(control.read_text());assert len(current)==len(parent)==600
  assert actual.read_bytes()==control.read_bytes(),('optional OT SO dispatch changed an ordinary scene',i)
  (p/'strict-so-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=True,differing_frames=0,current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(control)),indent=2)+'\n')
  actual=control
 if a.alt_goalies_reference:
  control=replay(a.alt_goalies_reference,p/'alt-goalies-r11-control');current=json.loads(actual.read_text());parent=json.loads(control.read_text());assert len(current)==len(parent)==600
  assert current[-1]['clock']<current[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in current),('invalid native alternate keeper Off scene',i)
  (p/'alt-goalies-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==control.read_bytes(),first_differing_frame=next((j+1 for j,(b,n) in enumerate(zip(current,parent)) if b!=n),None),differing_frames=sum(b!=n for b,n in zip(current,parent)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(control)),indent=2)+'\n')
  actual=control
 if a.pickup_delay_reference:
  control=replay(a.pickup_delay_reference,p/'pickup-delay-r10-control');current=json.loads(actual.read_text());parent=json.loads(control.read_text());assert len(current)==len(parent)==600
  assert current[-1]['clock']<current[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in current),('invalid native pickup-delay current scene',i)
  (p/'pickup-delay-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==control.read_bytes(),first_differing_frame=next((j+1 for j,(b,n) in enumerate(zip(current,parent)) if b!=n),None),differing_frames=sum(b!=n for b,n in zip(current,parent)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(control)),indent=2)+'\n')
  actual=control
 if a.charge_reference:
  control=replay(a.charge_reference,p/'charge-r9-control');current=json.loads(actual.read_text());parent=json.loads(control.read_text());assert len(current)==len(parent)==600
  assert current[-1]['clock']<current[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in current),('invalid native charge/colors current scene',i)
  (p/'charge-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==control.read_bytes(),first_differing_frame=next((j+1 for j,(b,n) in enumerate(zip(current,parent)) if b!=n),None),differing_frames=sum(b!=n for b,n in zip(current,parent)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(control)),indent=2)+'\n')
  actual=control
 if a.easy_reference:
  control=replay(a.easy_reference,p/'easy-r8-control');current=json.loads(actual.read_text());parent=json.loads(control.read_text());assert len(current)==len(parent)==600
  assert current[-1]['clock']<current[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in current),('invalid native Easy/colors current scene',i)
  (p/'easy-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==control.read_bytes(),first_differing_frame=next((j+1 for j,(b,n) in enumerate(zip(current,parent)) if b!=n),None),differing_frames=sum(b!=n for b,n in zip(current,parent)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(control)),indent=2)+'\n')
  actual=control
 if a.penalty_rate_reference:
  rate_control=replay(a.penalty_rate_reference,p/'directional-r7-control');current=json.loads(actual.read_text());parent=json.loads(rate_control.read_text());assert len(current)==len(parent)==600
  assert current[-1]['clock']<current[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in current),('invalid native current penalty-rate-default scene',i)
  (p/'penalty-rate-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==rate_control.read_bytes(),first_differing_frame=next((j+1 for j,(b,n) in enumerate(zip(current,parent)) if b!=n),None),differing_frames=sum(b!=n for b,n in zip(current,parent)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(rate_control)),indent=2)+'\n')
  actual=rate_control
 if a.directional_reference:
  directional_control=replay(a.directional_reference,p/'pickup-r6-control');current=json.loads(actual.read_text());parent=json.loads(directional_control.read_text());assert len(current)==len(parent)==600
  assert current[-1]['clock']<current[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in current),('invalid native current Directional-default scene',i)
  (p/'directional-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==directional_control.read_bytes(),first_differing_frame=next((j+1 for j,(b,n) in enumerate(zip(current,parent)) if b!=n),None),differing_frames=sum(b!=n for b,n in zip(current,parent)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(directional_control)),indent=2)+'\n')
  actual=directional_control
 if a.pickup_reference:
  pickup_control=replay(a.pickup_reference,p/'speed-r5-control');candidate_rows=json.loads(actual.read_text());pickup_rows=json.loads(pickup_control.read_text());assert len(candidate_rows)==len(pickup_rows)==600
  assert candidate_rows[-1]['clock']<candidate_rows[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in candidate_rows),('invalid native current gameplay',i)
  (p/'pickup-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==pickup_control.read_bytes(),first_differing_frame=next((j+1 for j,(x,y) in enumerate(zip(candidate_rows,pickup_rows)) if x!=y),None),differing_frames=sum(x!=y for x,y in zip(candidate_rows,pickup_rows)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(pickup_control)),indent=2)+'\n')
  actual=pickup_control
 if a.speed_reference:
  speed_control=replay(a.speed_reference,p/'height-r4-control');candidate_rows=json.loads(actual.read_text());speed_rows=json.loads(speed_control.read_text());assert len(candidate_rows)==len(speed_rows)==600
  assert candidate_rows[-1]['clock']<candidate_rows[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in candidate_rows),('invalid native current gameplay',i)
  (p/'speed-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==speed_control.read_bytes(),first_differing_frame=next((j+1 for j,(x,y) in enumerate(zip(candidate_rows,speed_rows)) if x!=y),None),differing_frames=sum(x!=y for x,y in zip(candidate_rows,speed_rows)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(speed_control)),indent=2)+'\n')
  actual=speed_control
 if a.height_reference:
  height_control=replay(a.height_reference,p/'receiver-r3-control');candidate_rows=json.loads(actual.read_text());height_rows=json.loads(height_control.read_text());assert len(candidate_rows)==len(height_rows)==600
  assert candidate_rows[-1]['clock']<candidate_rows[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in candidate_rows),('invalid native current gameplay',i)
  (p/'height-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==height_control.read_bytes(),first_differing_frame=next((j+1 for j,(x,y) in enumerate(zip(candidate_rows,height_rows)) if x!=y),None),differing_frames=sum(x!=y for x,y in zip(candidate_rows,height_rows)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(height_control)),indent=2)+'\n')
  actual=height_control
 if a.receiver_reference:
  receiver_control=replay(a.receiver_reference,p/'shootout-r2-control');candidate_rows=json.loads(actual.read_text());receiver_rows=json.loads(receiver_control.read_text());assert len(candidate_rows)==len(receiver_rows)==600
  assert candidate_rows[-1]['clock']<candidate_rows[0]['clock'] and all((x['owner']<12 or x['owner']>=0x8000) and len(x['positions'])==12 and all(-400<=q[1]<=400 for q in x['positions']) for x in candidate_rows),('invalid native current gameplay',i)
  (p/'receiver-comparison.json').write_text(json.dumps(dict(case=i,raw_exact=actual.read_bytes()==receiver_control.read_bytes(),first_differing_frame=next((j+1 for j,(x,y) in enumerate(zip(candidate_rows,receiver_rows)) if x!=y),None),differing_frames=sum(x!=y for x,y in zip(candidate_rows,receiver_rows)),current_trajectory_sha256=sha(actual),reference_trajectory_sha256=sha(receiver_control)),indent=2)+'\n')
  actual=receiver_control
 if a.shootout_reference:
  shootout_control=replay(a.shootout_reference,p/'net31-control');assert actual.read_bytes()==shootout_control.read_bytes(),('shootout rules changed ordinary gameplay',i)
  actual=shootout_control
 if a.net_reference:
  net_control=replay(a.net_reference,p/'r13-control')
  candidate=actual;candidate_rows=json.loads(candidate.read_text());reference_rows=json.loads(net_control.read_text());candidate_net=json.loads((candidate.parent/'net_contact_trace.json').read_text());reference_net=json.loads((net_control.parent/'net_contact_trace.json').read_text())
  net_audit=qualify_net_change(reference_rows,candidate_rows,reference_net,candidate_net)
  net_audit.update(case=i,candidate_trajectory_sha256=sha(candidate),reference_trajectory_sha256=sha(net_control))
  (p/'net-impact-audit.json').write_text(json.dumps(net_audit,indent=2)+'\n')
  # Retain the complete strict historical comparisons on a freshly replayed r13.
  # The new candidate is independently checked up to a physically verified impact.
  actual=net_control
 if a.manual_reference:
  manual_control=replay(a.manual_reference,p/'r12-control');assert actual.read_bytes()==manual_control.read_bytes(),('manual keeper input correction changed ordinary no-input gameplay',i)
 if a.seven_reference:
  seven_control=replay(a.seven_reference,p/'r11-control');assert actual.read_bytes()==seven_control.read_bytes(),('Mini seven count changed ordinary active gameplay',i)
 if a.penalty_reference:
  penalty_control=replay(a.penalty_reference,p/'r10-control');assert actual.read_bytes()==penalty_control.read_bytes(),('penalty ownership changed raw nonpenalty gameplay',i)
 if a.contact_reference:
  contact_control=replay(a.contact_reference,p/'r9-control');assert actual.read_bytes()==contact_control.read_bytes(),('human contact changed raw no-input gameplay',i)
 if a.mini_reference:
  mini_control=replay(a.mini_reference,p/'r8-control');assert actual.read_bytes()==mini_control.read_bytes(),('Mini scheduling changed raw active gameplay',i)
 rr=json.loads(actual.read_text());assert len(rr)==600 and rr[-1]['clock']<rr[0]['clock']
 exact=actual.read_bytes()==expected.read_bytes()
 if a.keeper_reference:
  control=replay(a.keeper_reference,p/'r2-control');assert control.read_bytes()==expected.read_bytes(),('r2 control no longer reproduces immutable original scene',i)
 else:assert exact,(i,specs[i],'No-B native gameplay changed from selected38image')
 if a.outlet_reference:
  outlet_control=replay(a.outlet_reference,p/'r3-control')
  if not a.menu_reference:assert actual.read_bytes()==outlet_control.read_bytes(),('No-B gameplay changed by input-only correction',i)
 if a.menu_reference:
  menu_control=replay(a.menu_reference,p/'r4-control')
  if not a.control_reference:assert actual.read_bytes()==menu_control.read_bytes()==outlet_control.read_bytes(),('Default Icing On altered native no-B trajectory',i)
 if a.icing_reference:
  icing_control=replay(a.icing_reference,p/'r6-control')
  rules_control=replay(a.rules_reference,p/'r7-control') if a.rules_reference else actual
  assert rules_control.read_bytes()==icing_control.read_bytes(),('default-only r7 change altered raw r6 gameplay',i)
 phase_samples=[]
 if a.control_reference:
  catch_control=replay(a.control_reference,p/'r5-control')
  assert catch_control.read_bytes()==menu_control.read_bytes()==outlet_control.read_bytes(),('fresh pre-catch controls disagree',i)
  prior=json.loads(catch_control.read_text())
  for frame,(before,now) in enumerate(zip(prior,rr)):
   if before==now:continue
   # Video-boundary samples can interrupt a native object update, prediction
   # cache refresh or sprite-list build. Never align/reorder actual actions:
   # both entire neighbouring rows and every other field must remain exact.
   keys=[k for k in before if before[k]!=now[k]]
   isolated=0<frame<len(rr)-1 and prior[frame-1]==rr[frame-1] and prior[frame+1]==rr[frame+1]
   item=dict(frame=frame+1,changed_fields=keys,whole_rows_exact_on_both_neighbours=isolated)
   errors=[]
   if not isolated:errors.append('whole rows do not rejoin on both neighbours')
   if keys==['positions']:
    delta=[(actor,axis,b,n) for actor,(bp,np) in enumerate(zip(before['positions'],now['positions'])) for axis,(b,n) in enumerate(zip(bp,np)) if b!=n]
    if len({a for a,x,b,n in delta})!=1:errors.append('more than one actor position differs')
    if not isolated or not all(n in [prior[frame-1]['positions'][actor][axis],prior[frame+1]['positions'][actor][axis]] for actor,axis,b,n in delta):errors.append('position is not an adjacent native observation')
    item['coordinates']=[dict(actor=actor,axis=axis,control=b,current=n) for actor,axis,b,n in delta]
   elif keys in (['shot_clock'],['sprite_bytes']):
    # Historical observer's shot_clock is BEEC/puckcross6 (goal-line crossing
    # prediction), not the match clock. sprite_bytes is the render-list cursor.
    key=keys[0];values=[prior[j][key] for j in range(max(0,frame-1),min(len(rr),frame+2))];value=now[key]
    if key=='shot_clock':values=[v-65536 if v&32768 else v for v in values];value=value-65536 if value&32768 else value
    if not min(values)<=value<=max(values):errors.append('derived cache/cursor outside adjacent native observation range')
    item.update(control=before[key],current=now[key],adjacent_control_range=[min(values),max(values)],meaning='puckcross6 goal-line prediction cache' if key=='shot_clock' else 'native sprite-list build cursor')
   else:errors.append('native event, clock, puck, action or control field changed')
   item['errors']=errors;phase_samples.append(item)
  (p/'catch-phase-observations.json').write_text(json.dumps(phase_samples,indent=2)+'\n')
 old=json.loads(expected.read_text());first=next((j for j,(b,n) in enumerate(zip(old,rr)) if b!=n),None)
 return dict(net_contact_audit=net_audit if a.net_reference else None,case=i,spec=specs[i],frames=600,trajectory_sha256=sha(actual),original_trajectory_sha256=sha(expected),exact=exact,first_differing_frame=first,keeper_change_scope=bool(a.keeper_reference),fresh_r2_control_exact=True if a.keeper_reference else None,fresh_r3_input_control_exact=True if a.outlet_reference else None,current_raw_exact_to_r5=(not phase_samples) if a.control_reference else None,video_boundary_observations=phase_samples)
with ThreadPoolExecutor(max_workers=3) as pool:cases=list(pool.map(run,range(40)))
(o/'all40-observation-audit.json').write_text(json.dumps(cases,indent=2)+'\n')
if a.control_reference:assert all(not sample['errors'] for case in cases for sample in case['video_boundary_observations']),('native no-B comparison failed; all40 cases retained',[(c['case'],v) for c in cases for v in c['video_boundary_observations'] if v['errors']])
result=dict(rom_sha256=sha(a.rom),reference_ROM_sha256=report['rom_sha256'],reference_report_sha256=sha(ref.parent/'qa_report.json'),state_sha256=sha(a.state),all40_original_no_B_contexts_exact=all(c['exact'] for c in cases),current_contexts_executed=40,current_frame_samples=24000,cases=cases)
if a.keeper_reference:result.update(scope='Authorized keeper behavior change: guarded keeper-only binary diff; all40 freshly repeated r2 controls reproduce original traces; all40 current traces recorded. Different current trajectories are expected and are not counted as unchanged or as fresh strength games.',keeper_reference_sha256=sha(a.keeper_reference))
if a.outlet_reference:result.update(scope='Retained keeper correction separately guarded versus exact r2. Input-only correction separately guarded versus exact r3; all40 current scenes match40 fresh r3 controls exactly. All40 fresh r2 controls still reproduce immutable original traces.',outlet_reference_sha256=sha(a.outlet_reference),all40_current_no_B_contexts_exact_to_r3=True)
if a.menu_reference:result.update(menu_reference_sha256=sha(a.menu_reference),all40_current_default_icing_on_contexts_exact_to_fresh_r4=True,scope='Declared r5 menu/settings and optional touch-icing award only. All40 current Icing On scenes match40 fresh r4 and40 fresh r3 controls; all40 fresh r2 controls reproduce immutable original traces. No new strength matches claimed.')
if a.control_reference:result.pop('all40_current_no_B_contexts_exact_to_r3',None);result.pop('all40_current_default_icing_on_contexts_exact_to_fresh_r4',None)
if a.control_reference:result.update(control_reference_sha256=sha(a.control_reference),current_raw_exact_to_r5_contexts=sum(c['current_raw_exact_to_r5'] for c in cases),video_boundary_observation_count=sum(len(c['video_boundary_observations']) for c in cases),all40_native_event_clock_puck_action_timelines_exact=True,scope='Declared cooperative catch handoff/current-skater outlet and boot defaults. Fresh r5/r4/r3 controls agree exactly; fresh r2 controls reproduce original traces. Every current event/match-clock/puck/action/control field is exact. Isolated one-actor position, prediction-cache or render-cursor observations are separately recorded only within adjacent native observation bounds and with both neighbouring complete rows exact. These are consistent with video sampling during native updates, not claimed byte-exact. No strength games claimed.')
if a.icing_reference and not a.rules_reference:result.update(icing_reference_sha256=sha(a.icing_reference),all40_current_raw_contexts_exact_to_fresh_r6=True,icing_scope='Only three default immediates change; all40 current raw traces match fresh r6 controls exactly. Retained comparisons to r5 and older keeper scopes are separately disclosed.')
(o/'results.json').write_text(json.dumps(result,indent=2)+'\n');print('PASS 40 current no-B scenes and',('40 fresh exact r2 controls with declared keeper-only scope' if a.keeper_reference else '24000 original byte-exact frame samples'))

if a.rules_reference:
 result.update(rules_reference_sha256=sha(a.rules_reference),r7_controls_raw_exact_to_fresh_r6=True,current_raw_exact_to_r7=sum((o/str(i)/('r13-control/trajectory.json' if a.net_reference else 'current/trajectory.json')).read_bytes()==(o/str(i)/'r7-control/trajectory.json').read_bytes() for i in range(40)),rules_scope='Only overtime and momentum modules change. Existing isolated video-boundary bounds retained; actual actions, puck and match-clock remain strict.')
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.mini_reference:
 result.update(mini_reference_sha256=sha(a.mini_reference),all40_current_raw_contexts_exact_to_fresh_r8=True,mini_scope='Divisional Mini schedule/menu/round bounds and season symbol rebinding only. All40 current active-game raw traces match fresh r8 controls exactly; no strength games claimed.')
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.contact_reference:
 result.update(contact_reference_sha256=sha(a.contact_reference),all40_current_raw_contexts_exact_to_fresh_r9=True,human_contact_scope='Only human buffered release/contact animation/pending input and fresh-owned-C dispatch change. All40 current raw active-game traces match fresh r9 controls exactly.')
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.penalty_reference:
 result.update(penalty_reference_sha256=sha(a.penalty_reference),all40_current_raw_contexts_exact_to_fresh_r10=True,penalty_owner_scope='Only accepted native breakaway-penalty ownership capture and penalty-shot controller setup change. All40 current raw ordinary-game traces match40 fresh r10 controls exactly. No new strength series.')
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.seven_reference:
 result.update(seven_reference_sha256=sha(a.seven_reference),all40_current_raw_contexts_exact_to_fresh_r11=True,mini_seven_scope='Only Mini count/new-slot/menu/schedule modules change. All40 current raw ordinary-game traces exactly match40 fresh r11 controls. No new strength series.')
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.manual_reference:
 result.update(all40_current_raw_contexts_exact_to_fresh_r12=True,manual_reference_sha256=sha(a.manual_reference))
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.net_reference:
 # No historical baseline-only success is relabelled as a current raw-exact claim.
 reference_audit=dict(result,rom_sha256=sha(a.net_reference),scope='Fresh exact r13 reference retains the entire strict historical comparison chain; these are reference results, not candidate raw-exact claims.');audits=[c['net_contact_audit'] for c in cases];changed=[c for c in audits if c['verified_impact']]
 assert changed,'the release must exercise the actual changed net-contact behavior'
 # Deliberate negative controls prove that arbitrary pre-impact drift is rejected.
 from copy import deepcopy
 first=changed[0]['case'];base=o/str(first);b=json.loads((base/'r13-control/trajectory.json').read_text());n=json.loads((base/('shootout-r2-control/trajectory.json' if a.receiver_reference else 'current/trajectory.json')).read_text());bn=json.loads((base/'r13-control/net_contact_trace.json').read_text());nn=json.loads((base/('shootout-r2-control/net_contact_trace.json' if a.receiver_reference else 'current/net_contact_trace.json')).read_text());bad=deepcopy(n);bad[0]['score'][0]+=1
 rejected=[]
 for label,nb,bb,nnn in [('pre-impact score drift',bad,bn,nn),('unrelated drift with no net change',bad,bn,bn)]:
  try:qualify_net_change(b,nb,bb,nnn)
  except AssertionError:rejected.append(label)
  else:raise AssertionError('net audit accepted '+label)
 bad_net=deepcopy(bn);frame=changed[0]['verified_impact']['frame']-1;idx=changed[0]['verified_impact']['nets'][0]['net'];bad_net[frame]['nets'][idx]['velocity']=[5000,0]
 try:qualify_net_change(b,n,bad_net,nn)
 except AssertionError:rejected.append('impact outside threshold band')
 else:raise AssertionError('net audit accepted out-of-band impact')
 for label,delta in [('unphysical net jump',100),('net movement opposite impulse',-1 if bn[frame]['nets'][idx]['velocity'][0]>0 else 1)]:
  malformed=deepcopy(bn);malformed[frame]['nets'][idx]['pos'][0]+=delta
  try:qualify_net_change(b,n,malformed,nn)
  except AssertionError:rejected.append(label)
  else:raise AssertionError('net audit accepted '+label)
 result=dict(rom_sha256=sha(a.rom),net_reference_sha256=sha(a.net_reference),scope='Only four native net-release threshold bytes change. Fresh r13 controls retain the entire strict historical comparison chain. Every candidate scene must remain exactly equal until its first verified below-new-threshold native net release; changed post-impact trajectories are recorded and are not counted as unchanged.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in audits),verified_net_impact_contexts=len(changed),all40_current_contexts_exact_or_verified_native_net_impact=True,negative_audit_controls_rejected=rejected,cases=audits,r13_reference_audit=reference_audit)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.shootout_reference:
 net_audit=dict(result,rom_sha256=sha(a.shootout_reference),scope='Retained net feature: exact2026-10-31 parent versus freshly replayed r13; all original historical comparisons retained.')
 result=dict(rom_sha256=sha(a.rom),shootout_reference_sha256=sha(a.shootout_reference),scope='Attempt progress watcher and automatic native countdown only. All40 current ordinary-game raw trajectories exactly equal40 freshly replayed2026-10-31 parent controls. Earlier net-release differences versus r13 are independently qualified below.',current_contexts_executed=40,current_raw_exact_contexts=40,all40_current_raw_contexts_exact_to_fresh_net31=True,net_parent_audit=net_audit)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.receiver_reference:
 retained=dict(result,rom_sha256=sha(a.receiver_reference),scope='Fresh exact shootout-r2 controls retain every previous strict ordinary/net/shootout comparison. These are parent-reference results, not current raw-exact claims.')
 comparisons=[json.loads((o/str(i)/'receiver-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),receiver_reference_sha256=sha(a.receiver_reference),scope='Only two pass eligibility sites and the existing actual stick-contact gate change. No new general frame/animation hook, RAM or RNG writes. Every current native600-frame scene is recorded against a fresh exact parent; posture corrections and added instruction timing may change later native HV-based decisions. Different trajectories are disclosed, not labelled unchanged or a strength qualification. Paired native healthy/downed/keeper/ABI tests separately qualify guard behavior.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.height_reference:
 retained=dict(result,rom_sha256=sha(a.height_reference),scope='Fresh exact receiver-r3 controls retain the full earlier strict comparison chain and disclosed receiver timing differences. These are parent-reference results, not current raw-exact claims.')
 comparisons=[json.loads((o/str(i)/'height-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),height_reference_sha256=sha(a.height_reference),scope='Targeted B-pass lift and optional persisted/locked menu setting only. Default Normal native arithmetic is paired separately, including registers/CCR/stack/fraction. Added dispatch instructions can shift HV-counter timing; every native600-frame scene and divergence is retained. No unchanged trajectories, completion-rate or Hard-strength claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.speed_reference:
 retained=dict(result,rom_sha256=sha(a.speed_reference),scope='Fresh exact height-r4 controls retain every previous strict comparison and declared height/receiver timing difference. These are parent-reference results, not current raw-exact claims.')
 comparisons=[json.loads((o/str(i)/'speed-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),speed_reference_sha256=sha(a.speed_reference),scope='Targeted B-pass timing and persisted/locked independent menu setting, with standalone record moved out of Full goalie data. Normal full native ABI/arithmetic is separately paired. Added dispatch changes HV-counter timing; all600-frame scenes and divergences retained. No unchanged-gameplay, completion-rate or Hard-strength claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.pickup_reference:
 retained=dict(result,rom_sha256=sha(a.pickup_reference),scope='Fresh exact speed-r5 controls retain the entire previous strict comparison chain and declared timing differences. These are parent results, not current exact-gameplay claims.')
 comparisons=[json.loads((o/str(i)/'pickup-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),pickup_reference_sha256=sha(a.pickup_reference),scope='Accepted unassigned co-op skater pickup arbitration only. No new RAM, general input hook, forced pickup or physics/rating change. Multi-human pickups deliberately consume one native RNG draw and choose an eligible physical pad. Added fallback instructions can change native HV timing even in single-human scenes; all600-frame current and fresh-parent scenes and every divergence are retained. No strength or unchanged-gameplay claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.directional_reference:
 retained=dict(result,rom_sha256=sha(a.directional_reference),scope='Fresh exact pickup-r6 controls retain every earlier strict comparison and declared timing difference. These are parent results, not current unchanged-gameplay claims.')
 comparisons=[json.loads((o/str(i)/'directional-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),directional_reference_sha256=sha(a.directional_reference),scope='Optional human free-direction B passes, vector receiver cone and saved/locked settings. Default Assisted/Default and CPU arithmetic are separately paired with complete native ABI. Extra dispatch timing may change native HV-counter decisions even at defaults; all40current600-frame scenes and every divergence are retained with fresh exactr6parents. No unchanged trajectories, strength or pass-completion claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.penalty_rate_reference:
 retained=dict(result,rom_sha256=sha(a.penalty_rate_reference),scope='Fresh exactr7 controls retain every earlier strict comparison and declared timing difference. These are parent results, not current unchanged-gameplay claims.')
 comparisons=[json.loads((o/str(i)/'penalty-rate-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),penalty_rate_reference_sha256=sha(a.penalty_rate_reference),scope='Separate saved/locked penalty frequency.100% native event output/ABI and no filter RNG are paired separately. Added admission instructions can alter HV-based decisions after a native high event; all40current600-frame scenes and every difference retained. No unchanged universal trajectories or Hard-strength claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.easy_reference:
 retained=dict(result,rom_sha256=sha(a.easy_reference),scope='Fresh exact r8 controls retain the complete prior comparison chain.')
 comparisons=[json.loads((o/str(i)/'easy-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),easy_reference_sha256=sha(a.easy_reference),scope='Easy skills/energy change intentionally; Normal/Hard native value/ABI controls are paired separately. Added rendering/energy guards can change native HV timing. All current600-frame scenes and every difference from fresh r8 controls retained; no Hard strength search or universal unchanged-gameplay claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.charge_reference:
 retained=dict(result,rom_sha256=sha(a.charge_reference),scope='Fresh exact r9 controls retain the complete prior comparison chain and all recorded r8-and-earlier differences. These are parent results, not current raw-exact claims.')
 comparisons=[json.loads((o/str(i)/'charge-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),charge_reference_sha256=sha(a.charge_reference),scope='Optional human hold/release B power and static physical-star/goal palette repair. Shared CPU native pass/solver/energy code is byte-exact; every actual current600-frame scene is compared with a freshly replayed exact r9 parent and every difference is retained. Parent r9/r8/earlier comparisons remain independent. No new Hard strength search or universal unchanged-gameplay claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.pickup_delay_reference:
 retained=dict(result,rom_sha256=sha(a.pickup_delay_reference),scope='Fresh exact r10 controls retain the entire r9-and-earlier chain independently.')
 comparisons=[json.loads((o/str(i)/'pickup-delay-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),pickup_delay_reference_sha256=sha(a.pickup_delay_reference),scope='Optional human B release sets a minimum6native updates of skater contact cooldown. Off is the default. Native CPU pass, collision, countdown, physics, keeper and rendering code retain their bytes. Added helper dispatch can change HV-counter timing; all40ordinary600frame scenes are freshly compared with exactr10 and every difference retained. No unchanged universal trajectories or Hard strength claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.alt_goalies_reference:
 retained=dict(result,rom_sha256=sha(a.alt_goalies_reference),scope='Fresh exact r11 controls retain the r10-and-earlier chain independently.')
 comparisons=[json.loads((o/str(i)/'alt-goalies-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),alt_goalies_reference_sha256=sha(a.alt_goalies_reference),scope='Optional Alt Goalies Off by default. Added dispatch may change native HV timing. All40 ordinary600frame scenes compared with exactr11; every difference retained. No universal identical trajectory or Hard strength claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
if a.strict_so_reference:
 retained=dict(result,rom_sha256=sha(a.strict_so_reference),scope='Fresh exact Nov1 controls retain the complete earlier comparison chain independently.')
 comparisons=[json.loads((o/str(i)/'strict-so-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),strict_so_reference_sha256=sha(a.strict_so_reference),scope='Optional OT SO Rules Off by default, only tied-overtime extension. No normal-frame hook. All40 ordinary600frame scenes required raw-exact to fresh Nov1; entire earlier difference chain retained. No Hard strength claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
if a.shot_plan_reference:
 retained=dict(result,rom_sha256=sha(a.shot_plan_reference),scope='Fresh exact Nov1r2 controls retain the complete earlier comparison chain independently, including40raw-exact Strict-vs-Nov1 scenes.')
 comparisons=[json.loads((o/str(i)/'shot-plan-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),shot_plan_reference_sha256=sha(a.shot_plan_reference),scope='Optional Hard AI Shot Plan Off by default. Extra dispatch may change native HV timing. Every current600frame scene compared with fresh exactr2; every difference and previous comparison retained. No universal identical-gameplay or strength claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
if a.faceoff_dots_reference:
 retained=dict(result,rom_sha256=sha(a.faceoff_dots_reference),scope='Fresh exact Nov1r3 controls retain the complete earlier comparison chain independently.')
 comparisons=[json.loads((o/str(i)/'faceoff-dots-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),faceoff_dots_reference_sha256=sha(a.faceoff_dots_reference),scope='Optional Faceoff Dots Off by default. Only stoppage-point/menu/save dispatch changes. Every current600frame scene compared with fresh exactr3; every difference and previous comparison retained. No universal identical-gameplay or strength claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
if a.presentation_reference:
 retained=dict(result,rom_sha256=sha(a.presentation_reference),scope='Fresh exact Nov1r4 controls retain the complete earlier comparison chain independently; previous limitations and raw differences remain reference evidence.')
 comparisons=[json.loads((o/str(i)/'presentation-comparison.json').read_text()) for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),presentation_reference_sha256=sha(a.presentation_reference),scope='Native receiver correction, existing Momentum On/Off and lower-left HUD. Every current600frame scene compared with fresh exactr4; native HV timing may differ. All differences and prior reference comparisons retained. No universal identical-gameplay or Hard strength claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact'] for c in comparisons),cases=comparisons,retained_parent_audit=retained)
if a.quickgame_reference:
 retained=dict(result,rom_sha256=sha(a.quickgame_reference),scope='Fresh exact Nov1r5 controls retain the entire earlier comparison chain, including every prior raw difference and limitation.')
 comparisons=[json.loads((o/str(i)/'quickgame-comparison.json').read_text())for i in range(40)]
 result=dict(rom_sha256=sha(a.rom),quickgame_reference_sha256=sha(a.quickgame_reference),scope='Human-only exhibition menu, native side assignment and season isolation. Ordinary AI/pass/shot/physics/HUD bytes retain exact regions; added input dispatch may change native HV timing. Every current600frame scene and freshR5comparison retained. No universal raw-exact or Hard-strength claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact']for c in comparisons),cases=comparisons,retained_parent_audit=retained)
if a.allstar_reference:
 retained=dict(result,rom_sha256=sha(a.allstar_reference),scope='Fresh exact R6 retains complete R5/R4 and all older comparison chains, every previous difference and limitation.')
 comparisons=[json.loads((o/str(i)/'allstar-comparison.json').read_text())for i in range(40)]
 result=dict(rom_sha256=sha(a.replay_hud_reference or a.rom),allstar_reference_sha256=sha(a.allstar_reference),scope='Conditional best-by-position Allstar records/getters and native human-only exhibition. No new global frame or AI/physics/statistics algorithm hook. Additional getter/menu dispatch may change HV timing. All40 current600frame scenes freshly compared with exactR6; every difference and complete earlier comparison chain retained. No universal trajectory or Hard-strength claim.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact']for c in comparisons),cases=comparisons,retained_parent_audit=retained)
(o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.replay_hud_reference:
 retained=result;comparisons=[json.loads((o/str(i)/'replay-hud-comparison.json').read_text())for i in range(40)];negatives=negative_controls()
 assert all(c['live_exact']for c in comparisons)
 result=dict(rom_sha256=sha(a.rom),replay_hud_reference_sha256=sha(a.replay_hud_reference),scope='All40 fresh declared AutoReplayOff pairs are raw-exact for600native frames. Original AutoReplayOn traces retain strict live equality; only partially committed position/puck components inside the byte-exact native decoder may differ, proven against identical actual packed records and calibrated native PC/GPR commit phases. All other fields stay exact. Every raw difference and older comparison chain retained; no timing padding or outcomes forced.',current_contexts_executed=40,current_raw_exact_contexts=sum(c['raw_exact']for c in comparisons),current_live_exact_contexts=40,current_replay_off_raw_exact_contexts=40,native_state_ABI=decoder_abi,comparison_negative_controls=negatives,cases=comparisons,retained_parent_audit=retained)
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.transfers_reference:
 transfer_cases=[json.loads((o/str(i)/'transfers-comparison.json').read_text())for i in range(40)]
 retained_replay=dict(result,rom_sha256=sha(a.transfers_reference),scope='Fresh historical Nov2 replay repair against R7; historical live/raw assertions refer only to this explicit reference, not to current transfer paths.')
 result=dict(rom_sha256=sha(a.refinements_reference or a.rom),retained_parent_audit=retained_replay,scope='Preseason transfers: all actual AutoOn/AutoOff comparisons and differences retained; fresh historical replay/older chains separately bound to their exact reference images.')
 result.update(transfers_reference_sha256=sha(a.transfers_reference),actual_current_transfer_contexts=40,actual_current_transfer_frame_samples=48000,transfer_comparisons=transfer_cases,transfer_raw_exact_AutoOn=sum(c['actual_current_comparisons'][0]['raw_exact']for c in transfer_cases),transfer_raw_exact_AutoOff=sum(c['actual_current_comparisons'][1]['raw_exact']for c in transfer_cases),transfers_scope='New roster Off paths change native CPU timing. Every current AutoOn/AutoOff difference retained; not claimed unchanged. Original replay repair contract independently freshly rechecked on exact Nov2 against R7, including40 strict raw-exact AutoOff pairs and10 active negatives. Current native Off getter semantics and full register/status/IRQ/SP/SRAM contracts require the new transfer runtime group. No Hard strength or physical USB claim.')
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')

if a.refinements_reference:
 refinement_cases=[json.loads((o/str(i)/'refinements-comparison.json').read_text())for i in range(40)]
 assert all(c['current_rom_sha256']==sha(a.rom)and c['parent_rom_sha256']==sha(a.refinements_reference)for c in refinement_cases)
 retained=result
 result=dict(rom_sha256=sha(a.rom),refinements_reference_sha256=sha(a.refinements_reference),
  retained_parent_audit=retained,actual_current_contexts=40,actual_current_frame_samples=48000,
  raw_exact_AutoOn=sum(c['actual_current_comparisons'][0]['raw_exact']for c in refinement_cases),
  raw_exact_AutoOff=sum(c['actual_current_comparisons'][1]['raw_exact']for c in refinement_cases),
  cases=refinement_cases,scope='Requested current presentation/defaults and Allstar CPU policy: every real AutoOn/AutoOff sample and difference retained. The entire historical transfer/replay comparison chain executes freshly on its own exact images. Current ABI, native inputs, visible HUD and screenshots are separate required checks. No universal trajectory equality or Hard strength claim.')
 (o/'results.json').write_text(json.dumps(result,indent=2)+'\n')
