Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions jumper/core/node.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ if (...) then
-- @tparam int y the y-coordinate of the node on the collision map
-- @treturn node a new `node`
-- @usage local node = Node(3,4)
function Node:new(x,y)
return setmetatable({_x = x, _y = y, _clearance = {}}, Node)
function Node:new(x,y,c)
return setmetatable({_x = x, _y = y, _c=c,_clearance = {}}, Node)
end

-- Enables the use of operator '<' to compare nodes.
Expand All @@ -45,6 +45,8 @@ if (...) then
-- @usage local y = node:getY()
function Node:getY() return self._y end

function Node:getCost() return self._c end

--- Returns x and y coordinates of a `node`
-- @class function
-- @treturn number the x-coordinate of the `node`
Expand Down
2 changes: 1 addition & 1 deletion jumper/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ if (...) then
for x in pairs(map[y]) do
min_x = not min_x and x or (x<min_x and x or min_x)
max_x = not max_x and x or (x>max_x and x or max_x)
nodes[y][x] = Node:new(x,y)
nodes[y][x] = Node:new(x,y,map[y][x])
end
end
return nodes,
Expand Down
6 changes: 6 additions & 0 deletions jumper/pathfinder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,12 @@ if (...) then
return self
end

function Pathfinder:setCostEval(costEval)
assert((type(costEval) == 'function'),'Not a valid heuristic!')
self._costEval = costEval
return self
end

--- Returns the `heuristic` used. Returns the function itself.
-- @class function
-- @treturn func the `heuristic` function being used by the `pathfinder`
Expand Down
2 changes: 1 addition & 1 deletion jumper/search/astar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (...) then

-- Updates G-cost
local function computeCost(node, neighbour, finder, clearance)
local mCost = Heuristics.EUCLIDIAN(neighbour, node)
local mCost = neighbour._c--Heuristics.EUCLIDIAN(neighbour, node)
if node._g + mCost < neighbour._g then
neighbour._parent = node
neighbour._g = node._g + mCost
Expand Down