def symmetries(state): x_symmetry = perm.Permutation(19)(1, 3)(5, 7)(13, 15) y_symmetry = perm.Permutation(0, 2)(4, 6)(8, 9)(10, 11)(17, 19) def x_flip(state): for piece in state: if piece == 'R': piece = 'L' elif piece == 'L': piece = 'R' return state def y_flip(state): for piece in state: if piece == 'F': piece = 'B' elif piece == 'B': piece = 'F' return state x_state = x_symmetry(x_flip(state)) y_state = y_symmetry(y_flip(state)) xy_state = x_symmetry(y_symmetry(state)) return state, x_state, y_state, xy_state
def lse_scr(): corners = random.choice(range(4)) if corners == 1 or corners == 3: permn = random.choice(o_6) else: permn = random.choice(a_6) flip = random.choice(range(4)) orient = random.sample(range(6), flip*2) m2 = random.choice(range(2)) LSE_pieces = np.array([[1, 37], [3, 10], [7, 19], [5, 28], [46, 25], [52, 43]]) LSE_pieces_new = LSE_pieces for i in orient: LSE_pieces_new[i] = perm.Permutation(0,1)(LSE_pieces[i]) LSE_pieces_new = permn(LSE_pieces_new) edge_perm_list = perm.Permutation(53).list() for i in range(12): edge_perm_list[np.asarray(LSE_pieces).reshape(12)[i]] = np.asarray(LSE_pieces_new).reshape(12)[i] scramble_perm = perm.Permutation(11,20,29,38)(6,8,2,0)(18,27,36,9)**corners*perm.Permutation(edge_perm_list) cube = scramble_perm(SOLVED_CUBE) if m2 == 1: cube = M2(cube) return(cube)
def _generate_mu_moves(): U = perm.Permutation(19)(1, 2, 3, 0)(5, 6, 7, 4)(12, 13, 14, 15) U2 = U * U Up = U2 * U M = perm.Permutation(0, 6, 8, 11)(2, 10, 9, 4)(16, 17, 18, 19) M2 = M * M Mp = M2 * M return [U, U2, Up, M, M2, Mp]
def _generate_mu_moves(): U = perm.Permutation(19)(1, 2, 3, 0)(5, 6, 7, 4)(12, 13, 14, 15) U2 = U * U Up = U2 * U M = perm.Permutation(0, 6, 8, 11)(2, 10, 9, 4)(16, 17, 18, 19) M2 = M * M Mp = M2 * M return [U, "U"], [U2, "U2"], [Up, "U'"], [M, "M"], [M2, "M2"], [Mp, "M'"]
def LSE_scramble(self): self.cube = SOLVED_CUBE corners = random.choice(range(4)) if corners == 1 or corners == 3: permn = random.choice(o_6) else: permn = random.choice(a_6) flip = random.choice(range(4)) orient = random.sample(range(6), flip * 2) m2 = random.choice(range(2)) LSE_pieces = np.array([[1, 37], [3, 10], [7, 19], [5, 28], [46, 25], [52, 43]]) LSE_pieces_new = LSE_pieces for i in orient: LSE_pieces_new[i] = perm.Permutation(0, 1)(LSE_pieces[i]) LSE_pieces_new = permn(LSE_pieces_new) edge_perm_list = perm.Permutation(53).list() for i in range(12): edge_perm_list[np.asarray(LSE_pieces).reshape(12)[i]] = np.asarray( LSE_pieces_new).reshape(12)[i] scramble_perm = perm.Permutation(11, 20, 29, 38)(6, 8, 2, 0)( 18, 27, 36, 9)**corners * perm.Permutation(edge_perm_list) self.cube = scramble_perm(self.cube) if m2 == 1: self.cube = M2(self.cube) order = scramble_perm.order() inv_scramble = (scramble_perm**(order - 2))(self.cube) empty = "" # scramble = ida_lse(full_to_mu(self.cube)) non_M2_scramble = utils.solve(empty.join(inv_scramble), "Kociemba") M2_scramble = [] if m2 == 1: for mv in non_M2_scramble + ["M2"]: M2_scramble.append( mv) # couldn't directly append M2 so did it this way self.cube = M2(self.cube) else: M2_scramble = non_M2_scramble self.print_cube() self.scramble.set(M2_scramble)
def generate_moves(): """ This function generates the permutations representing the moves of faces or slices performed on the cube, eg. U, F', M2. These permutations can then be applied to a generated cube. """ y2 = DEFAULT_CUBE M2 = DEFAULT_CUBE M = DEFAULT_CUBE Mp = DEFAULT_CUBE U = DEFAULT_CUBE U2 = DEFAULT_CUBE Up = DEFAULT_CUBE for cubelet in range(9): y2 = y2 * perm.Permutation(cubelet, cubelet + 45) # Swaps U and D faces for cubelet in range(4): y2 = y2 * perm.Permutation(cubelet + 27, 35 - cubelet) # Rotates R face y2 = y2 * perm.Permutation(cubelet + 9, 17 - cubelet) # Rotates L face for cubelet in range(3): y2 = y2 * perm.Permutation(cubelet + 18, 44 - cubelet) # Puts FU* to BD* y2 = y2 * perm.Permutation(cubelet + 21, 41 - cubelet) # Puts FE* to BE* y2 = y2 * perm.Permutation(cubelet + 24, 38 - cubelet) # Puts FD* to BU* for cubelet in [1, 4, 7]: M = M * perm.Permutation(cubelet, 44 - cubelet, cubelet + 45, cubelet + 18) # UM -> FM -> DM -> BM U = perm.Permutation(53)(0, 2, 8, 6)(1, 5, 7, 3) # Rotates U face for cubelet in [9, 10, 11]: U = U * perm.Permutation(cubelet, cubelet + 9, cubelet + 18, cubelet + 27) # FU -> LU -> BU -> RU M2 = M * M Mp = M2 * M U2 = U * U Up = U2 * U return [y2, M, M2, Mp, U, U2, Up]
def generate_moves(): M2 = DEFAULT_CUBE M = DEFAULT_CUBE Mp = DEFAULT_CUBE U = DEFAULT_CUBE U2 = DEFAULT_CUBE Up = DEFAULT_CUBE for cubelet in [1,4,7]: M = M *perm.Permutation(cubelet, 44-cubelet, cubelet+45, cubelet+18) # UM -> FM -> DM -> BM U = perm.Permutation(53)(0,2,8,6)(1,5,7,3) #Rotates U face for cubelet in [9,10,11]: U = U *perm.Permutation(cubelet, cubelet+9, cubelet+18, cubelet+27) # FU -> LU -> BU -> RU M2 = M*M Mp = M2*M U2 = U*U Up = U2*U return(M2, M, Mp, U, U2, Up)
def domain(rips, simp_dict, mapped_pts): """Return the complete filtration of domains from the given filtration of complexes and list of mapped vertices. Parameters: rips -- as in the function rips_complex simp_dict -- as in the function rips_complex mapped_pts -- as in the function mapped_points Return: domain_filtration -- a list of pairs (ordered simplex, minimal domain filtration index) sorted by increasing minimal domain filtration index, followed by increasing dimension of simplices mapped_simp -- a dictionary: key = ordered simplex, value = (mapped simplex, signature : 1 or -1, collapse : Bool) signature tells us if we preserve or reverse orientation of the simplex collapse tells us if the mapped simplex collapses in dimension domain_dict -- a dictionary, key = ordered simplex, value = minimal domain filtration index """ mapped_simp = dict() domain_dict = dict() domain_filtration = [] for (index, simp) in rips: image = [] collapse = False for i in range(len(simp)): if mapped_pts[simp[i]] not in image: image.append(mapped_pts[simp[i]]) else: collapse = True image = sorted(list(enumerate(image)), key=lambda x: (x[1], x[0])) image_simp = tuple([s for (_, s) in image]) permutation = tuple([i for (i, _) in image]) mapped_simp[simp] = (image_simp, sp.Permutation(permutation).signature(), collapse) domain_index = max(simp_dict[simp], simp_dict[image_simp]) domain_dict[simp] = domain_index domain_filtration.append((domain_index, simp)) return sorted(domain_filtration, key=lambda x: (x[0], len(x[1]), x[1])), mapped_simp, domain_dict
""" import random from tkinter.colorchooser import askcolor import numpy as np import sympy.combinatorics.permutations as perm import sympy.combinatorics.generators as gens from mu_scramble_gen import ida_lse from gen_transformations import mu_to_full, full_to_mu from tkinter import * from rubik_solver import utils COLOUR_NAMES = ["Y", "B", "R", "G", "O", "W"] FACE_DICT = {"U": "Y", "L": "B", "F": "R", "R": "G", "B": "O", "D": "W"} DEFAULT_CUBE = perm.Permutation(53) SOLVED_CUBE = [] for colour in COLOUR_NAMES: for cubie in range(9): SOLVED_CUBE.append(colour) DEFAULT_PERM = perm.Permutation(53) def generate_moves(): """ This function generates the permutations representing the moves of faces or slices performed on the cube, eg. U, F', M2. These permutations can then be applied to a generated cube. """ y2 = DEFAULT_CUBE M2 = DEFAULT_CUBE
Up = DEFAULT_CUBE for cubelet in [1,4,7]: M = M *perm.Permutation(cubelet, 44-cubelet, cubelet+45, cubelet+18) # UM -> FM -> DM -> BM U = perm.Permutation(53)(0,2,8,6)(1,5,7,3) #Rotates U face for cubelet in [9,10,11]: U = U *perm.Permutation(cubelet, cubelet+9, cubelet+18, cubelet+27) # FU -> LU -> BU -> RU M2 = M*M Mp = M2*M U2 = U*U Up = U2*U return(M2, M, Mp, U, U2, Up) def generate_groups(): a_6 = list(gens.alternating(6)) o_6 = [x for x in list(gens.symmetric(6)) if x not in a_6] return(a_6, o_6) DEFAULT_CUBE = perm.Permutation(53) COLOUR_NAMES = ["Y","B","R","G","O","W"] SOLVED_CUBE = [] for colour in COLOUR_NAMES: for cubie in range(9): SOLVED_CUBE.append(colour) a_6, o_6 = generate_groups() M2, M, Mp, U, U2, Up = generate_moves()