Implement a function random_walk_td_mc that runs both TD(0) and first-visit Monte Carlo prediction on a set of random walk episodes and returns the value estimates from each method.
The random walk environment has n_states non-terminal states indexed from 0 to n_states-1. Two terminal states exist implicitly: one to the left of state 0 and one to the right of state n_states-1. Episodes are provided as pre-generated sequences of transitions.
Parameters:
episodes: A list of episodes. Each episode is a list of (state, reward, next_state, done) tuples. When done=True, the episode has terminated (the agent reached a terminal state). Non-terminal states are indexed 0 to n_states-1. Terminal next_states can be any value and should be ignored for value computation.n_states: Integer, the number of non-terminal states.gamma: Float, the discount factor (default 1.0).alpha: Float, the learning rate for TD(0) (default 0.1).Requirements:
Returns:
(td_values, mc_values) where each is a list of floats of length n_states representing the estimated values for states 0 through n_states-1.