Rough bot that plays though cement factory for classic. It's far from perfect, but this game is too slow anyways so it won't be done unless someone wants to do a 100%
memory.usememorydomain("Combined WRAM")
local lift = {[1]=0x03C14E,[2]=0x03C152,[3]=0x03C156,[4]=0x03C15A,[5]=0x03C15E,[6]=0x03C162}
local cement = {[1]=0x03C186,[2]=0x03C18A,[3]=0x03C18E,[4]=0x03C192,[5]=0x03C196,[6]=0x03C19A,[7]=0x03C19E,[8]=0x03C1A2,[9]=0x03C1A6,[10]=0x03C1AA,[11]=0x03C1AE,[12]=0x03C1B2}
--local cementX = {[1]=0x03C184,[2]=0x03C188,[3]=0x03C18C,[4]=0x03C190,[5]=0x03C194,[6]=0x03C198,[7]=0x03C19C,[8]=0x03C1A0,[9]=0x03C1A4,[10]=0x03C1A8,[11]=0x03C1AC,[12]=0x03C1B0}
local function testTrue(array,value)
local result = false
for i = 1, table.getn(array) do
if memory.readbyte(array[i]) == value then
result = true
break
end
end
return result
end
local function testTrue2(array1,array2,value1,value2) --assumes for this case both arrays same size
local result = false
for i = 1, table.getn(array1) do
if memory.readbyte(array1[i]) == value1 and memory.readbyte(array2[i]) == value2 then
result = true
break
end
end
return result
end
local function waitLift()
local position = memory.readbyte(0x03C13B)
while position == memory.readbyte(0x03C13B) do
emu.frameadvance()
end
end
local function moveTopLeft()
if memory.readbyte(0x03C13B) == 0 and testTrue(cement,3) then
emu.frameadvance()
joypad.set({A = 1})
emu.frameadvance()
return
elseif (memory.readbyte(0x03C13B) == 1 or memory.readbyte(0x03C13B) == 2) then
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveTopLeft()
elseif memory.readbyte(0x03C13B) == 3 then
if testTrue(lift,2) == false then
emu.frameadvance()
return moveTopLeft()
else
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveTopLeft()
end
elseif memory.readbyte(0x03C13B) == 4 then
if (testTrue(lift,2) and testTrue(lift,7)) == false then
emu.frameadvance()
return moveTopLeft()
else
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveTopLeft()
end
elseif memory.readbyte(0x03C13B) == 5 or memory.readbyte(0x03C13B) == 6 then
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveTopLeft()
elseif memory.readbyte(0x03C13B) == 7 then
if (testTrue(lift,1) and testTrue(lift,6)) == false then
emu.frameadvance()
return moveTopLeft()
else
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveTopLeft()
end
elseif memory.readbyte(0x03C13B) == 8 then
emu.frameadvance()
return moveTopLeft()
elseif memory.readbyte(0x03C13B) == 9 then
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveTopLeft()
elseif memory.readbyte(0x03C13B) == 10 then
if (testTrue(lift,1) and testTrue(lift,3) and testTrue(lift,6)) == false then
emu.frameadvance()
return moveTopLeft()
else
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveTopLeft()
end
elseif memory.readbyte(0x03C13B) == 11 then
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveTopLeft()
else
gui.drawText(3,3,"ERROR @UpperLeft!",'RED')
return
end
end
local function moveLowerLeft()
if memory.readbyte(0x03C13B) == 0 then
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveLowerLeft()
elseif memory.readbyte(0x03C13B) == 1 then
if testTrue(lift,2) == false then
emu.frameadvance()
return moveLowerLeft()
else
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveLowerLeft()
end
elseif memory.readbyte(0x03C13B) == 2 then
emu.frameadvance()
return moveLowerLeft()
elseif memory.readbyte(0x03C13B) == 3 then
if testTrue(lift,2) == false then
emu.frameadvance()
return moveLowerLeft()
else
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveLowerLeft()
end
elseif memory.readbyte(0x03C13B) == 4 then
if (testTrue(lift,2) and testTrue(lift,7)) == false then
emu.frameadvance()
return moveLowerLeft()
else
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveLowerLeft()
end
elseif memory.readbyte(0x03C13B) == 5 or memory.readbyte(0x03C13B) == 6 then
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveLowerLeft()
elseif memory.readbyte(0x03C13B) == 7 then
if (testTrue(lift,3) and testTrue(lift,6)) == false then
emu.frameadvance()
return moveLowerLeft()
else
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveLowerLeft()
end
elseif memory.readbyte(0x03C13B) == 8 then
if testTrue(lift,3) == false then
emu.frameadvance()
return moveLowerLeft()
else
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveLowerLeft()
end
elseif memory.readbyte(0x03C13B) == 9 then
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveLowerLeft()
elseif memory.readbyte(0x03C13B) == 10 then
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveLowerLeft()
elseif memory.readbyte(0x03C13B) == 11 and testTrue(cement,7) then
emu.frameadvance()
joypad.set({A = 1})
emu.frameadvance()
return
else
gui.drawText(3,3,"ERROR @LowerLeft!",'RED')
return
end
end
local function moveTopRight()
if memory.readbyte(0x03C13B) == 0 then
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveTopRight()
elseif memory.readbyte(0x03C13B) == 1 then
if (testTrue(lift,2) and testTrue(lift,7)) == false then
emu.frameadvance()
return moveTopRight()
else
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveTopRight()
end
elseif memory.readbyte(0x03C13B) == 2 then
if testTrue(lift,7) == false then
emu.frameadvance()
return moveTopRight()
else
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveTopRight()
end
elseif memory.readbyte(0x03C13B) >= 3 and memory.readbyte(0x03C13B) < 5 then
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveTopRight()
elseif memory.readbyte(0x03C13B) == 5 and testTrue(cement,3) then
emu.frameadvance()
joypad.set({A = 1})
emu.frameadvance()
return
elseif memory.readbyte(0x03C13B) == 6 then
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveTopRight()
elseif memory.readbyte(0x03C13B) == 7 then
if testTrue(lift,6) == false then
emu.frameadvance()
return moveTopRight()
else
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveTopRight()
end
elseif memory.readbyte(0x03C13B) == 8 then
emu.frameadvance()
return moveTopRight()
elseif memory.readbyte(0x03C13B) == 9 then
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveTopRight()
elseif memory.readbyte(0x03C13B) == 10 then
if (testTrue(lift,3) and testTrue(lift,6)) == false then
emu.frameadvance()
return moveTopRight()
else
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveTopRight()
end
elseif memory.readbyte(0x03C13B) == 11 then
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveTopRight()
else
gui.drawText(3,3,"ERROR @UpperRight!",'RED')
return
end
end
local function moveLowerRight()
if memory.readbyte(0x03C13B) == 0 then
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveLowerRight()
elseif memory.readbyte(0x03C13B) == 1 then
if (testTrue(lift,2) and testTrue(lift,5)) == false then
emu.frameadvance()
return moveLowerRight()
else
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveLowerRight()
end
elseif memory.readbyte(0x03C13B) == 2 then
emu.frameadvance()
return moveLowerRight()
elseif memory.readbyte(0x03C13B) == 3 then
if testTrue(lift,2) == false then
emu.frameadvance()
return moveLowerRight()
else
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveLowerRight()
end
elseif memory.readbyte(0x03C13B) == 4 then
if (testTrue(lift,2) and testTrue(lift,5) and testTrue(lift,7)) == false then
emu.frameadvance()
return moveLowerRight()
else
emu.frameadvance()
joypad.set({Left = 1})
emu.frameadvance()
return moveLowerRight()
end
elseif memory.readbyte(0x03C13B) == 5 then
joypad.set({Left = 1})
emu.frameadvance()
return moveLowerRight()
elseif memory.readbyte(0x03C13B) == 6 and testTrue(cement,7) then
emu.frameadvance()
joypad.set({A = 1})
emu.frameadvance()
return
elseif memory.readbyte(0x03C13B) == 7 or memory.readbyte(0x03C13B) == 8 then
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveLowerRight()
elseif memory.readbyte(0x03C13B) == 9 then
if testTrue(lift,6) == false then
emu.frameadvance()
return moveLowerRight()
else
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveLowerRight()
end
elseif memory.readbyte(0x03C13B) == 10 then
if (testTrue(lift,3) and testTrue(lift,6)) == false then
emu.frameadvance()
return moveLowerRight()
else
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveLowerRight()
end
elseif memory.readbyte(0x03C13B) == 11 then
emu.frameadvance()
joypad.set({Right = 1})
emu.frameadvance()
return moveLowerRight()
else
gui.drawText(3,3,"ERROR @LowerRight!",'RED')
return
end
end
while true do
if memory.readbyte(0x03C137) >= 1 then -- upper left machine and cement
moveTopLeft()
elseif memory.readbyte(0x03C138) >= 1 then
moveLowerLeft()
elseif memory.readbyte(0x03C139) >= 1 then
moveTopRight()
elseif memory.readbyte(0x03C13A) >= 1 then
moveLowerRight()
end
gui.drawText(3,3,"Waiting...",'BLACK')
emu.frameadvance()
end