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
endlocal IntermediateArena = function(arena)local intermediate = {cells = {}}function intermediate:resolve(x, y)local resultfor _, cell in self.cells[x][y].cells doif not result thenresult = cellelseif cell.core and result.core thenreturn nilelseif cell.core and not result.core thenresult = cellendendreturn result or self:getCell(x, y)endfunction intermediate:undo(x, y)local cell = self.cells[x][y]for _, action in ipairs(cell.actions) doaction.undo()endcell.cell = cell.originalendfunction intermediate:setCell(x, y, to, undo)table.insert(self.cells[x][y].actions, undo)table.insert(self.cells[x][y].cells, to)endfunction intermediate:getCell(x, y)return self.cells[x][y].originalendfor x, row in ipairs(arena.cells) dointermediate.cells[x] = {}for y, cell in ipairs(row) dointermediate.cells[x][y] = {original = cell,cells = {},-- Undo actions.actions = {}}endendreturn intermediate
function arena.simulate(self)local intermediate = Arena(width, height)for x = 1, width dofor y = 1, height dointermediate.setCell(x, y, self.cells[x][y])endendfor x in ipairs(self.cells) dofor y in ipairs(self.cells) dolocal cell = self.cells[x][y]
function arena:simulate()local intermediate = IntermediateArena(self)for x, row in ipairs(self.cells) dofor y, cell in ipairs(row) do
endendendend-- Resolve conflicts by undoing the actions that caused them.local hasConflicts = truewhile hasConflicts dohasConflicts = falsefor x, row in ipairs(self.cells) dofor y, _ in ipairs(row) doif not intermediate:resolve(x, y) thenhasConflicts = trueintermediate:undo(x, y)