Код: Выделить всё
while frontier:
# get a node from frontier with minimum cost
last_node = cur_node # storing last node
min_cost = float('inf')
for s in frontier:
if s.cost < min_cost:
min_cost = s.cost
cur_node = s
# Coloring the roads taken
if cur_node.prev !=None:
color_roads(maze,cur_node)
# check if goal is true
if(isColored(maze)):
print("PREV NODES")
node = cur_node
while node != None:
print(node.row,node.col)
node = node.prev
break
# add each viable succesor of current node to the frontier
find_successors(maze,frontier,visited,cur_node)
# pop itself
frontier.remove(cur_node)
visited.append(cur_node)
Код: Выделить всё
def find_successors(maze,frontier,visited,node):
row_lim = len(maze) -1
col_lim = len(maze[0]) -1
directions = [[0,1],[0,-1],[1,0],[-1,0]] #right left down up
for a,b in directions:
r = node.row
c = node.col
while 0
Подробнее здесь: [url]https://stackoverflow.com/questions/78171307/color-maze-with-a-search[/url]