added an endgame check function