A2HONA2RA6ZGQXHKELGFUTITFK52HYDRMUPS5VJJCK5QTQRCCIMQC
arena.setCell(pos + dirFromString(direction), self)
arena.setCell(pos, Cell{owner=self.owner})
self.waitTime = 4
arena:setCell(pos + dirFromString(direction), self, function()
arena:setCell(pos, Cell{owner=self.owner})
end)
arena:setCell(pos, Cell{owner=self.owner})
return 4
end
local IntermediateArena = function(arena)
local intermediate = {cells = {}}
function intermediate:resolve(x, y)
local result
for _, cell in self.cells[x][y].cells do
if not result then
result = cell
elseif cell.core and result.core then
return nil
elseif cell.core and not result.core then
result = cell
end
end
return result or self:getCell(x, y)
end
function intermediate:undo(x, y)
local cell = self.cells[x][y]
for _, action in ipairs(cell.actions) do
action.undo()
end
cell.cell = cell.original
end
function intermediate:setCell(x, y, to, undo)
table.insert(self.cells[x][y].actions, undo)
table.insert(self.cells[x][y].cells, to)
end
function intermediate:getCell(x, y)
return self.cells[x][y].original
end
for x, row in ipairs(arena.cells) do
intermediate.cells[x] = {}
for y, cell in ipairs(row) do
intermediate.cells[x][y] = {
original = cell,
cells = {},
-- Undo actions.
actions = {}
}
end
end
return intermediate
function arena.simulate(self)
local intermediate = Arena(width, height)
for x = 1, width do
for y = 1, height do
intermediate.setCell(x, y, self.cells[x][y])
end
end
for x in ipairs(self.cells) do
for y in ipairs(self.cells) do
local cell = self.cells[x][y]
function arena:simulate()
local intermediate = IntermediateArena(self)
for x, row in ipairs(self.cells) do
for y, cell in ipairs(row) do
end
end
end
end
-- Resolve conflicts by undoing the actions that caused them.
local hasConflicts = true
while hasConflicts do
hasConflicts = false
for x, row in ipairs(self.cells) do
for y, _ in ipairs(row) do
if not intermediate:resolve(x, y) then
hasConflicts = true
intermediate:undo(x, y)