improve board edge algorithm