Implement cliff_walking_comparison(num_episodes=500, alpha=0.5, gamma=1.0, epsilon=0.1, seed=42), which trains SARSA and Q-learning on Cliff Walking and returns the tuple (sarsa_avg, qlearning_avg): each algorithm's mean total reward per training episode, rounded to 1 decimal.
Environment: a 4x12 grid of (row, col) cells, start (3, 0), goal (3, 11), cliff (3, 1) to (3, 10). Actions 0=up, 1=down, 2=left, 3=right; a move off the grid leaves the agent in place. Entering a cliff cell gives reward and teleports the agent to the start (the episode continues); every other step gives . An episode ends on reaching the goal or after 1000 steps.
Rules the expected numbers depend on:
rng = np.random.RandomState(seed) and a zero Q-table of shape (4, 12, 4).u = rng.random(); if u < epsilon the action is rng.randint(4), otherwise the argmax of Q at the state (ties -> lowest index). Nothing else consumes randomness.