logic for end game