refactored cell count and win check logic