sorting squares by heuristic