the program fails repeatedly and then loads a previous state to try a different move, what you see is the result of multiple trials. it can't reliably get it right on the first try.
Is a decade or two of baseball practice really all that different from a computer playing and re-playing the game over and over looking for optimal strategy?