"""Push the Emerald boulder normally; verify its exact position from a normal save.""" from nav import * import ast from locate import locate eid=int(sys.argv[1]);assert eid in [42,43] key=sys.argv[2];count=int(sys.argv[3]);label=sys.argv[4];assert key in ['up','down','left','right'] and 1<=count<=40 v=json.loads(subprocess.check_output(['ruby',str(ROOT/'scripts/route_map.rb'),'805','0','0'],stderr=subprocess.DEVNULL));e=v['events'][str(eid)];assert 'pbPushThisBoulder' in str(e['list']);dx,dy={'up':(0,-1),'down':(0,1),'left':(-1,0),'right':(1,0)}[key];x,y=e['x'],e['y'];expected=[x+count*dx,y+count*dy] tree=ast.parse((ROOT/'scripts/nav.py').read_text());fun=next(n for n in tree.body if isinstance(n,ast.FunctionDef)and n.name=='route');ns=dict(ROOT=ROOT,json=json,heapq=heapq,re=re);exec(ast.unparse(fun).replace('graph = {}','jumps = {}; graph = {}').replace('native_jump = terrain(n) == 1','native_jump = False'),ns) vv=json.loads(json.dumps(v));vv['events'].pop(str(eid));g=ns['route'](vv,None,True);cursor=(x,y) for _ in range(count): dest=cursor[0]+dx,cursor[1]+dy;assert (key,dest)in g.get(cursor,[]);cursor=dest m,px,py=locate(805);v['position']=[px,py];walk=route(v,(x-dx,y-dy));seq=[] for direction,group in groupby(walk): n=len(list(group));seq.extend([direction+':.12']*n if n<3 else [direction+':'+str(round(.1*n+.02,3))]) print('FAST PUSH APPROACH',walk,flush=True) if '--to-wall' in sys.argv: assert (key,(expected[0]+dx,expected[1]+dy)) not in g.get(tuple(expected),[]) seq += [key+':'+str(round(.65*count+.5,2))] else: for j in range(count): seq += [key+':.12','wait:.55'] if j