-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8puzzleProblm.py
81 lines (61 loc) · 2.24 KB
/
8puzzleProblm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Written by
# Seyyed Ali Shohadaalhosseini
# We'll never forget that:
# < What doesn't kill you makes you STRONGER >
import AISearchAlgorithm
Search = AISearchAlgorithm.SearchAlgorithm()
# easy level at finding answer
initialState = [
[1, 2, 3],
[7, 8, " "],
[6, 5, 4]
]
# astar finds path at 108th state
# medium level at finding answer
# initialState = [
# [1, 2, 3],
# [7, " ", 8],
# [6, 5, 4]
# ]
# This can not be found easily
# very hard level at finding answer
# initialState = [
# [1, 2, 3],
# [6, " ", 4],
# [7, 8, 5]
# ]
GoalState = [
[1, 2, 3],
[8, " ", 4],
[7, 6, 5]
]
ans = "y"
while ans == "y":
WhichAlgorithm = input("""Enter one of the name below to search with the default parameters: \n
Enter DFS as Depth First Search\n
Enter BFS as Breadth First Search\n
Enter DLS as Depth Limited Search\n
Enter IDS as Iterative Deepening Search\n
Enter UCS as Uniform Cost Search\n
Enter ASTAR as A Star Search\n
Enter GREEDY as Greedy Search\n
Enter HILL as Hill Climbing Search: \n
Enter the name here: """).lower()
if WhichAlgorithm == "DFS".lower():
print(Search.searchDFS(initialState, GoalState))
elif WhichAlgorithm == "BFS".lower():
print(Search.searchBFS(initialState, GoalState))
elif WhichAlgorithm == "DLS".lower():
deeplimit = int(input("Enter the depth limitation: "))
print(Search.searchDLS(initialState, GoalState, deeplimit), sep=" === > \n\n")
elif WhichAlgorithm == "IDS".lower():
print(Search.searchIDS(initialState, GoalState), sep=" === > \n\n")
elif WhichAlgorithm == "UCS".lower():
print(Search.searchUCS(initialState, GoalState), sep=" === > \n\n")
elif WhichAlgorithm == "ASTAR".lower():
print(Search.searchAstar(initialState, GoalState), sep=" === > \n\n")
elif WhichAlgorithm == "GREEDY".lower():
print(Search.searchGreedy(initialState, GoalState), sep=" === > \n\n")
elif WhichAlgorithm == "HILL".lower():
print(Search.searchHillClimbing(initialState, GoalState), sep=" === > \n\n")
ans = input("Do you want to continue ? y/n ")