logic to determine winner