Implement q_learning(num_states, num_actions, P, R, terminal_states, alpha, gamma, epsilon, num_episodes) for a tabular MDP and return the learned Q-table, a NumPy array of shape (num_states, num_actions) that starts at zeros.
P has shape (num_states, num_actions, num_states) (transition probabilities); R has shape (num_states, num_actions) (reward for action in state ).np.random.choice over the list of non-terminal states in increasing order, and runs until a terminal state is reached.np.random.rand(); if it is below epsilon take np.random.randint(num_actions), otherwise the argmax of Q[state] (lowest index on ties). Then sample next_state = np.random.choice(num_states, p=P[state, action]).next_state is terminal, else , where is R[state, action].