Implement blocking_maze_dyna_q(rows, cols, initial_walls, added_walls, start, goal, change_step, gamma, alpha, epsilon, n_planning, n_steps, seed): a tabular Dyna-Q agent in a gridworld where extra walls appear mid-run.
Environment:
row * cols + col; actions 0=up, 1=down, 2=left, 3=right. A move into a wall or off the grid leaves the agent in place.1.0 for landing on goal, else 0.0; landing on the goal ends the episode and returns the agent to start.t == change_step (0-indexed), the added_walls become walls.Agent: Q starts at zeros; call np.random.seed(seed) once. Each of the n_steps steps, in order:
np.random.random() < epsilon, take np.random.randint(4); otherwise np.argmax(Q[s]).Q[s,a] += alpha * (r + gamma * max(Q[s']) - Q[s,a]) and store model[(s,a)] = (s', r) (overwriting).n_planning times: idx = np.random.randint(len(model)), take the idx-th (s,a) key in insertion order, and apply the same Q update with its stored (s', r).Return a dict:
"episodes_completed": number of goal arrivals"cumulative_reward": total reward, float rounded to 4 decimals"model_entries": number of (s, a) pairs in the model"stale_entries": model entries whose stored (s', r) no longer matches the final (post-change) environment