-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (57 loc) · 1.65 KB
/
Copy pathmain.py
File metadata and controls
70 lines (57 loc) · 1.65 KB
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
from magiccube import Cube
from backend.Solvers.astar.astar import ida_star, search
from backend.Solvers.astar.helpers import *
from backend.utils import *
# Setup cube
cube = Cube(3, "WWWWWWWWWOOOOOOOOOGGGGGGGGGRRRRRRRRRBBBBBBBBBYYYYYYYYY")
cube.scramble(2)
scrambled_cube = get_cube_str(cube)
# First stage
path, counter, depth = ida_star(
cube,
heuristic_fn=heuristic_EO,
create_children_fn=get_children_scrambled,
maxdepth=13,
is_goal_fn=is_goal_eo,
)
solution1 = [node.action for node in path]
solution1.pop(0)
print(solution1)
for move in solution1:
cube.rotate(move)
# Second state
eo_cube = get_cube_str(cube)
path, counter, depth = ida_star(
cube,
heuristic_fn=heuristic_DR,
create_children_fn=get_children_eo,
maxdepth=11,
is_goal_fn=is_goal_dr,
)
solution2 = [node.action for node in path]
solution2.pop(0)
print(solution2)
for move in solution2:
cube.rotate(move)
# Final state
dr_cube = get_cube_str(cube)
path, counter, depth = ida_star(
cube,
heuristic_fn=heuristic_solved,
create_children_fn=get_children_dr,
maxdepth=11,
is_goal_fn=is_goal_solved_cube,
)
solution3 = [node.action for node in path]
solution3.pop(0)
print(solution3)
for move in solution3:
cube.rotate(move)
# solution1, solution2, solution3 = ["Joe"], ["Joe"], ["Joe"]
# eo_cube, dr_cube = ["mama"], ["Joe"]
with open("Saved_solution", "w", encoding="UTF-8") as file:
file.write("----------------")
file.write(f"First stage: {scrambled_cube}, {solution1}\n")
file.write(f"Second stage: {eo_cube}, {solution2}\n")
file.write(f"Final stage: {dr_cube}, {solution3}\n")
file.write("----------------")