return states, actions, rewards
+def seq2str(seq):
+ def token2str(t):
+ if t >= first_state_code and t < first_state_code + nb_state_codes:
+ return " #@$"[t - first_state_code]
+ elif t >= first_actions_code and t < first_actions_code + nb_actions_codes:
+ return "ISNEW"[t - first_actions_code]
+ elif t >= first_rewards_code and t < first_rewards_code + nb_rewards_codes:
+ return "-0+"[t - first_rewards_code]
+ elif (
+ t >= first_lookahead_rewards_code
+ and t < first_lookahead_rewards_code + nb_lookahead_rewards_codes
+ ):
+ return "n.p"[t - first_lookahead_rewards_code]
+ else:
+ return "?"
+
+ return ["".join([token2str(x.item()) for x in row]) for row in seq]
+
+
######################################################################
def status_bar(a, r, lr=None):
a, r = a.item(), r.item()
sb_a = "ISNEW"[a] if a >= 0 and a < 5 else "?"
- sb_r = " " + ("- +"[r + 1] if r in {-1, 0, 1} else "?")
- if lr is not None:
+ sb_r = "- +"[r + 1] if r in {-1, 0, 1} else "?"
+ if lr is None:
+ sb_lr = ""
+ else:
lr = lr.item()
- sb_r = sb_r + "/" + ("- +"[lr + 1] if lr in {-1, 0, 1} else "?")
- return sb_a + " " * (states.size(-1) - len(sb_a) - len(sb_r)) + sb_r
+ sb_lr = "n p"[lr + 1] if lr in {-1, 0, 1} else "?"
+ return (
+ sb_a
+ + "/"
+ + sb_r
+ + " " * (states.size(-1) - 1 - len(sb_a + sb_r + sb_lr))
+ + sb_lr
+ )
if lookahead_rewards is None:
result += (
seq = episodes2seq(states, actions, rewards, lookahead_delta=T)
s, a, r, lr = seq2episodes(seq, height, width, lookahead=True)
print(episodes2str(s, a, r, lookahead_rewards=lr, unicode=True, ansi_colors=True))
+ print()
+ for s in seq2str(seq):
+ print(s)