def find_unsolved(self, cube, print_debug=False): unsolved = [] for dest_edge, dest_edge2 in Cube.cw_corners_on_face('up'): #print dest_edge, dest_edge2 if cube.get_color('up', dest_edge, dest_edge2) != 'yellow': corner_neighbors = Cube.cw_neighbor_corners( ('up', dest_edge, dest_edge2)) #print corner_neighbors colors = [cube.get_color(face, edge, edge2) for face, edge, edge2 in corner_neighbors] #print colors yellow_index = colors.index('yellow') assert yellow_index == 1 or yellow_index == 2 yellow_corner = corner_neighbors[yellow_index] unsolved.append(Unsolved( yellow_corner[0], yellow_corner[1], yellow_corner[2], 'up', dest_edge, dest_edge2)) return unsolved
def find_unsolved(self, cube, print_debug=False): #print "Finding unsolved " + self.__class__.__name__ unsolved = [] for face in Cube.faces: for edge, edge2 in Cube.cw_corners_on_face(face): if cube.get_color(face, edge, edge2) == 'white': dest_face = 'down' other_color = cube.get_color(edge, face, edge2) dest_edge = cube.get_dest_face(other_color) other_color2 = cube.get_color(edge2, face, edge) dest_edge2 = cube.get_dest_face(other_color2) already_solved = Cube.corners_equal( \ (face, edge, edge2), (dest_face, dest_edge, dest_edge2)) if not already_solved: new_case = Unsolved(face, edge, edge2, dest_face, dest_edge, dest_edge2) #print new_case unsolved.append(new_case) def sorter(u): source_cubie = (u.source_face, u.source_edge, u.source_edge2) dest_cubie = (u.dest_face, u.dest_edge, u.dest_edge2) if cube.is_cubie_in_layer(source_cubie, 'up'): assert dest_cubie[0] == 'down' cubie_above_dest = ('up', u.dest_edge, u.dest_edge2) if u.source_face != 'up': if Cube.same_cubie(source_cubie, cubie_above_dest): return 0 else: return 1 else: if Cube.same_cubie(source_cubie, cubie_above_dest): return 2 else: return 3 else: return 4 unsolved.sort(key=sorter) return unsolved
def find_unsolved(self, cube, print_debug=False): unsolved = [] num_unsolved = 0 for edge, edge2 in Cube.cw_corners_on_face('up'): color_edge = cube.get_color(edge, edge2, 'up') color_edge2 = cube.get_color(edge2, edge, 'up') dest_edge = cube.get_dest_face(color_edge) dest_edge2 = cube.get_dest_face(color_edge2) if edge != dest_edge and edge2 != dest_edge2: num_unsolved += 1 else: assert edge == dest_edge and edge2 == dest_edge2 unsolved.append(Unsolved( 'up', edge, edge2, 'up', dest_edge, dest_edge2)) # return either all edges or none if num_unsolved > 0: return unsolved else: return []
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