An analysis of reinforcement learning with function approximation