First algorithm for the game