# Problem 1(d): value of the start state (1,1) after each iteration, walled in
# compared with the closed form -0.1 * (1 - 0.95^k) / (1 - 0.95)
from common import make_mdp, run_vi

mdp = make_mdp(walls=[(1, 2), (2, 1), (2, 2)], lava_locs=[])
n_iter, v_start, v_hist = run_vi(mdp)
print('iterations:', n_iter)
print('value of the start state at the end:', round(v_start, 4))
print('iteration  value  formula')
for k in [1, 2, 5, 10, 50, 100, n_iter]:
    v = [val for s, val in v_hist[k - 1].items() if (s.x, s.y) == (1, 1)][0]
    print(k, ' ', round(v, 4), ' ', round(-0.1 * (1 - 0.95 ** k) / 0.05, 4))
