def _cross_left_or_right(self, edge_piece, face_piece, face_color, move_1, move_2): # don't do anything if piece is in correct place if (edge_piece.pos == (face_piece.pos.x, face_piece.pos.y, 1) and edge_piece.colors[2] == self.cube.front_color()): return # ensure piece is at z = -1 undo_move = None if edge_piece.pos.z == 0: pos = Point(edge_piece.pos) pos.x = 0 # pick the UP or DOWN face cw, cc = cube.get_rot_from_face(pos) if edge_piece.pos in (cube.LEFT + cube.UP, cube.RIGHT + cube.DOWN): self.move(cw) undo_move = cc else: self.move(cc) undo_move = cw elif edge_piece.pos.z == 1: pos = Point(edge_piece.pos) pos.z = 0 cw, cc = cube.get_rot_from_face(pos) self.move("{0} {0}".format(cc)) # don't set the undo move if the piece starts out in the right position # (with wrong orientation) or we'll screw up the remainder of the algorithm if edge_piece.pos.x != face_piece.pos.x: undo_move = "{0} {0}".format(cw) assert edge_piece.pos.z == -1 # piece is at z = -1, rotate to correct face (LEFT or RIGHT) count = 0 while (edge_piece.pos.x, edge_piece.pos.y) != (face_piece.pos.x, face_piece.pos.y): self.move("B") count += 1 if count == 10: raise Exception("Stuck in loop - unsolvable cube?\n" + str(self.cube)) # if we moved a correctly-placed piece, restore it if undo_move: self.move(undo_move) # the piece is on the correct face on plane z = -1, but has two orientations if edge_piece.colors[0] == face_color: self.move(move_1) else: self.move(move_2)
def _cross_left_or_right(self, edge_piece, face_piece, face_color, move_1, move_2): if (edge_piece.pos == (face_piece.pos.x, face_piece.pos.y, 1) and edge_piece.colors[2] == self.cube.front_color()): return undo_move = None if edge_piece.pos.z == 0: pos = Point(edge_piece.pos) pos.x = 0 cw, cc = cube.get_rot_from_face(pos) if edge_piece.pos in (cube.LEFT + cube.UP, cube.RIGHT + cube.DOWN): self.move(cw) undo_move = cc else: self.move(cc) undo_move = cw elif edge_piece.pos.z == 1: pos = Point(edge_piece.pos) pos.z = 0 cw, cc = cube.get_rot_from_face(pos) self.move("{0} {0}".format(cc)) # don't set the undo move if the piece starts out in the right position if edge_piece.pos.x != face_piece.pos.x: undo_move = "{0} {0}".format(cw) assert edge_piece.pos.z == -1 #rotate to correct face (LEFT or RIGHT) count = 0 while (edge_piece.pos.x, edge_piece.pos.y) != (face_piece.pos.x, face_piece.pos.y): self.move("B") count += 1 if count == 10: raise Exception("Stuck in loop - unsolvable cube?\n" + str(self.cube)) # if we moved a correctly-placed piece, restore it if undo_move: self.move(undo_move) if edge_piece.colors[0] == face_color: self.move(move_1) else: self.move(move_2)