def set_d_edges(self, idx): slice_edge = [Ed.DR, Ed.DF, Ed.DL, Ed.DB] other_edge = [Ed.FR, Ed.FL, Ed.BL, Ed.BR, Ed.UR, Ed.UF, Ed.UL, Ed.UB] b = idx % 24 # Permutation a = idx // 24 # Location for e in Ed: self.ep[e] = -1 # Invalidate all edge positions j = 1 # generate permutation from index b while j < 4: k = b % (j + 1) b //= j + 1 while k > 0: rotate_right(slice_edge, 0, j) k -= 1 j += 1 x = 4 # set slice edges for j in Ed: if a - c_nk(11 - j, x) >= 0: self.ep[j] = slice_edge[4 - x] a -= c_nk(11 - j, x) x -= 1 x = 0 # set the remaining edges UR..DB for j in Ed: if self.ep[j] == -1: self.ep[j] = other_edge[x] x += 1 for j in range(4): rotate_left(self.ep, 0, 11)
def get_ud_edges(self): """Get the permutation of the 8 U and D edges. ud_edges undefined in phase 1, 0 <= ud_edges < 40320 in phase 2, ud_edges = 0 for solved cube.""" perm = self.ep[0:8] # duplicate first 8 elements of ep b = 0 for j in range(Ed.DB, Ed.UR, -1): k = 0 while perm[j] != j: rotate_left(perm, 0, j) k += 1 b = (j + 1) * b + k return b
def get_corners(self): """Get the permutation of the 8 corners. 0 <= corners < 40320 defined but unused in phase 1, 0 <= corners < 40320 in phase 2, corners = 0 for solved cube""" perm = list(self.cp) # duplicate cp b = 0 for j in range(Co.DRB, Co.URF, -1): k = 0 while perm[j] != j: rotate_left(perm, 0, j) k += 1 b = (j + 1) * b + k return b
def get_slice_sorted(self): """Get the permutation and location of the UD-slice edges FR,FL,BL and BR. 0 <= slice_sorted < 11880 in phase 1, 0 <= slice_sorted < 24 in phase 2, slice_sorted = 0 for solved cube.""" a = x = 0 edge4 = [0] * 4 # First compute the index a < (12 choose 4) and the permutation array perm. for j in range(Ed.BR, Ed.UR - 1, -1): if Ed.FR <= self.ep[j] <= Ed.BR: a += c_nk(11 - j, x + 1) edge4[3 - x] = self.ep[j] x += 1 # Then compute the index b < 4! for the permutation in edge4 b = 0 for j in range(3, 0, -1): k = 0 while edge4[j] != j + 8: rotate_left(edge4, 0, j) k += 1 b = (j + 1) * b + k return 24 * a + b
def get_d_edges(self): """Get the permutation and location of the edges DR, DF, DL and DB. 0 <= d_edges < 11880 in phase 1, 0 <= d_edges < 1680 in phase 2, d_edges = 0 for solved cube.""" a = x = 0 edge4 = [0] * 4 ep_mod = self.ep[:] for j in range(4): rotate_right(ep_mod, 0, 11) # First compute the index a < (12 choose 4) and the permutation array perm. for j in range(Ed.BR, Ed.UR - 1, -1): if Ed.DR <= ep_mod[j] <= Ed.DB: a += c_nk(11 - j, x + 1) edge4[3 - x] = ep_mod[j] x += 1 # Then compute the index b < 4! for the permutation in edge4 b = 0 for j in range(3, 0, -1): k = 0 while edge4[j] != j + 4: rotate_left(edge4, 0, j) k += 1 b = (j + 1) * b + k return 24 * a + b