-
Notifications
You must be signed in to change notification settings - Fork 2
/
map-conv.py
39 lines (34 loc) · 1.01 KB
/
map-conv.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
36
37
38
39
#!/usr/bin/python
## Original format:
### type octile
### height <h>
### width <w>
### map
### @@@@@@@@@TTTTTTT........TTTTTT@@@@@@
## where:
## - @: impassable
## - T: impassable (tree)
## - .: reachable
## Because of the way the ECBS implementation is set up,
## we need to pad the graph with an impassable ring.
def convert_map(src, dest):
header = src.readline().strip()
if header.startswith("type"):
ht = int(src.readline().strip().split()[1])
wd = int(src.readline().strip().split()[1])
src.readline()
else:
toks = header.split(',')
ht = int(toks[0])
wd = int(toks[1])
print >>dest, "{0},{1}".format(ht+2, wd+2)
print >>dest, ",".join(["1" for i in xrange(wd+2)])
for r in xrange(ht):
row = src.readline().strip()
prow = ["1"] + map(lambda e : "0" if e == '.' else "1", row) + ["1"]
assert(len(prow) == wd+2)
print >>dest, ",".join(prow)
print >>dest, ",".join(["1" for i in xrange(wd+2)])
if __name__ == '__main__':
import sys
convert_map(sys.stdin, sys.stdout)