change the method to stablely detect game end