Skip to content

Commit 82c6e57

Browse files
author
Peter Vaiko
committed
wip: pathfinder
1 parent 831d271 commit 82c6e57

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

pathfinder/main.lua

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ require('ReedsShepp')
1515
require('ReedsSheppSolver')
1616
require('Waypoint')
1717
require('Course')
18-
require('PathfinderUtil')
1918
require('ai.util.AIUtil')
2019
require('pathfinder.pathfinder')
2120

@@ -199,7 +198,7 @@ local function drawPathFinderNodes()
199198
drawOne(cell, highestCost, lowestCost, alpha)
200199
nStartNodes = nStartNodes + 1
201200
end
202-
alpha = 1 - math.min(0.5, nMiddleNodes / 1000)
201+
alpha = 1 - math.min(0.3, nMiddleNodes / 1000)
203202
nMiddleNodes = 0
204203
for cell, lowestCost, highestCost in TestPathfinder.getNodeIteratorMiddle() do
205204
drawOne(cell, highestCost, lowestCost, alpha)
@@ -279,10 +278,10 @@ function love.draw()
279278

280279
love.graphics.setPointSize(5)
281280

282-
drawPath(dubinsPath, 3, 0.8, 0.8, 0)
283-
drawPath(rsPath, 2, 0, 0.3, 0.8)
281+
--drawPath(dubinsPath, 3, 0.8, 0.8, 0)
282+
--drawPath(rsPath, 2, 0, 0.3, 0.8)
284283
if TestPathfinder.getPath() then
285-
drawPath(TestPathfinder.getPath(), 2, 0, 0.8, 0)
284+
drawPath(TestPathfinder.getPath(), 0.3, 0, 0.6, 1)
286285
end
287286
drawProhibitedAreas()
288287
drawPathFinderNodes()

pathfinder/pathfinder.lua

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ end
2727
function closeIntervalTimer(timer)
2828
end
2929

30+
function printCallstack()
31+
print(debug.traceback())
32+
end
33+
3034
require('HybridAStar')
35+
require('AStar')
36+
require('HybridAStarWithAStarInTheMiddle')
37+
require('PathfinderUtil')
3138

3239
---@class TestConstraints : PathfinderConstraintInterface
3340
local TestConstraints = CpObject(PathfinderConstraintInterface)
@@ -58,11 +65,12 @@ function TestConstraints:getNodePenalty(node)
5865
return self.penalty
5966
end
6067
end
68+
return 0
6169
end
6270

6371
local constraints = TestConstraints()
64-
local pathfinder = HybridAStarWithAStarInTheMiddle(20)
65-
local pathfinder = AStar({})
72+
local pathfinder = HybridAStarWithAStarInTheMiddle({}, 20)
73+
--local pathfinder = AStar({})
6674
local path = nil
6775

6876
TestPathfinder = {}
@@ -84,11 +92,11 @@ function TestPathfinder.update()
8492
end
8593

8694
function TestPathfinder.onFinish(result)
87-
local hasValidPath = result.path and #result.path > 2
95+
local hasValidPath = result.path and #result.path >= 2
8896
if hasValidPath then
8997
path = result.path
90-
if pathfinder.nodes then pathfinder.nodes:print()
91-
98+
if pathfinder.nodes then
99+
-- pathfinder.nodes:print()
92100
end
93101
else
94102
path = nil
@@ -132,10 +140,10 @@ function TestPathfinder.getNodeIterator(iterator)
132140
end
133141

134142
function TestPathfinder.call(func, ...)
135-
local resultOrOk, done, resultPath = func(pathfinder, ...)
136-
if type(resultOrOk) ~= 'table' then
137-
return {done = done, path = resultPath}
143+
local resultOrDone, resultPath = func(pathfinder, ...)
144+
if type(resultOrDone) ~= 'table' then
145+
return {done = resultOrDone, path = resultPath}
138146
else
139-
return resultOrOk
147+
return resultOrDone
140148
end
141149
end

0 commit comments

Comments
 (0)