Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local STATE = 'new_attempt'
- local POSITIONS = {}
- local CURRENT_POSITION_ID = 0
- local SAVE = savestate.create()
- local function tohex(num, i)
- return string.format('%0' .. tostring(i) .. 'X', num)
- end
- local function print_results()
- local hits = {}
- for _, position in ipairs(POSITIONS) do
- local i = tohex(position['y'], 4) .. ',' .. tohex(position['x'], 4)
- local coord = hits[i]
- if coord == nil then
- coord = {}
- hits[i] = coord
- end
- table.insert(coord, position['hits'])
- end
- for coord, hits in pairs(hits) do
- local total_hits = 0
- for _, hit in ipairs(hits) do
- total_hits = total_hits + hit
- end
- local avg_hits = total_hits / #hits
- print(coord, avg_hits)
- end
- end
- local function init_positions()
- local lanmo_xs = {0x58, 0x50, 0x60, 0x70, 0x80, 0x90, 0xA0, 0x98}
- local lanmo_ys = {0x68, 0x60, 0x70, 0x80, 0x90, 0xA0, 0xA8, 0xB0}
- local starting_y = 0x0763
- local starting_x = 0x0678
- for dy = -2, 8 do
- local y = starting_y + dy
- for dx = -1, 4 do
- for _, lanmo_x in ipairs(lanmo_xs) do
- for _, lanmo_y in ipairs(lanmo_ys) do
- local x = starting_x + dx
- for framerule = 0, 3 do
- position = {
- ['hits'] = 0,
- ['y'] = y,
- ['x'] = x,
- ['framerule'] = framerule,
- ['lanmo_x'] = lanmo_x,
- ['lanmo_y'] = lanmo_y,
- }
- table.insert(POSITIONS, position)
- end
- end
- end
- end
- end
- end
- local function set_position()
- local position = POSITIONS[CURRENT_POSITION_ID]
- memory.writebyte(0x7E0DA0, position['lanmo_x'])
- memory.writebyte(0x7E0DB0, position['lanmo_y'])
- end
- local function tick()
- local position = POSITIONS[CURRENT_POSITION_ID]
- local frame = emu.framecount()
- local first_shot = frame == 99700
- local second_shot = frame == 99718
- local check_results = frame >= 99768
- if STATE == 'new_attempt' then
- savestate.load(SAVE)
- STATE = 'before_shoot'
- CURRENT_POSITION_ID = CURRENT_POSITION_ID + 1
- position = POSITIONS[CURRENT_POSITION_ID]
- if not position then
- STATE = 'done'
- else
- memory.writeword(0x7E0020, position['y'])
- memory.writeword(0x7E0022, position['x'])
- memory.writebyte(0x7E001A, position['framerule'])
- end
- elseif STATE == 'before_shoot' then
- if first_shot then
- joypad.set(1, {['Y'] = true})
- elseif second_shot then
- joypad.set(1, {['Y'] = true})
- STATE = 'wait_for_results'
- end
- elseif STATE == 'wait_for_results' then
- if check_results then
- local b1_hits = 4 - (memory.readbyteunsigned(0x7E0E50) / 4)
- local b2_hits = 4 - (memory.readbyteunsigned(0x7E0E51) / 4)
- position['hits'] = b1_hits + b2_hits
- STATE = 'new_attempt'
- end
- end
- end
- savestate.save(SAVE)
- emu.registerbefore(tick)
- memory.registerexecute(0x05a411, set_position)
- init_positions()
- while STATE ~= 'done' do
- snes9x.frameadvance()
- gui.text(50, 50, 'attempt ' .. tostring(CURRENT_POSITION_ID) .. '/' .. tostring(#POSITIONS) .. ' ' .. tostring(CURRENT_POSITION_ID / #POSITIONS * 100) .. '%')
- end
- print_results()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement