Skip to content

Commit

Permalink
optimal for hallway in improved repeat A*
Browse files Browse the repository at this point in the history
  • Loading branch information
王锦潼 committed Sep 26, 2021
1 parent cf4b636 commit 3cc31f5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions assignment1/final_project/Improvement_repeat_A_star.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,33 @@ def check_route(path: list, block_list_info: list, closed_list: list, maze: list
return path


def check_hallway(maze:list, path:list, rows:int, columns:int, re_start_cell:Node):
if len(path)==0:
return path
while True:
point = path[-1]
surround_cells=[[point[0] - 1, point[1]], [point[0] + 1, point[1]], [point[0], point[1] - 1],
[point[0], point[1] + 1]]
surround_cells_copy=surround_cells.copy()
for surround_cell in surround_cells_copy:
if 0<=surround_cell[0]<rows:
if 0<=surround_cell[1]<columns:
if maze[surround_cell[0]][surround_cell[1]]!=1:
continue
surround_cells.remove(surround_cell)
if len(surround_cells)==2:
if len(path)==1:
pre_cell=re_start_cell.get_father_node().get_items()
else:
pre_cell=path[-2]
surround_cells.remove(pre_cell)
new_cell=surround_cells[0]
path.append(new_cell)
else:
break
return path


def improved_repeat_A_star(start_point: list, end_point: list, maze: list, rows: int, columns: int, model="E"):
"""
the main algorithm of improved repeat forward A*
Expand Down Expand Up @@ -123,6 +150,13 @@ def improved_repeat_A_star(start_point: list, end_point: list, maze: list, rows:
closed_list=closed_list.copy(),
maze=maze)

# go into the hallway
route=check_hallway(maze=maze,
path=route,
rows=rows,
columns=columns,
re_start_cell=re_start_cell)

# change cell list to cell node list
node_path = generate_path_list(re_start_cell=re_start_cell,
path=route,
Expand Down

0 comments on commit 3cc31f5

Please sign in to comment.