Detect the end of the game