-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmoves.py
117 lines (108 loc) · 4.68 KB
/
moves.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# ################### Movetables describe the transformation of the coordinates by cube moves. #########################
from os import path
import array as ar
import cubie as cb
import enums
from defs import N_TWIST, N_FLIP, N_SLICE_SORTED, N_CORNERS, N_MOVE
a = cb.CubieCube()
# ######################################### Move table for the twists of the corners. ##################################
# The twist coordinate describes the 3^7 = 2187 possible orientations of the 8 corners
# 0 <= twist < 2187
fname = "move_twist"
if not path.isfile(fname):
print("creating " + fname + " table...")
twist_move = ar.array('H', [0 for i in range(N_TWIST * N_MOVE)])
for i in range(N_TWIST):
a.set_twist(i)
for j in enums.Color: # six faces U, R, F, D, L, B
for k in range(3): # three moves for each face, for example U, U2, U3 = U'
a.corner_multiply(cb.basicMoveCube[j])
twist_move[N_MOVE * i + 3 * j + k] = a.get_twist()
a.corner_multiply(cb.basicMoveCube[j]) # 4. move restores face
fh = open(fname, "wb")
twist_move.tofile(fh)
else:
print("loading " + fname + " table...")
fh = open(fname, "rb")
twist_move = ar.array('H')
twist_move.fromfile(fh, N_TWIST * N_MOVE)
fh.close()
########################################################################################################################
# #################################### Move table for the flip of the edges. ##########################################
# The flip coordinate describes the 2^11 = 2048 possible orientations of the 12 edges
# 0 <= flip < 2048
fname = "move_flip"
if not path.isfile(fname):
print("creating " + fname + " table...")
flip_move = ar.array('H', [0 for i in range(N_FLIP * N_MOVE)])
for i in range(N_FLIP):
a.set_flip(i)
for j in enums.Color:
for k in range(3):
a.edge_multiply(cb.basicMoveCube[j])
flip_move[N_MOVE * i + 3 * j + k] = a.get_flip()
a.edge_multiply(cb.basicMoveCube[j])
fh = open(fname, "wb")
flip_move.tofile(fh)
else:
print("loading " + fname + " table...")
fh = open(fname, "rb")
flip_move = ar.array('H')
flip_move.fromfile(fh, N_FLIP * N_MOVE)
fh.close()
########################################################################################################################
# ###################### Move table for the four UD-slice edges FR, FL, Bl and BR. #####################################
# The slice_sorted coordinate describes the 12!/8! = 11880 possible positions of the FR, FL, BL and BR edges.
# 0 <= slice_sorted < 11880
fname = "move_slice_sorted"
if not path.isfile(fname):
print("creating " + fname + " table...")
slice_sorted_move = ar.array('H', [0 for i in range(N_SLICE_SORTED * N_MOVE)])
for i in range(N_SLICE_SORTED):
if i % 200 == 0:
print('.', end='', flush=True)
a.set_slice_sorted(i)
for j in enums.Color:
for k in range(3):
a.edge_multiply(cb.basicMoveCube[j])
slice_sorted_move[N_MOVE * i + 3 * j + k] = a.get_slice_sorted()
a.edge_multiply(cb.basicMoveCube[j])
fh = open(fname, "wb")
slice_sorted_move.tofile(fh)
print()
else:
print("loading " + fname + " table...")
fh = open(fname, "rb")
slice_sorted_move = ar.array('H')
slice_sorted_move.fromfile(fh, N_SLICE_SORTED * N_MOVE)
fh.close()
########################################################################################################################
# ########################################## Move table for the corners. ###############################################
# The corners coordinate describes the 8! = 40320 permutations of the corners.
# 0 <= corners < 40320
fname = "move_corners"
if not path.isfile(fname):
print("creating " + fname + " table...")
corners_move = ar.array('H', [0 for i in range(N_CORNERS * N_MOVE)])
for i in range(N_CORNERS):
if (i+1) % 200 == 0:
print('.', end='', flush=True)
if(i+1) % 16000 == 0:
print('')
a.set_corners(i)
for j in enums.Color:
for k in range(3):
a.corner_multiply(cb.basicMoveCube[j])
corners_move[N_MOVE * i + 3 * j + k] = a.get_corners()
a.corner_multiply(cb.basicMoveCube[j])
fh = open(fname, "wb")
corners_move.tofile(fh)
fh.close()
print()
else:
print("loading " + fname + " table...")
fh = open(fname, "rb")
corners_move = ar.array('H')
corners_move.fromfile(fh, N_CORNERS * N_MOVE)
fh.close()
########################################################################################################################