-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpprint.py
More file actions
69 lines (58 loc) · 1.75 KB
/
pprint.py
File metadata and controls
69 lines (58 loc) · 1.75 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
68
69
from config import Config
from utils import position_to_str, state_to_str, action_to_str
def pprint_map(data=None):
if data is None:
data = {}
def edge_weight(ij1, ij2):
p1, p2 = position_to_str(ij1), position_to_str(ij2)
w = Config.edges.get((p1, p2))
if w:
return w
else:
return Config.edges.get((p2, p1))
s = ' a b c d e f g\n\n'
for j in range(len(Config.numbers)):
h = ' #'
if j == 2:
v = str(j + 1) + '--->'
else:
v = str(j + 1) + ' '
for i in range(len(Config.letters)):
w = edge_weight((i, j), (i, j - 1))
if not w or w >= -1.:
h += ' #'
else:
h += ' - #'
if (i, j) in data:
t = data[i, j]
else:
t = ' '
if i == len(Config.letters) - 1:
w = None
else:
w = edge_weight((i, j), (i + 1, j))
if not w or w >= -1.:
v += ' {} '.format(t)
else:
v += ' {} |'.format(t)
s += h + '\n'
s += v + '\n'
s += ' #'
for _ in Config.letters:
s += ' #'
s += '\n'
print(s)
def pformat_path(path, include_state=True):
ppath = []
for elem in path:
if isinstance(elem, tuple):
if include_state:
ppath.append(state_to_str(elem))
else:
ppath.append(action_to_str(elem))
return ppath
def pprint_transition(s1, a, s2, rew):
tran_str = state_to_str(s1) + "-" + action_to_str(a) + "->" + state_to_str(s2) + " : " + str(rew)
print(tran_str)
if __name__ == '__main__':
pprint_map()