#!/usr/bin/env python3 """Generate isolated PBS assertions; caller must install and restore explicitly.""" from extract_graphics import ROOT def generate(): out=ROOT/'.tmp/north-fixture';out.mkdir(exist_ok=True,parents=True) (out/'main.pbs').write_text('''import { EnemyFixture } from @zelda1:enemies/octorok; [Init] fn init() -> void { EnemyFixture.run(); } [Frame] fn frame() -> void { EnemyFixture.draw(); } ''') source='''import { Enemies } from @zelda1:enemies/octorok; import { Stage } from @zelda1:stage; import { Link } from @zelda1:link; import { Inventory } from @zelda1:inventory; import { Gfx } from @sdk:gfx; import { Color } from @core:color; declare global results: array = new array(64); declare global cases: int = 0; declare global actor: Octorok = new Octorok(new Rock(0,0,0,0,0),128,141,8,0,0,0,0,0,0,1,0,false,0,0,0,7); declare global bolt: Rock = new Rock(0,0,0,0,0); declare service EnemyFixture { fn check(passed: bool) -> void { results[cases]=if passed { 1 } else { 0 }; cases+=1; } fn run() -> void { Inventory.reset(); Stage.reset(); Link.start_game(); Enemies.reset(); let command=Stage.advance(120,61,8,0,0,false,false); EnemyFixture.check(command==0); command=Stage.advance(120,61,8,0,0,false,true); EnemyFixture.check(command==2); EnemyFixture.check(Stage.scrolling()); for tick: int from 0 until 43 { command=Stage.advance(120,61,8,0,0,false,false); } EnemyFixture.check(Stage.scrolling()); command=Stage.advance(120,61,8,0,0,false,false); EnemyFixture.check(Stage.id()==2); EnemyFixture.check(Stage.position_y()==221); command=Stage.advance(120,221,8,0,0,false,false); EnemyFixture.check(!Stage.controls_locked()); Enemies.update(); let total=Enemies.alive_count(); EnemyFixture.check(total==4); let wall=Stage.enemy_tile(0,0); EnemyFixture.check(wall>=137); let ground=Stage.enemy_tile(16,10); EnemyFixture.check(ground<137); actor.reset(128,141,32); EnemyFixture.check(actor.cloud==44); for tick: int from 0 until 44 { actor.update(0,255); } EnemyFixture.check(actor.cloud==0 && actor.x==128 && actor.y==141); actor.x=144; actor.direction=8; actor.turn=255; for tick: int from 0 until 32 { actor.update(0,255); } EnemyFixture.check(actor.y==125 && actor.x==144); EnemyFixture.check(actor.clock==32); // Force a pending native fire countdown without RNG dependence. actor.shoot=17; actor.update(0,255); let shot_dir=actor.shot_direction(); EnemyFixture.check(actor.shoot==16 && shot_dir!=0); let shot_y=actor.shot_y(); EnemyFixture.check(shot_y==actor.y); // Front-facing ordinary shield blocks a rock; rear contact harms Link. Inventory.reset(); Link.start_game(); bolt.x=120; bolt.y=132; bolt.direction=4; bolt.update(); EnemyFixture.check(bolt.direction!=0 && bolt.bounce==8); let partial=Inventory.read_slot(25); EnemyFixture.check(partial==255); bolt.x=120; bolt.y=150; bolt.direction=8; bolt.update(); partial=Inventory.read_slot(25); EnemyFixture.check(partial==127); EnemyFixture.check(Link.invincibility_remaining()==24); bolt.x=120; bolt.y=150; bolt.direction=8; bolt.update(); partial=Inventory.read_slot(25); EnemyFixture.check(partial==127); // A sword can kill only during fully extended state 2. Inventory.reset(); Link.start_game(); let taken=Inventory.take_sword(1); EnemyFixture.check(taken); Link.update(false,false,false,false,true); let hit=Link.sword_hits(120,125); EnemyFixture.check(!hit); for tick: int from 0 until 5 { Link.draw(); } hit=Link.sword_hits(120,125); EnemyFixture.check(hit); hit=Link.sword_hits(160,125); EnemyFixture.check(!hit); actor.reset(120,125,32); actor.cloud=0; actor.turn=255; actor.direction=8; actor.update(0,255); EnemyFixture.check(actor.hp==0 && actor.dying==18); for tick: int from 0 until 18 { actor.update(0,255); } EnemyFixture.check(actor.dying==0 && actor.hp==0); // Body contact uses the same half-heart damage and original immunity. Inventory.reset(); Link.start_game(); actor.reset(120,141,32); actor.cloud=0; actor.turn=255; actor.update(0,255); partial=Inventory.read_slot(25); EnemyFixture.check(partial==127); actor.update(0,255); partial=Inventory.read_slot(25); EnemyFixture.check(partial==127); // Return south only on explicit directional input. command=Stage.advance(120,221,4,0,0,false,false); EnemyFixture.check(command==0); command=Stage.advance(120,221,4,0,0,true,false); EnemyFixture.check(command==2); for tick: int from 0 until 44 { command=Stage.advance(120,221,4,0,0,false,false); } EnemyFixture.check(Stage.id()==0 && Stage.position_y()==61); } fn draw() -> void { Gfx.clear(Color.rgb(0,0,0)); for i: int from 0 until cases { let verdict=results[i] else 0; let color=if verdict==1 { Color.rgb(0,255,0) } else { Color.rgb(255,0,0) }; Gfx.fill_rect((i%16)*16,(i/16)*16,14,14,color); } } } ''' import re lines=[];counter=0 for line in source.splitlines(): if 'EnemyFixture.check(' in line: for call in re.findall(r'(?:Stage|Link)\.[A-Za-z_]+\(\)',line): name=f'check_local_{counter}';counter+=1 lines.append(f' let {name}={call};');line=line.replace(call,name,1) lines.append(line) (out/'fixture.pbs').write_text('\n'.join(lines)+'\n') print('Generated isolated fixture, 32 assertions; not installed') if __name__=='__main__':generate()