detect end of the game