Implement the First-Visit Monte Carlo (MC) Control algorithm with Exploring Starts for finding the optimal policy in a finite Markov Decision Process (MDP).
Write a function mc_control_exploring_starts(env, n_states, n_actions, gamma, n_episodes, max_steps=100, seed=42) where:
env: A dictionary mapping (state, action) tuples to (next_state, reward, done) tuples, representing deterministic environment transitions.n_states: Integer, total number of states.n_actions: Integer, total number of actions.gamma: Float, the discount factor.n_episodes: Integer, number of episodes to simulate.max_steps: Integer, maximum number of steps per episode (default 100).seed: Integer, random seed for reproducibility (default 42).The function should return a tuple (Q, policy) where:
Q is a numpy array of shape (n_states, n_actions) containing the estimated action-value function.policy is a numpy array of shape (n_states,) containing the greedy action for each state.Key requirements:
np.random.seed(seed) at the start for reproducibility.np.argmax).(state, action) pair is not found in env, the episode ends immediately with no transition.