Files

28 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Check route metadata and blue drops against the local native 6502 routine."""
import json,re
from extract_graphics import ROOT
from validate_combat_rom import drop
from nes_object_graphics import P,descriptor
def validate():
route=json.loads((ROOT/'extracted/overworld/northwest/bomb-route.json').read_text())
assert [r['room'] for r in route['route']]==[0x66,0x65,0x64]
assert [r['types'] for r in route['route']]==[[8,7,8,7],[8,7,8,7],[8,9,8,9,8]]
text=(ROOT/'src/loot/data.generated.pbs').read_text();items=list(map(int,re.search(r'drop_table: array<int> = \[([^]]+)\]',text)[1].split(',')));rates=list(map(int,re.search(r'drop_rates: array<int> = \[([^]]+)\]',text)[1].split(',')))
cases=0;bomb_cases=0
for cycle in range(10):
for random in range(256):
got=drop(9,cycle,random,0,0,0);expected=items[20+cycle] if random<rates[2] else -1
assert got==(expected,0,0),(cycle,random,got,expected);cases+=1;bomb_cases+=got[0]==0
# Types 7/8/9 share patterns and H/V flips; color is the native palette row.
for frame in range(6):
red=descriptor(7,frame);blue=descriptor(9,frame);fast=descriptor(8,frame)
for key in ('tiles','attributes','sides','x_separation'):assert red[key]==fast[key]
for key in ('tiles','sides','x_separation'):assert red[key]==blue[key]
assert [a&252 for a in red['attributes']]==[a&252 for a in blue['attributes']]
assert all(a%4==1 for a in blue['attributes'])
report={'native_blue_drop_cases':cases,'mismatches':0,'bomb_cases':bomb_cases,'route':route['route'],'descriptor_frame_cases':6,'scope':'Bounded native descriptor/drop execution; no full-game frame-lockstep claim.'}
(ROOT/'extracted/overworld/northwest/native-validation.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report))
if __name__=='__main__':validate()