-
Notifications
You must be signed in to change notification settings - Fork 3
/
Floorplan.py
35 lines (28 loc) · 1.02 KB
/
Floorplan.py
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
# built-in
# third-party
# local
class Floorplan(object):
'''
The floorplan the DotBots move in.
'''
def __init__(self,drawing):
# local variables
(self.width,self.height,self.obstacles) = self._parseDrawing(drawing)
#======================== public ==========================================
def getJSON(self):
return {
'width': self.width,
'height': self.height,
'obstacles': self.obstacles,
}
#======================== private =========================================
def _parseDrawing(self,drawing):
lines = [line for line in drawing.splitlines() if line]
width = max([len(line) for line in lines])
height = len(lines)
obstacles = []
for (y,line) in enumerate(lines):
for (x,c) in enumerate(line):
if c=='#':
obstacles += [{'x': x, 'y': y, 'width': 1, 'height': 1}]
return (width,height,obstacles)