Iterates through various input combinations to minimize crystal loss when touching an enemy, while also maximizing horizontal distance gain.
Used heavily for this submission.
--change mode value below to maximize one of the following scenarios:
--1 for rightwards gain, 2 for rightwards gain on a slippery surface, 3 for leftwards gain, 4 for leftwards gain on a slippery surface
mode = 1
if mode == 1 then
function press1() joypad.set({["Right"]=true, ["B"]=true}) end
function press2() joypad.set({["Right"]=true, ["B"]=true}) end
elseif mode == 2 then
function press1() joypad.set({["Right"]=true, ["B"]=true}) end
function press2() joypad.set({["Left"]=true, ["B"]=true}) end
elseif mode == 3 then
function press1() joypad.set({["Left"]=true, ["B"]=true}) end
function press2() joypad.set({["Left"]=true, ["B"]=true}) end
elseif mode == 4 then
function press1() joypad.set({["Left"]=true, ["B"]=true}) end
function press2() joypad.set({["Right"]=true, ["B"]=true}) end
end
start = emu.framecount()
framefin = start + 30
xbest1 = 0
xbest2 = 0
xbest3 = 0
xbest = 0
savestate.saveslot(1)
savestate.saveslot(3)
crystalbest = 0
function input()
change1 = 0
change2 = 0
change3 = 0
for k=1,30,1 do
press1()
emu.frameadvance()
crystals = mainmemory.read_u8(0x00AD)
x = mainmemory.read_u16_le(0x0D40)
if emu.framecount() == framefin - 2
then
if (crystals > crystalbest)
then
crystalbest = crystals
xbest = x
xbest1 = 0
xbest2 = 0
xbest3 = 0
savestate.saveslot(2)
elseif (mode == 1 or mode == 2) and (crystals == crystalbest)
then
if x > xbest1
then
xbest1 = x
change1 = 1
end
elseif (mode == 3 or mode == 4) and (crystals == crystalbest)
then
if x < xbest1
then
xbest1 = x
change1 = 1
end
end
end
if emu.framecount() == framefin - 1 and (crystals == crystalbest)
then
if (mode == 1 or mode == 2)
then
if x > xbest2
then
xbest2 = x
change2 = 1
end
elseif (mode == 3 or mode == 4)
then
if x < xbest2
then
xbest2 = x
change2 = 1
end
end
end
if emu.framecount() == framefin and (crystals == crystalbest)
then
if (mode == 1 or mode == 2)
then
if x > xbest3
then
xbest3 = x
change3 = 1
end
elseif (mode == 3 or mode == 4)
then
if x < xbest3
then
xbest3 = x
change3 = 1
end
end
if change1 + change2 + change3 >= 2
then
xbest = x
savestate.saveslot(2)
end
end
end
savestate.loadslot(3)
end
function scenario()
input()
emu.frameadvance()
input()
emu.frameadvance()
emu.frameadvance()
input()
emu.frameadvance()
emu.frameadvance()
emu.frameadvance()
input()
emu.frameadvance()
emu.frameadvance()
emu.frameadvance()
emu.frameadvance()
input()
emu.frameadvance()
emu.frameadvance()
emu.frameadvance()
emu.frameadvance()
emu.frameadvance()
input()
end
scenario()
savestate.loadslot(1)
emu.frameadvance()
press2()
emu.frameadvance()
savestate.saveslot(3)
scenario()
savestate.loadslot(1)
emu.frameadvance()
emu.frameadvance()
press2()
emu.frameadvance()
savestate.saveslot(3)
scenario()
savestate.loadslot(1)
emu.frameadvance()
press2()
emu.frameadvance()
press2()
emu.frameadvance()
savestate.saveslot(3)
scenario()
savestate.loadslot(1)
emu.frameadvance()
emu.frameadvance()
press2()
emu.frameadvance()
press2()
emu.frameadvance()
savestate.saveslot(3)
scenario()
savestate.loadslot(1)
emu.frameadvance()
press2()
emu.frameadvance()
emu.frameadvance()
press2()
emu.frameadvance()
savestate.saveslot(3)
scenario()
savestate.loadslot(1)
emu.frameadvance()
emu.frameadvance()
press2()
emu.frameadvance()
emu.frameadvance()
press2()
emu.frameadvance()
savestate.saveslot(3)
scenario()
savestate.loadslot(1)
emu.frameadvance()
press2()
emu.frameadvance()
press2()
emu.frameadvance()
press2()
emu.frameadvance()
savestate.saveslot(3)
scenario()
savestate.loadslot(1)
emu.frameadvance()
emu.frameadvance()
press2()
emu.frameadvance()
press2()
emu.frameadvance()
press2()
emu.frameadvance()
savestate.saveslot(3)
scenario()
savestate.loadslot(1)
emu.frameadvance()
press2()
emu.frameadvance()
emu.frameadvance()
press2()
emu.frameadvance()
press2()
emu.frameadvance()
savestate.saveslot(3)
scenario()
savestate.loadslot(1)
emu.frameadvance()
emu.frameadvance()
press2()
emu.frameadvance()
emu.frameadvance()
press2()
emu.frameadvance()
press2()
emu.frameadvance()
savestate.saveslot(3)
scenario()
savestate.loadslot(1)
emu.frameadvance()
press2()
emu.frameadvance()
emu.frameadvance()
press2()
emu.frameadvance()
emu.frameadvance()
press2()
emu.frameadvance()
savestate.saveslot(3)
scenario()
console.log(framefin, xbest, bizstring.hex(crystalbest))
savestate.loadslot(2)
client.pause()