Skip to content

Instantly share code, notes, and snippets.

View ansharora28's full-sized avatar
:octocat:

Ansh Arora ansharora28

:octocat:
View GitHub Profile
import heapq
def a_star(graph, start, goal, heuristic):
open_list = [(0, start)] # Priority queue with initial node
came_from = {} # Dictionary to store parent nodes
g_score = {node: float('inf') for node in graph} # Initialize g_score to infinity for all nodes
g_score[start] = 0 # Cost from start to start is 0
while open_list:
_, current_node = heapq.heappop(open_list) # Pop node with lowest f_score