local startaddress = 0x1F35
local endaddress = 0x1FF8
while mainmemory.readbyte(0x1992) == 0 do
-- selecting one of the three possible colours on go 2
local random_count = math.random(1, 3) --for slecting a random colour on go 2
if random_count == 1 then
for i = 1, 2 do
joypad.set({Up=true})
emu.frameadvance()
joypad.set({})
emu.frameadvance()
end
-- set colour
joypad.set({A=true})
emu.frameadvance()
elseif random_count == 2 then
for i = 1, 3 do
joypad.set({Up=true})
emu.frameadvance()
joypad.set({})
emu.frameadvance()
end
-- set colour
joypad.set({A=true})
emu.frameadvance()
else
for i = 1, 5 do
joypad.set({Up=true})
emu.frameadvance()
joypad.set({})
emu.frameadvance()
end
-- set colour
joypad.set({A=true})
emu.frameadvance()
end
-- while loop for goes 3-end
while mainmemory.readbyte(0x1FFD) > 0 do
savestate.saveslot(2)
local random_count = math.random(1, 5) --for slecting a random colour
local prev_color = mainmemory.readbyte(0x1F35)
local prev_coloramt = 0
-- generate a random colour
for i = 1, random_count do
joypad.set({Up=true})
emu.frameadvance()
joypad.set({})
emu.frameadvance()
end
for i = 1, 5 do
emu.frameadvance()
end
-- get amount of pixels for colour that is going to be played
local new_color = mainmemory.readbyte(0x1F2C)
local new_colorprevamt = 0 -- amount of pixels of colour before being played
for i = startaddress, endaddress do
if mainmemory.readbyte(i) == mainmemory.readbyte(0x1F2C) then
new_colorprevamt = new_colorprevamt + 1
end
end
-- set colour
joypad.set({A=true})
emu.frameadvance()
-- skip potential lag frames
for i = 1, 10 do
joypad.set({})
emu.frameadvance()
end
savestate.saveslot(3)
joypad.set({Up=true})
emu.frameadvance()
joypad.set({A=true})
emu.frameadvance()
joypad.set({})
for i = 1, 5 do
emu.frameadvance()
end
local new_coloramt = 0
-- get amount of pixels of selected colour
for i = startaddress, endaddress do
if mainmemory.readbyte(i) == new_color then
new_coloramt = new_coloramt + 1
end
end
print(new_coloramt,new_colorprevamt)
if new_coloramt < new_colorprevamt then
savestate.loadslot(3)
elseif new_coloramt == new_colorprevamt then
savestate.loadslot(2)
print("Retrying")
end
end
savestate.loadslot(1)
end
print("Solution found")
emu.pause()