Logic to check if game is over