refactoring board-state checking algorithm code
refactoring algorithm code again