refactored code: used same win logic for boxes and boards