11import copy
2+ import math
23
34
45# This class is used to store the idea of a point in the maze and linking it to other points to create a path.
@@ -7,7 +8,7 @@ def __init__(self, x=0, y=0):
78 self .x = x
89 self .y = y
910 self .parent = None
10- self .cost = 99999
11+ self .cost = math . inf
1112
1213 def set_parent (self , p ):
1314 self .parent = p
@@ -50,8 +51,8 @@ def get_current_point_value(self, current_point):
5051 # Return all valid neighbors around a specific point, excluding points outside of the maze and walls.
5152 def get_neighbors (self , current_point ):
5253 neighbors = []
53- # potential_neighbors = [[0, - 1], [1, 0 ], [0, 1 ], [-1, 0]]
54- potential_neighbors = [[SOUTH .x , SOUTH .y ], [WEST .x , WEST .y ], [NORTH .x , NORTH .y ], [EAST .x , EAST .y ]]
54+ # potential_neighbors = [[0, 1], [0, -1 ], [1, 0 ], [-1, 0]]
55+ potential_neighbors = [[NORTH .x , NORTH .y ], [SOUTH .x , SOUTH .y ], [EAST .x , EAST .y ], [WEST .x , WEST .y ]]
5556 for neighbor in potential_neighbors :
5657 target_point = Point (current_point .x + neighbor [0 ], current_point .y + neighbor [1 ])
5758 if 0 <= target_point .x < self .maze_size_x and 0 <= target_point .y < self .maze_size_y :
@@ -131,12 +132,16 @@ def get_direction(origin, target):
131132 return 'S'
132133 elif target .x == origin .x + 1 and target .y == origin .y :
133134 return 'E'
134- else :
135+ elif target . x == origin . x - 1 and target . y == origin . y :
135136 return 'W'
136137
137138
138139# Utility to determine the cost of a move given a direction. In this case, North and South is 5, and East and West is 1.
140+ STANDARD_COST = 1
141+ GRAVITY_COST = 5
142+
143+
139144def get_cost (direction ):
140145 if direction == 'N' or direction == 'S' :
141- return 5
142- return 1
146+ return GRAVITY_COST
147+ return STANDARD_COST
0 commit comments