Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function newNode (posX, posY, distance, priority)
- node = {}
- node.posX = posX
- node.posY = posY
- node.distance = distance
- node.priority = priority
- -- Estimation function for the remaining distance to the goal.
- function node:estimate(destX, destY)
- local dx = destX - self.posX
- local dy = destY - self.posY
- -- Manhattan distance
- -- abs(dx) + abs(dy)
- --Euclidian Distance
- return math.sqrt(dx * dx + dy * dy)
- end
- function node:updatePriority(destX, destY)
- self.priority = self.distance + self:estimate(destX, destY) * 10
- end
- function node:nextMove()
- self.distance = self.distance + 10
- end
- mt = { __lt = function (a, b)
- return { value = a.priority < b.priority }
- end }
- setmetatable(node, mt)
- return node
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement