forked from paulofmandown/rotLove
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdijkstra.lua
More file actions
67 lines (53 loc) · 1.61 KB
/
Copy pathdijkstra.lua
File metadata and controls
67 lines (53 loc) · 1.61 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
ROT=require 'src.rot'
data={}
function love.load()
--f=ROT.Display:new()
-- use this to stress out the map creation and path finding
-- should take about a second to do one demo with this
f=ROT.Display:new(256, 100, .275)
map=ROT.Map.Uniform(f:getWidth(), f:getHeight(), {dugPercentage=.7})
doTheThing()
end
function love.draw() f:draw() end
update=false
function love.update()
if update then
update=false
doTheThing()
end
end
function love.keypressed() update=true end
function doTheThing()
local start=os.clock()
map:create(mapCallback)
p1=getRandomFloor(data)
p2=getRandomFloor(data)
p3=getRandomFloor(data)
start=os.clock()
dijkstra=ROT.Path.Dijkstra(p1[1], p1[2], passableCallback)
start=os.clock()
dijkstra:compute(p2[1], p2[2], dijkstraCallback)
start=os.clock()
dijkstra:compute(p3[1], p3[2], dijkstraCallback)
f:write('S', tonumber(p1[1]), tonumber(p1[2]), nil, { 0, 0, 1, 1 })
f:write('E', tonumber(p2[1]), tonumber(p2[2]), nil, { 0, 0, 1, 1 })
f:write('E', tonumber(p3[1]), tonumber(p3[2]), nil, { 0, 0, 1, 1 })
end
function dijkstraCallback(x, y)
f:write('.', x, y, nil, { 0.533, 0.0, 0.0, 1.0 })
end
function passableCallback(x, y) return data[x..','..y]==0 end
function getRandomFloor(data)
local key=nil
while true do
key=ROT.RNG:random(1,f:getWidth())..','..
ROT.RNG:random(1,f:getHeight())
if data[key]==0 then
return key:split(',')
end
end
end
function mapCallback(x, y, val)
data[x..','..y]=val
f:write(val==0 and '.' or '#', x, y)
end