Lua能判断一个单元格的坐标是什么功能?

Lua能判断一个单元格的坐标是什么功能?,lua,cellular-automata,Lua,Cellular Automata,我正在开发Lua scriptcell自动化,现在我需要将cellularspace分为4个部分,每个部分都有自己的功能,我使用以下代码可能会让一些人觉得很愚蠢: if cells:getCell(Coord{x < 25 ,y < 25}) then cell.P = (cell.past.P + e*i1 + u1*i2) elseif cells:getCell(Coord{x < 25 ,y > 25})then cell.P = (cell.past.P +

我正在开发Lua scriptcell自动化,现在我需要将cellularspace分为4个部分,每个部分都有自己的功能,我使用以下代码可能会让一些人觉得很愚蠢:

if  cells:getCell(Coord{x < 25 ,y < 25}) then
cell.P = (cell.past.P + e*i1 + u1*i2)
elseif cells:getCell(Coord{x < 25 ,y > 25})then
cell.P = (cell.past.P + e*i1 + u2*i2)
elseif cells:getCell(Coord{x > 25 ,y < 25})then
cell.P = (cell.past.P + e*i1 + u3*i2)
else
cell.P = (cell.past.P + e*i1 + u4*i2)
end
现在我想问一下,重写上述代码的正确方法是什么?有什么功能吗?谢谢大家!

这个怎么样:

do
  local t = {
    { {x < 25, y < 25}, u1 },
    { {x < 25, y > 25}, u2 },
    { {x > 25, y < 25}, u3 },
    { {x > 25, y > 25}, u4 },
  }

  for i = 1, 4 do
    if cells:getCell(Coord(t[i][1])) then
      cell.P = (cell.past.P + e*i1 + t[i][2]*i2)
      break
    end
  end
end
虽然短不了多少,但至少代码重复少了很多。

cells:getCell和Coord做什么?这个代码有效吗?