Implementation of the sarsa algorithm