-
Notifications
You must be signed in to change notification settings - Fork 0
/
simul.lua
61 lines (51 loc) · 1.45 KB
/
simul.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-- simul.lua
terrain = [[
-- w = wall
-- o = obstacle surrounded by walls
-- c = charger surrounded by wall has * charging terminals
-- * = charging terminal contact
-- + = connection of borders
-- - = object border
-- | = object border
-- \ = object border
-- / = object border
+-------------------W------------------+
| +-+ +---+ |
| |O| +------+ | O | |
| +-+ | | | | |
| | O | +---+ |
| | | |
W +------+ |
| + W
| / \ |
| + O + +-------+ |
| \ / | C |* |
| + +-------+ |
| |
+-----------W--------------------------+
]]
--- any line starting with -- will be removed
function stripComments(t)
t = string.gsub(t,"^%s*%-%-[^\n\r]*","")
t = string.gsub(t,"\n%s*%-%-[^\n\r]*","")
return t
end
function itemAt(x,y, terrainTable)
return terrainTable[y]:sub(x,x)
end
function parseTerrain(t)
local terrain=stripComments(t)
local lines={}
terrain:gsub("([^\n\r]*)\n",function(l) lines[#lines+1]=l end)
return lines
end
function simulateSonicSensor()
end
obstacle1={x,y,radius}
obstacle2={x,y,radius}
obstacleList={}
print(stripComments(terrain))
local l=parseTerrain(terrain)
for i,v in ipairs(l) do
print(i,v)
end