Skip to content

Commit d1d9cd5

Browse files
committed
add state labels
1 parent 1b1723e commit d1d9cd5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: chapter03/grid_world.py

+23
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,20 @@ def draw_image(image):
5757

5858
# Add cells
5959
for (i, j), val in np.ndenumerate(image):
60+
61+
# add state labels
62+
if [i, j] == A_POS:
63+
val = str(val) + " (A)"
64+
if [i, j] == A_PRIME_POS:
65+
val = str(val) + " (A')"
66+
if [i, j] == B_POS:
67+
val = str(val) + " (B)"
68+
if [i, j] == B_PRIME_POS:
69+
val = str(val) + " (B')"
70+
6071
tb.add_cell(i, j, width, height, text=val,
6172
loc='center', facecolor='white')
73+
6274

6375
# Row and column labels...
6476
for i in range(len(image)):
@@ -88,6 +100,17 @@ def draw_policy(optimal_values):
88100
val=''
89101
for ba in best_actions:
90102
val+=ACTIONS_FIGS[ba]
103+
104+
# add state labels
105+
if [i, j] == A_POS:
106+
val = str(val) + " (A)"
107+
if [i, j] == A_PRIME_POS:
108+
val = str(val) + " (A')"
109+
if [i, j] == B_POS:
110+
val = str(val) + " (B)"
111+
if [i, j] == B_PRIME_POS:
112+
val = str(val) + " (B')"
113+
91114
tb.add_cell(i, j, width, height, text=val,
92115
loc='center', facecolor='white')
93116

0 commit comments

Comments
 (0)