forked from Yonaba/Jumper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannotatedPathing.lua
41 lines (37 loc) · 1.1 KB
/
annotatedPathing.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- Tests sample for clearance metrics calculation
-- See Figure 10 at http://aigamedev.com/open/tutorial/clearance-based-pathfinding/
-- Jump Point Search still has some flaws with clearance based pathfinding
local Grid = require 'jumper.grid'
local PF = require 'jumper.pathfinder'
local map = {
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,1,0},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,1,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0,2,0},
{0,0,1,1,1,0,0,2,0,0},
{0,0,0,1,1,0,2,0,0,2},
{0,0,0,0,1,0,0,0,0,2},
{0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0}
}
local grid = Grid(map)
local walkable = function(v) return v~=2 end
local finder = PF(grid, 'ASTAR',walkable)
finder:annotateGrid()
local finderNames = PF:getFinders()
local sx, sy = 1,1
local ex, ey = 9,9
local agent_size = 2
for i = 1,#finderNames do
finder:setFinder(finderNames[i])
local path = finder:getPath(sx, sy, ex, ey, agent_size)
print(('Algorithm used: %s - Path %s')
:format(finder:getFinder(), path and 'found' or 'not found'))
if path then
for node, count in path:nodes() do
print((' Step %d. (%d,%d)')
:format(count, node:getPos()))
end
end
end