From 851975e818b1cff18d14b6bacc0aa195c07f2d25 Mon Sep 17 00:00:00 2001 From: Uday Date: Fri, 4 Oct 2024 12:59:10 +0530 Subject: [PATCH 1/4] A* Searching Algorithm Added with README file --- A_star_searching_algorithm/A_star_search.py | 193 ++++++++++++++ A_star_searching_algorithm/README.md | 264 ++++++++++++++++++++ 2 files changed, 457 insertions(+) create mode 100644 A_star_searching_algorithm/A_star_search.py create mode 100644 A_star_searching_algorithm/README.md diff --git a/A_star_searching_algorithm/A_star_search.py b/A_star_searching_algorithm/A_star_search.py new file mode 100644 index 000000000000..fb2fecbba638 --- /dev/null +++ b/A_star_searching_algorithm/A_star_search.py @@ -0,0 +1,193 @@ +# Python program for A* Search Algorithm +import math +import heapq + +# Define the Cell class + + +class Cell: + def __init__(self): + # Parent cell's row index + self.parent_i = 0 + # Parent cell's column index + self.parent_j = 0 + # Total cost of the cell (g + h) + self.f = float('inf') + # Cost from start to this cell + self.g = float('inf') + # Heuristic cost from this cell to destination + self.h = 0 + + +# Define the size of the grid +ROW = 9 +COL = 10 + +# Check if a cell is valid (within the grid) + + +def is_valid(row, col): + return (row >= 0) and (row < ROW) and (col >= 0) and (col < COL) + +# Check if a cell is unblocked + + +def is_unblocked(grid, row, col): + return grid[row][col] == 1 + +# Check if a cell is the destination + + +def is_destination(row, col, dest): + return row == dest[0] and col == dest[1] + +# Calculate the heuristic value of a cell (Euclidean distance to destination) + + +def calculate_h_value(row, col, dest): + return ((row - dest[0]) ** 2 + (col - dest[1]) ** 2) ** 0.5 + +# Trace the path from source to destination + + +def trace_path(cell_details, dest): + print("The Path is ") + path = [] + row = dest[0] + col = dest[1] + + # Trace the path from destination to source using parent cells + while not (cell_details[row][col].parent_i == row and cell_details[row][col].parent_j == col): + path.append((row, col)) + temp_row = cell_details[row][col].parent_i + temp_col = cell_details[row][col].parent_j + row = temp_row + col = temp_col + + # Add the source cell to the path + path.append((row, col)) + # Reverse the path to get the path from source to destination + path.reverse() + + # Print the path + for i in path: + print("->", i, end=" ") + print() + +# Implement the A* search algorithm + + +def a_star_search(grid, src, dest): + # Check if the source and destination are valid + if not is_valid(src[0], src[1]) or not is_valid(dest[0], dest[1]): + print("Source or destination is invalid") + return + + # Check if the source and destination are unblocked + if not is_unblocked(grid, src[0], src[1]) or not is_unblocked(grid, dest[0], dest[1]): + print("Source or the destination is blocked") + return + + # Check if we are already at the destination + if is_destination(src[0], src[1], dest): + print("We are already at the destination") + return + + # Initialize the closed list (visited cells) + closed_list = [[False for _ in range(COL)] for _ in range(ROW)] + # Initialize the details of each cell + cell_details = [[Cell() for _ in range(COL)] for _ in range(ROW)] + + # Initialize the start cell details + i = src[0] + j = src[1] + cell_details[i][j].f = 0 + cell_details[i][j].g = 0 + cell_details[i][j].h = 0 + cell_details[i][j].parent_i = i + cell_details[i][j].parent_j = j + + # Initialize the open list (cells to be visited) with the start cell + open_list = [] + heapq.heappush(open_list, (0.0, i, j)) + + # Initialize the flag for whether destination is found + found_dest = False + + # Main loop of A* search algorithm + while len(open_list) > 0: + # Pop the cell with the smallest f value from the open list + p = heapq.heappop(open_list) + + # Mark the cell as visited + i = p[1] + j = p[2] + closed_list[i][j] = True + + # For each direction, check the successors + directions = [(0, 1), (0, -1), (1, 0), (-1, 0), + (1, 1), (1, -1), (-1, 1), (-1, -1)] + for dir in directions: + new_i = i + dir[0] + new_j = j + dir[1] + + # If the successor is valid, unblocked, and not visited + if is_valid(new_i, new_j) and is_unblocked(grid, new_i, new_j) and not closed_list[new_i][new_j]: + # If the successor is the destination + if is_destination(new_i, new_j, dest): + # Set the parent of the destination cell + cell_details[new_i][new_j].parent_i = i + cell_details[new_i][new_j].parent_j = j + print("The destination cell is found") + # Trace and print the path from source to destination + trace_path(cell_details, dest) + found_dest = True + return + else: + # Calculate the new f, g, and h values + g_new = cell_details[i][j].g + 1.0 + h_new = calculate_h_value(new_i, new_j, dest) + f_new = g_new + h_new + + # If the cell is not in the open list or the new f value is smaller + if cell_details[new_i][new_j].f == float('inf') or cell_details[new_i][new_j].f > f_new: + # Add the cell to the open list + heapq.heappush(open_list, (f_new, new_i, new_j)) + # Update the cell details + cell_details[new_i][new_j].f = f_new + cell_details[new_i][new_j].g = g_new + cell_details[new_i][new_j].h = h_new + cell_details[new_i][new_j].parent_i = i + cell_details[new_i][new_j].parent_j = j + + # If the destination is not found after visiting all cells + if not found_dest: + print("Failed to find the destination cell") + +# Driver Code + + +def main(): + # Define the grid (1 for unblocked, 0 for blocked) + grid = [ + [1, 0, 1, 1, 1, 1, 0, 1, 1, 1], + [1, 1, 1, 0, 1, 1, 1, 0, 1, 1], + [1, 1, 1, 0, 1, 1, 0, 1, 0, 1], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 1], + [1, 1, 1, 0, 1, 1, 1, 0, 1, 0], + [1, 0, 1, 1, 1, 1, 0, 1, 0, 0], + [1, 0, 0, 0, 0, 1, 0, 0, 0, 1], + [1, 0, 1, 1, 1, 1, 0, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 0, 0, 1] + ] + + # Define the source and destination + src = [8, 0] + dest = [0, 0] + + # Run the A* search algorithm + a_star_search(grid, src, dest) + + +if __name__ == "__main__": + main() diff --git a/A_star_searching_algorithm/README.md b/A_star_searching_algorithm/README.md new file mode 100644 index 000000000000..15b0160a8c6b --- /dev/null +++ b/A_star_searching_algorithm/README.md @@ -0,0 +1,264 @@ +## A* Search Algorithm in Python +- Given an adjacency list and a heuristic function for a directed graph, implement the A* search algorithm to find the shortest path from a start node to a goal node. + +`Examples:` +```bash +Input: +Start Node: A +Goal Node: F +Nodes: A, B, C, D, E, F +Edges with weights: +(A, B, 1), (A, C, 4), +(B, D, 3), (B, E, 5), +(C, F, 2), +(D, F, 1), (D, E, 1), +(E, F, 2) +Output: A -> B -> D -> F +Explanation: The A* search algorithm is applied to find the shortest path from node A to node F in the given graph. The path found is A -> B -> D -> F, with a total cost of 5. + + + +Input: +Start Node: A +Goal Node: E +Nodes: A, B, C, D, E +Edges with weights: +(A, B, 3), (A, C, 5), +(B, D, 2), (B, E, 6), +(C, E, 1), +(D, E, 4) +Output: A -> B -> D -> E +Explanation: The A* search algorithm is applied to find the shortest path from node A to node E in the given graph. The path found is A -> B -> D -> E, with a total cost of 9. +``` +#### What is A* Search Algorithm? +- The ***A* search algorithm*** is a popular ***pathfinding algorithm*** used in many applications, including video games, robotics, and route planning. A* is an extension of Dijkstra’s algorithm and uses heuristics to improve the efficiency of the search by prioritizing paths that are likely to be closer to the goal. + +#### How A* Search Algo works? +- Here’s how the A* search algorithm works: + +`Initialization:` +- Start with an open list containing the start node. +- Start with an empty closed list. + +`While the open list is not empty:` +- Select the node with the lowest f value from the open list. - This node is the current node. +- If the current node is the goal node, the path has been found; reconstruct the path and return it. +- Move the current node to the closed list. +- For each neighbor of the current node: + - If the neighbor is in the closed list or is a wall, skip it. + - If the neighbor is not in the open list: + - Compute its g value (cost from the start node to the current node plus the cost from the current node to the neighbor). + - Compute its h value (heuristic estimate of the cost from the neighbor to the goal). + - Add it to the open list with f=g+h and set the parent of the neighbor to the current node. + - If the neighbor is already in the open list: + - If the new g value is lower than the current g value, update the neighbor’s g and f values and update its parent to the current node. + +`If the open list is empty:` +- The goal is unreachable; return failure. + +***`A_start_search.py`*** +```bash +# Python program for A* Search Algorithm +import math +import heapq + +# Define the Cell class + + +class Cell: + def __init__(self): + # Parent cell's row index + self.parent_i = 0 + # Parent cell's column index + self.parent_j = 0 + # Total cost of the cell (g + h) + self.f = float('inf') + # Cost from start to this cell + self.g = float('inf') + # Heuristic cost from this cell to destination + self.h = 0 + + +# Define the size of the grid +ROW = 9 +COL = 10 + +# Check if a cell is valid (within the grid) + + +def is_valid(row, col): + return (row >= 0) and (row < ROW) and (col >= 0) and (col < COL) + +# Check if a cell is unblocked + + +def is_unblocked(grid, row, col): + return grid[row][col] == 1 + +# Check if a cell is the destination + + +def is_destination(row, col, dest): + return row == dest[0] and col == dest[1] + +# Calculate the heuristic value of a cell (Euclidean distance to destination) + + +def calculate_h_value(row, col, dest): + return ((row - dest[0]) ** 2 + (col - dest[1]) ** 2) ** 0.5 + +# Trace the path from source to destination + + +def trace_path(cell_details, dest): + print("The Path is ") + path = [] + row = dest[0] + col = dest[1] + + # Trace the path from destination to source using parent cells + while not (cell_details[row][col].parent_i == row and cell_details[row][col].parent_j == col): + path.append((row, col)) + temp_row = cell_details[row][col].parent_i + temp_col = cell_details[row][col].parent_j + row = temp_row + col = temp_col + + # Add the source cell to the path + path.append((row, col)) + # Reverse the path to get the path from source to destination + path.reverse() + + # Print the path + for i in path: + print("->", i, end=" ") + print() + +# Implement the A* search algorithm + + +def a_star_search(grid, src, dest): + # Check if the source and destination are valid + if not is_valid(src[0], src[1]) or not is_valid(dest[0], dest[1]): + print("Source or destination is invalid") + return + + # Check if the source and destination are unblocked + if not is_unblocked(grid, src[0], src[1]) or not is_unblocked(grid, dest[0], dest[1]): + print("Source or the destination is blocked") + return + + # Check if we are already at the destination + if is_destination(src[0], src[1], dest): + print("We are already at the destination") + return + + # Initialize the closed list (visited cells) + closed_list = [[False for _ in range(COL)] for _ in range(ROW)] + # Initialize the details of each cell + cell_details = [[Cell() for _ in range(COL)] for _ in range(ROW)] + + # Initialize the start cell details + i = src[0] + j = src[1] + cell_details[i][j].f = 0 + cell_details[i][j].g = 0 + cell_details[i][j].h = 0 + cell_details[i][j].parent_i = i + cell_details[i][j].parent_j = j + + # Initialize the open list (cells to be visited) with the start cell + open_list = [] + heapq.heappush(open_list, (0.0, i, j)) + + # Initialize the flag for whether destination is found + found_dest = False + + # Main loop of A* search algorithm + while len(open_list) > 0: + # Pop the cell with the smallest f value from the open list + p = heapq.heappop(open_list) + + # Mark the cell as visited + i = p[1] + j = p[2] + closed_list[i][j] = True + + # For each direction, check the successors + directions = [(0, 1), (0, -1), (1, 0), (-1, 0), + (1, 1), (1, -1), (-1, 1), (-1, -1)] + for dir in directions: + new_i = i + dir[0] + new_j = j + dir[1] + + # If the successor is valid, unblocked, and not visited + if is_valid(new_i, new_j) and is_unblocked(grid, new_i, new_j) and not closed_list[new_i][new_j]: + # If the successor is the destination + if is_destination(new_i, new_j, dest): + # Set the parent of the destination cell + cell_details[new_i][new_j].parent_i = i + cell_details[new_i][new_j].parent_j = j + print("The destination cell is found") + # Trace and print the path from source to destination + trace_path(cell_details, dest) + found_dest = True + return + else: + # Calculate the new f, g, and h values + g_new = cell_details[i][j].g + 1.0 + h_new = calculate_h_value(new_i, new_j, dest) + f_new = g_new + h_new + + # If the cell is not in the open list or the new f value is smaller + if cell_details[new_i][new_j].f == float('inf') or cell_details[new_i][new_j].f > f_new: + # Add the cell to the open list + heapq.heappush(open_list, (f_new, new_i, new_j)) + # Update the cell details + cell_details[new_i][new_j].f = f_new + cell_details[new_i][new_j].g = g_new + cell_details[new_i][new_j].h = h_new + cell_details[new_i][new_j].parent_i = i + cell_details[new_i][new_j].parent_j = j + + # If the destination is not found after visiting all cells + if not found_dest: + print("Failed to find the destination cell") + +# Driver Code + + +def main(): + # Define the grid (1 for unblocked, 0 for blocked) + grid = [ + [1, 0, 1, 1, 1, 1, 0, 1, 1, 1], + [1, 1, 1, 0, 1, 1, 1, 0, 1, 1], + [1, 1, 1, 0, 1, 1, 0, 1, 0, 1], + [0, 0, 1, 0, 1, 0, 0, 0, 0, 1], + [1, 1, 1, 0, 1, 1, 1, 0, 1, 0], + [1, 0, 1, 1, 1, 1, 0, 1, 0, 0], + [1, 0, 0, 0, 0, 1, 0, 0, 0, 1], + [1, 0, 1, 1, 1, 1, 0, 1, 1, 1], + [1, 1, 1, 0, 0, 0, 1, 0, 0, 1] + ] + + # Define the source and destination + src = [8, 0] + dest = [0, 0] + + # Run the A* search algorithm + a_star_search(grid, src, dest) + + +if __name__ == "__main__": + main() +``` +***`output:`*** +```bash +The destination cell is found +The Path is +-> (8, 0) -> (7, 0) -> (6, 0) -> (5, 0) -> (4, 1) -> (3, 2) -> (2, 1) -> (1, 0) -> (0, 0) +``` + +- ***Time Complexity:*** O(E log V), where E is the number of edges and V is the number of vertices, due to the use of the priority queue. +- ***Auxiliary Space:*** O(V), where V is the number of vertices in the grid. + From 04d1c193f3be0847c2a2d643aff6107aa52146ff Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 07:36:55 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- A_star_searching_algorithm/A_star_search.py | 54 +++++++++++++++------ A_star_searching_algorithm/README.md | 4 +- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/A_star_searching_algorithm/A_star_search.py b/A_star_searching_algorithm/A_star_search.py index fb2fecbba638..b33a6c1b9794 100644 --- a/A_star_searching_algorithm/A_star_search.py +++ b/A_star_searching_algorithm/A_star_search.py @@ -7,15 +7,15 @@ class Cell: def __init__(self): - # Parent cell's row index + # Parent cell's row index self.parent_i = 0 - # Parent cell's column index + # Parent cell's column index self.parent_j = 0 - # Total cost of the cell (g + h) - self.f = float('inf') - # Cost from start to this cell - self.g = float('inf') - # Heuristic cost from this cell to destination + # Total cost of the cell (g + h) + self.f = float("inf") + # Cost from start to this cell + self.g = float("inf") + # Heuristic cost from this cell to destination self.h = 0 @@ -29,24 +29,28 @@ def __init__(self): def is_valid(row, col): return (row >= 0) and (row < ROW) and (col >= 0) and (col < COL) + # Check if a cell is unblocked def is_unblocked(grid, row, col): return grid[row][col] == 1 + # Check if a cell is the destination def is_destination(row, col, dest): return row == dest[0] and col == dest[1] + # Calculate the heuristic value of a cell (Euclidean distance to destination) def calculate_h_value(row, col, dest): return ((row - dest[0]) ** 2 + (col - dest[1]) ** 2) ** 0.5 + # Trace the path from source to destination @@ -57,7 +61,10 @@ def trace_path(cell_details, dest): col = dest[1] # Trace the path from destination to source using parent cells - while not (cell_details[row][col].parent_i == row and cell_details[row][col].parent_j == col): + while not ( + cell_details[row][col].parent_i == row + and cell_details[row][col].parent_j == col + ): path.append((row, col)) temp_row = cell_details[row][col].parent_i temp_col = cell_details[row][col].parent_j @@ -74,6 +81,7 @@ def trace_path(cell_details, dest): print("->", i, end=" ") print() + # Implement the A* search algorithm @@ -84,7 +92,9 @@ def a_star_search(grid, src, dest): return # Check if the source and destination are unblocked - if not is_unblocked(grid, src[0], src[1]) or not is_unblocked(grid, dest[0], dest[1]): + if not is_unblocked(grid, src[0], src[1]) or not is_unblocked( + grid, dest[0], dest[1] + ): print("Source or the destination is blocked") return @@ -125,14 +135,26 @@ def a_star_search(grid, src, dest): closed_list[i][j] = True # For each direction, check the successors - directions = [(0, 1), (0, -1), (1, 0), (-1, 0), - (1, 1), (1, -1), (-1, 1), (-1, -1)] + directions = [ + (0, 1), + (0, -1), + (1, 0), + (-1, 0), + (1, 1), + (1, -1), + (-1, 1), + (-1, -1), + ] for dir in directions: new_i = i + dir[0] new_j = j + dir[1] # If the successor is valid, unblocked, and not visited - if is_valid(new_i, new_j) and is_unblocked(grid, new_i, new_j) and not closed_list[new_i][new_j]: + if ( + is_valid(new_i, new_j) + and is_unblocked(grid, new_i, new_j) + and not closed_list[new_i][new_j] + ): # If the successor is the destination if is_destination(new_i, new_j, dest): # Set the parent of the destination cell @@ -150,7 +172,10 @@ def a_star_search(grid, src, dest): f_new = g_new + h_new # If the cell is not in the open list or the new f value is smaller - if cell_details[new_i][new_j].f == float('inf') or cell_details[new_i][new_j].f > f_new: + if ( + cell_details[new_i][new_j].f == float("inf") + or cell_details[new_i][new_j].f > f_new + ): # Add the cell to the open list heapq.heappush(open_list, (f_new, new_i, new_j)) # Update the cell details @@ -164,6 +189,7 @@ def a_star_search(grid, src, dest): if not found_dest: print("Failed to find the destination cell") + # Driver Code @@ -178,7 +204,7 @@ def main(): [1, 0, 1, 1, 1, 1, 0, 1, 0, 0], [1, 0, 0, 0, 0, 1, 0, 0, 0, 1], [1, 0, 1, 1, 1, 1, 0, 1, 1, 1], - [1, 1, 1, 0, 0, 0, 1, 0, 0, 1] + [1, 1, 1, 0, 0, 0, 1, 0, 0, 1], ] # Define the source and destination diff --git a/A_star_searching_algorithm/README.md b/A_star_searching_algorithm/README.md index 15b0160a8c6b..47ce84646371 100644 --- a/A_star_searching_algorithm/README.md +++ b/A_star_searching_algorithm/README.md @@ -255,8 +255,8 @@ if __name__ == "__main__": ***`output:`*** ```bash The destination cell is found -The Path is --> (8, 0) -> (7, 0) -> (6, 0) -> (5, 0) -> (4, 1) -> (3, 2) -> (2, 1) -> (1, 0) -> (0, 0) +The Path is +-> (8, 0) -> (7, 0) -> (6, 0) -> (5, 0) -> (4, 1) -> (3, 2) -> (2, 1) -> (1, 0) -> (0, 0) ``` - ***Time Complexity:*** O(E log V), where E is the number of edges and V is the number of vertices, due to the use of the priority queue. From 7893722aff455431ae7d18ad79fb944be3df23d0 Mon Sep 17 00:00:00 2001 From: Uday Date: Fri, 4 Oct 2024 13:22:56 +0530 Subject: [PATCH 3/4] A* Searching Algorithm Added with README file issue Resolved --- A_star_searching_algorithm/A_star_search.py | 35 ++++++++++++++------- A_star_searching_algorithm/__init__.py | 0 2 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 A_star_searching_algorithm/__init__.py diff --git a/A_star_searching_algorithm/A_star_search.py b/A_star_searching_algorithm/A_star_search.py index fb2fecbba638..fc004906f20c 100644 --- a/A_star_searching_algorithm/A_star_search.py +++ b/A_star_searching_algorithm/A_star_search.py @@ -1,12 +1,13 @@ # Python program for A* Search Algorithm import math import heapq +from typing import List, Tuple # Define the Cell class class Cell: - def __init__(self): + def __init__(self)->None: # Parent cell's row index self.parent_i = 0 # Parent cell's column index @@ -26,31 +27,31 @@ def __init__(self): # Check if a cell is valid (within the grid) -def is_valid(row, col): +def is_valid(row: int, col: int) -> bool: return (row >= 0) and (row < ROW) and (col >= 0) and (col < COL) # Check if a cell is unblocked -def is_unblocked(grid, row, col): +def is_unblocked(grid: List[List[int]], row: int, col: int) -> bool: return grid[row][col] == 1 # Check if a cell is the destination -def is_destination(row, col, dest): +def is_destination(row: int, col: int, dest: Tuple[int, int]) -> bool: return row == dest[0] and col == dest[1] # Calculate the heuristic value of a cell (Euclidean distance to destination) -def calculate_h_value(row, col, dest): +def calculate_h_value(row: int, col: int, dest: Tuple[int, int]) -> float: return ((row - dest[0]) ** 2 + (col - dest[1]) ** 2) ** 0.5 # Trace the path from source to destination -def trace_path(cell_details, dest): +def trace_path(cell_details: List[List[Cell]], dest: Tuple[int, int]) -> None: print("The Path is ") path = [] row = dest[0] @@ -77,7 +78,7 @@ def trace_path(cell_details, dest): # Implement the A* search algorithm -def a_star_search(grid, src, dest): +def a_star_search(grid: List[List[int]], src: Tuple[int, int], dest: Tuple[int, int]) -> None: # Check if the source and destination are valid if not is_valid(src[0], src[1]) or not is_valid(dest[0], dest[1]): print("Source or destination is invalid") @@ -167,7 +168,19 @@ def a_star_search(grid, src, dest): # Driver Code -def main(): +def main() -> None: + """ + Run the A* search algorithm on a predefined grid. + + Returns: + None + + Examples: + >>> main() + The destination cell is found + The Path is + -> (8, 0) -> (7, 1) -> (6, 0) -> (5, 1) -> (4, 0) -> (3, 1) -> (2, 0) -> (1, 1) -> (0, 0) + """ # Define the grid (1 for unblocked, 0 for blocked) grid = [ [1, 0, 1, 1, 1, 1, 0, 1, 1, 1], @@ -182,12 +195,12 @@ def main(): ] # Define the source and destination - src = [8, 0] - dest = [0, 0] + src = (8, 0) + dest = (0, 0) # Run the A* search algorithm a_star_search(grid, src, dest) - if __name__ == "__main__": main() + diff --git a/A_star_searching_algorithm/__init__.py b/A_star_searching_algorithm/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 From 13336677e11d0df97cbd83b3ec3bf847f1d8f4a1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 07:56:55 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- A_star_searching_algorithm/A_star_search.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/A_star_searching_algorithm/A_star_search.py b/A_star_searching_algorithm/A_star_search.py index 38faa7b5d075..18ea3a22f1c3 100644 --- a/A_star_searching_algorithm/A_star_search.py +++ b/A_star_searching_algorithm/A_star_search.py @@ -209,8 +209,8 @@ def main() -> None: Examples: >>> main() The destination cell is found - The Path is - -> (8, 0) -> (7, 1) -> (6, 0) -> (5, 1) -> (4, 0) -> (3, 1) -> (2, 0) -> (1, 1) -> (0, 0) + The Path is + -> (8, 0) -> (7, 1) -> (6, 0) -> (5, 1) -> (4, 0) -> (3, 1) -> (2, 0) -> (1, 1) -> (0, 0) """ # Define the grid (1 for unblocked, 0 for blocked) grid = [ @@ -234,4 +234,3 @@ def main() -> None: if __name__ == "__main__": main() -