8 Puzzel
8 Puzzel
import heapq
while open_list:
_, g, current_state, path = heapq.heappop(open_list)
if is_goal(current_state):
return path
# Example usage:
start_state = [[1, 2, 3], [4, 0, 5], [7, 8, 6]] # Start state example
# Define the goal state
goal_state = [[1, 2, 3], [4, 5, 6], [7, 8, 0]]
print("Start State:")
print_state(start_state)
solution = a_star_search(start_state)
if solution:
print("Solution found!")
for step in solution:
print_state(step)
else:
print("No solution found!")
Output:
Start State:
[1, 2, 3]
[4, 0, 5]
[7, 8, 6]
Solution found!
[1, 2, 3]
[4, 5, 0]
[7, 8, 6]
[1, 2, 3]
[4, 5, 6]
[7, 8, 0]