Learning when to change the direction of the ball