This should suffice, but if I'm wrong it's easy to generalize.
73FZRRIBGT2F6MK4C2JIK4M4BXVKLF5YWRWEERBB7BZ7X4XZCWTQC
TRZPDEYAE6S3FP7NKTNKQLECPVV2LRKGC7PJCC2MHPXDLU7CAABQC
X6AJODURS3K7O6ZNPOJLXFKI73E7OBRJRMBL66UHBDKFZXK4F6RAC
GVX7YSQYURPWFSUWVUAORZJTQBJURWWNBNUGEZYFAUMX3X5LSACQC
4DJCRM2JZJDQMGNBLSKEZTL42DNWFF7ZM4FUR33OHYLZFTDA5MIQC
IMDZUX5WFBYCKZPYGVTSJPONI3ORUDNALX5A2BMUFK3JOZ6DHJWQC
undo_state = nil -- undo a single move, a list of {x=,y=,cell=} squares to write to
end, }) end if undo_state then local w = App.width('undo')+10 button(ui_state, 'undo', {x=bside-w-10, y=5, w=w, h=Line_height+10, bg=bg, onpress1=undo_move, icon=function(p) color(0,0,0) g.print('undo', p.x+5, p.y+5)
end,
})
end
if undo_state then
local w = App.width('undo')+10
button(ui_state, 'undo', {x=bside-w-10, y=5, w=w, h=Line_height+10,
bg=bg, onpress1=undo_move,
icon=function(p)
color(0,0,0)
g.print('undo', p.x+5, p.y+5)
elseif chord == 'C-z' then undo_move()
elseif chord == 'C-z' then
undo_move()
local u = { {x=player.x, y=player.y, cell=src}, {x=player.x, y=player.y+1, cell=dest}}
local u = {
{x=player.x, y=player.y, cell=src},
{x=player.x, y=player.y+1, cell=dest}}
table.insert(u, {x=player.x, y=player.y+2, cell=dest2})
undo_state = u
local u = { {x=player.x, y=player.y, cell=src}, {x=player.x, y=player.y-1, cell=dest}}
{x=player.x, y=player.y-1, cell=dest}}
table.insert(u, {x=player.x, y=player.y-2, cell=dest2})
local u = { {x=player.x, y=player.y, cell=src}, {x=player.x-1, y=player.y, cell=dest}}
{x=player.x-1, y=player.y, cell=dest}}
table.insert(u, {x=player.x-2, y=player.y, cell=dest2})
local u = { {x=player.x, y=player.y, cell=src}, {x=player.x+1, y=player.y, cell=dest}}
{x=player.x+1, y=player.y, cell=dest}}
table.insert(u, {x=player.x+2, y=player.y, cell=dest2})
function undo_move() if undo_state == nil then return end for _,sq in ipairs(undo_state) do level_state[sq.y][sq.x] = sq.cell end undo_state = nilend
function undo_move()
if undo_state == nil then return end
for _,sq in ipairs(undo_state) do
level_state[sq.y][sq.x] = sq.cell
undo_state = nil