Open JanSkn opened 8 months ago
https://deniz.co/8-puzzle-solver/
Breadth-First Search (BFS) Depth-First Search (DFS) Iterative Deeping Search
example BFS:
from collections import deque
def bfs(src,target):
queue = deque([src])
visited_states = set()
while queue:
state = queue.popleft()
print("Visiting: ", state)
if state == target:
print("Found solution")
return
for move in possible_moves(state, visited_states):
if tuple(move) not in queue and tuple(move) not in visited_states:
queue.append(tuple(move))
visited_states.add(tuple(move))
print("No solution found.")
# Call the function
bfs(src = (1, 2, 3, 4, 5, 6, 7, 8, 0), target = (0, 1, 2, 3, 4, 5, 6, 7, 8))
hey, thank you! Do you want to adjust that to the GUI and open a PR? @levo-777
So far, there is Greedy and A* to solve the puzzle. Would be nice to add further algorithms.