Implement mountain_car_sarsa(n_episodes, n_bins=8, alpha=0.05, gamma=1.0, epsilon=0.1, max_steps=200, seed=42): episodic semi-gradient Sarsa on Mountain Car with one-hot grid features.
Environment: state , actions , reward per step. Transition: , ; if then ; terminal when .
Features: position edges np.linspace(-1.2, 0.5, n_bins + 1), velocity edges np.linspace(-0.07, 0.07, n_bins + 1); a value's bin is np.searchsorted(edges[1:], value) capped at . Each activates exactly one of weights, so is that weight; all weights start at .
Randomness, with rng = np.random.RandomState(seed), in this order:
rng.uniform(-0.6, -0.4), , then pick the first action.rng.random(); if it is the action is rng.randint(3), otherwise the greedy action (lowest index on ties). The draw happens even when .max_steps steps the episode is truncated; that last step still picks and updates.Return (episode_lengths, weight_sum): a list with the steps taken per episode (a truncated episode counts max_steps) and round(float(w.sum()), 4).