Implement the SARSA (State-Action-Reward-State-Action) on-policy temporal-difference control algorithm for navigating a windy gridworld environment.
The environment is a rectangular grid of size height x width. The agent starts at a given position and must reach a goal position. Each column of the grid has a wind strength that pushes the agent upward (toward row 0) after every move.
Actions (encoded as integers):
0 = Up, 1 = Right, 2 = Down, 3 = LeftTransitions: When the agent takes an action at position (row, col), the resulting position is computed by applying the action's movement AND subtracting the wind strength of the current column from the row. The result is clipped to stay within grid bounds.
Reward: Every step gives a reward of -1.0. The episode ends when the agent reaches the goal state.
Your function should:
(Q, policy, episode_lengths) where:
Q is a numpy array of shape (height, width, 4)policy is the greedy policy grid of shape (height, width) with the best action at each stateepisode_lengths is a list of the number of steps taken in each episodeEpsilon-greedy: With probability epsilon, choose a random action uniformly; otherwise, choose the action with the highest Q-value (break ties by choosing the lowest index via argmax).
Use np.random.seed(seed) at the start, np.random.random() for the epsilon check, and np.random.randint() for random action selection.