Detect end of game