Python: remove diagonal traversing

This commit is contained in:
Jan Mrna
2025-11-03 05:03:03 +01:00
parent ec3022d43e
commit c7ae2c6c14
2 changed files with 14 additions and 28 deletions

File diff suppressed because one or more lines are too long

View File

@@ -56,7 +56,8 @@ class Map:
x_center, y_center = center_point x_center, y_center = center_point
for x in range(-1,2): for x in range(-1,2):
for y in range(-1,2): for y in range(-1,2):
if x == 0 and y == 0: diagonal = x == y # includes center 0,0
if diagonal:
continue continue
p = Point2D((x + x_center, y + y_center)) p = Point2D((x + x_center, y + y_center))
if self.IsPointValid(p): if self.IsPointValid(p):
@@ -304,10 +305,6 @@ class GBFS(PathFinderBase):
@staticmethod @staticmethod
def heuristic(a: Point2D, b: Point2D) -> float: def heuristic(a: Point2D, b: Point2D) -> float:
# for now we use Manhattan distance, although
# it is probably not entirely correct, given that
# we can also move diagonally in the grid
# TODO a problem for future me
x_a, y_a = a x_a, y_a = a
x_b, y_b = b x_b, y_b = b
return abs(x_a - x_b) + abs(y_a - y_b) return abs(x_a - x_b) + abs(y_a - y_b)
@@ -348,10 +345,6 @@ class A_star(PathFinderBase):
@staticmethod @staticmethod
def heuristic(a: Point2D, b: Point2D) -> float: def heuristic(a: Point2D, b: Point2D) -> float:
# for now we use Manhattan distance, although
# it is probably not entirely correct, given that
# we can also move diagonally in the grid
# TODO a problem for future me
x_a, y_a = a x_a, y_a = a
x_b, y_b = b x_b, y_b = b
return abs(x_a - x_b) + abs(y_a - y_b) return abs(x_a - x_b) + abs(y_a - y_b)