Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Ant = class()
- function Ant:init(dir, x, y, rules)
- self.dir = dir
- self.x = x
- self.y = y
- self.rules = {}
- for k,v in pairs(rules) do
- table.insert(self.rules, k, v)
- end
- end
- function Ant:go(board)
- self.x = self:wrap(self.x, board.width)
- self.y = self:wrap(self.y, board.height)
- local p = grey
- p.r, p.g, p.b, p.a = board:get(self.x, self.y)
- for k,v in pairs(self.rules) do
- if colorEqual(colors[k], p) then
- newColor = k + 1
- if #self.rules < newColor then
- newColor = 1
- end
- board:set(self.x, self.y, colors[newColor])
- if v == L then
- self.dir = self.dir:rotate90()
- else
- self.dir = -self.dir:rotate90()
- end
- self.x = self.x + self.dir.x
- self.y = self.y + self.dir.y
- return
- end
- end
- self.x = self.x + self.dir.x
- self.y = self.y + self.dir.y
- end
- function Ant:wrap(pos, bound)
- if pos < 1 then
- return bound
- elseif bound < pos then
- return 1
- end
- return pos
- end
- function Ant:draw()
- end
- function Ant:touched(touch)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement