def solve_case(self, cube, unsolved, print_debug=False): case = unsolved[0] steps = [] if case.source_face == 'up': steps.append(cube.get_simple_move( 'up', case.source_edge, case.dest_edge)) steps.append((case.dest_edge, 2)) elif case.source_face == 'down': steps.append((case.source_edge, 2)) steps.append(cube.get_simple_move( 'up', case.source_edge, case.dest_edge)) steps.append((case.dest_edge, 2)) elif case.source_edge == 'up': neighbors = Cube.cw_neighbor_edges('up') index = neighbors.index(case.dest_edge) dest_edge_offset = neighbors[(index + 1) % 4] steps.append(cube.get_simple_move( 'up', case.source_face, dest_edge_offset)) steps.append((dest_edge_offset, 1)) steps.append((case.dest_edge, 3)) steps.append((dest_edge_offset, 3)) else: face, times = cube.get_simple_move(case.source_face, case.source_edge, 'up') steps.append((face, times)) steps.append(('up', 1)) steps.append((face, -times % 4)) return steps
def find_unsolved(self, cube, print_debug=False): unsolved = [] for n in Cube.cw_neighbor_edges('up'): up_color = cube.get_color('up', n) if up_color != 'yellow': unsolved.append(Unsolved(n, 'up', None, 'up', n, None)) return unsolved
def move_with_y_rotation(move, num_rotations=1): num_rotations = num_rotations % 4 face, times = move if num_rotations == 0 or face == 'up' or face == 'down': return move up_cw_neighbor_edges = Cube.cw_neighbor_edges('up') new_face_index = (up_cw_neighbor_edges.index(face) - num_rotations) % 4 return (up_cw_neighbor_edges[new_face_index], times)
def find_unsolved(self, cube, print_debug=False): edges = [] edges.extend([('up', f) for f in Cube.cw_neighbor_edges('up')]) edges.extend([c for c in Cube.cw_corners_on_face('up')]) edges.extend([('down', f) for f in Cube.cw_neighbor_edges('down')]) unsolved = [] for f1, f2 in edges: color1 = cube.get_color(f1, f2) color2 = cube.get_color(f2, f1) dest_f1 = cube.get_dest_face(color1) dest_f2 = cube.get_dest_face(color2) already_solved = (f1 == dest_f1 and f2 == dest_f2) if not already_solved: assert f1 != 'down' and f2 != 'down' assert dest_f1 != 'down' and dest_f2 != 'down' if dest_f1 != 'up' and dest_f2 != 'up': unsolved.append(Unsolved(f1, f2, None, dest_f1, dest_f2, None)) def sorter(u, print_debug=False): if cube.is_cubie_in_layer((u.source_face, u.source_edge), 'up'): if u.source_face == 'up': non_up = u.source_edge non_up_dest = u.dest_edge else: non_up = u.source_face non_up_dest = u.dest_face if non_up == non_up_dest: return 0 # in top layer and aligned else: return 1 # in top layer but not aligned else: return 2 # not in top layer # NOTE: Sorting by the worst-case number of times "solve_case" must be # invoked to solve each cubie. unsolved.sort(key=sorter) return unsolved
def find_unsolved(self, cube, print_debug=False): unsolved = [] num_unsolved = 0 for n in Cube.cw_neighbor_edges('up'): non_up_color = cube.get_color(n, 'up') dest_face = cube.get_dest_face(non_up_color) if dest_face != n: num_unsolved += 1 unsolved.append(Unsolved(n, 'up', None, dest_face, 'up', None)) # either return all edges, or none of them if num_unsolved > 0: return unsolved else: return []
def find_unsolved(self, cube, print_debug=False): unsolved = [] for face in Cube.faces: for edge in Cube.cw_neighbor_edges(face): if cube.get_color(face, edge) == 'white': dest_face = 'down' other_color = cube.get_color(edge, face) dest_edge = cube.get_dest_face(other_color) if face != dest_face or edge != dest_edge: unsolved.append( Unsolved(face, edge, None, dest_face, dest_edge, None)) def sorter(u): if u.source_face == 'up': return 0 elif u.source_face == 'down': return 1 elif u.source_edge == 'up': return 2 elif u.source_edge != 'down': return 3 else: return 4 unsolved.sort(key=sorter) return unsolved