-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcube_utils.py
More file actions
102 lines (93 loc) · 2.65 KB
/
Copy pathcube_utils.py
File metadata and controls
102 lines (93 loc) · 2.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from manim.constants import *
def get_type_of_cubie(dim, position):
if (position[1] == 0 or position[1] == dim - 1) and (
position[2] == 0 or position[2] == dim - 1
):
return "corner"
elif position[1] == 0 or position[1] == dim - 1:
return "edge"
else:
return "center"
# DOWN = IN
# OUT = RIGHT
# LEFT = UP
# UP = OUT
# RIGHT = DOWN
# IN = LEFT
def get_faces_of_cubie(dim, position):
dim = dim - 1
try:
faces = {
# Front corners
(0, 0, 0): [LEFT, DOWN, IN],
(0, 0, dim): [LEFT, DOWN, OUT],
(0, dim, 0): [LEFT, UP, IN],
(0, dim, dim): [LEFT, UP, OUT],
# Back corners
(dim, 0, 0): [RIGHT, DOWN, IN],
(dim, 0, dim): [RIGHT, DOWN, OUT],
(dim, dim, 0): [RIGHT, UP, IN],
(dim, dim, dim): [RIGHT, UP, OUT],
}
return faces[position]
except:
x = position[0]
y = position[1]
z = position[2]
if x == 0:
if y == 0:
return [DOWN, LEFT]
elif y == dim:
return [UP, LEFT]
else:
if z == 0:
return [IN, LEFT]
elif z == dim:
return [OUT, LEFT]
else:
return [LEFT]
elif x == dim:
if y == 0:
return [DOWN, RIGHT]
elif y == dim:
return [UP, RIGHT]
else:
if z == 0:
return [IN, RIGHT]
elif z == dim:
return [OUT, RIGHT]
else:
return [RIGHT]
else:
if y == 0:
if z == 0:
return [IN, DOWN]
elif z == dim:
return [OUT, DOWN]
else:
return [DOWN]
elif y == dim:
if z == 0:
return [IN, UP]
elif z == dim:
return [OUT, UP]
else:
return [UP]
else:
if z == 0:
return [IN]
elif z == dim:
return [OUT]
else:
return []
def parse_move(move):
face = move[0]
assert face in "FUBLRD"
# Try parsing moves like F2 or even F8
try:
n_turns = int(move[1])
except (IndexError, ValueError):
# If the string is too short, or move[1] is not a number
n_turns = 1
n_turns = -n_turns if "'" in move else n_turns
return face, n_turns