X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=inline;f=escape.py;h=a2e378d882814c14192b664829ce0081b3583cb8;hb=49218a3e2adb19d2ec98a454e0076c3461ab1c69;hp=f945172d7db242411431a8a4c1b83dcd770a698b;hpb=8855d37cef610b39f37d2b3b331046d1e7040a37;p=culture.git diff --git a/escape.py b/escape.py index f945172..a2e378d 100755 --- a/escape.py +++ b/escape.py @@ -165,6 +165,25 @@ def seq2episodes(seq, height, width, lookahead=False): 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] + + ###################################################################### @@ -204,11 +223,19 @@ def episodes2str( 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 += ( @@ -249,3 +276,6 @@ if __name__ == "__main__": 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)