Пример #1
0
 def get_fake_555(self):
     if self.fake_555 is None:
         self.fake_555 = RubiksCube555(solved_555, 'URFDLB')
         self.fake_555.lt_init()
         self.fake_555.enable_print_cube = False
     else:
         self.fake_555.re_init()
     return self.fake_555
Пример #2
0
def lr_centers_555() -> None:
    filename_nn = "cube.csv"
    cube = RubiksCube555(solved_555, "URFDLB")
    cube.cpu_mode = "normal"
    cube.lt_init()
    cube.re_init()
    pt_count = len(cube.lt_LR_centers_stage.prune_tables)

    BATCH_SIZE = 10
    to_write = []
    to_write_count = 0
    original_state = cube.state[:]

    with open(filename_nn, "w") as fh_nn:
        fh_nn.write(",".join([f"PT{x}" for x in range(pt_count)]))
        fh_nn.write(",COST\n")

        # solve 10000 random cubes
        for x in range(10000):
            cube.state = original_state[:]
            cube.randomize()
            cube.solution = []

            cube.lt_LR_centers_stage.solve_via_c()
            logger.info(cube.solve_via_c_output)
            in_table = False

            for line in cube.solve_via_c_output.splitlines():
                if line.startswith("       ===  ===  ===  ===  ==="):
                    in_table = True

                elif in_table:
                    if line:
                        line = line.strip().split()
                        cost_to_goal = line[-2]

                        if cost_to_goal != "0":
                            nn_line = line[1:pt_count + 1]
                            nn_line.append(cost_to_goal)
                            to_write.append(",".join(nn_line))
                            to_write_count += 1

                    else:
                        in_table = False
                        break

            if to_write_count >= BATCH_SIZE:
                fh_nn.write("\n".join(to_write) + "\n")
                fh_nn.flush()
                to_write = []
                to_write_count = 0

        if to_write_count:
            fh_nn.write("\n".join(to_write) + "\n")
            fh_nn.flush()
            to_write = []
            to_write_count = 0
    def group_centers_guts(self):
        self.lt_init()
        self.group_centers_stage_UD()

        self.lt_LR_inner_x_centers_stage.solve()
        log.info("LR inner x-center staged, %d steps in" % self.get_solution_len_minus_rotates(self.solution))

        self.lt_LR_oblique_edge_pairing.solve()
        log.info("LR oblique edges paired, %d steps in" % self.get_solution_len_minus_rotates(self.solution))
        log.info("")
        log.info("")
        log.info("")
        log.info("")
        log.info("")

        # Reduce the centers to 5x5x5 centers
        # - solve the UD inner x-centers and pair the UD oblique edges
        # - solve the LR inner x-centers and pair the LR oblique edges
        # - solve the FB inner x-centers and pair the FB oblique edges
        self.lt_UD_solve_inner_x_centers_and_oblique_edges.solve()
        log.info("UD inner x-center solved, %d steps in" % self.get_solution_len_minus_rotates(self.solution))

        self.lt_LR_solve_inner_x_centers_and_oblique_edges.solve() # speed up IDA
        log.info("LR inner x-center and oblique edges prune table solved, %d steps in" % self.get_solution_len_minus_rotates(self.solution))

        self.lt_LFRB_solve_inner_x_centers_and_oblique_edges.solve()
        log.info("LFRB inner x-center and oblique edges paired, %d steps in" % self.get_solution_len_minus_rotates(self.solution))
        self.print_cube()
        log.info("")
        log.info("")
        log.info("")
        log.info("")
        log.info("")

        # At this point the 6x6x6 centers have been reduced to 5x5x5 centers
        fake_555 = RubiksCube555(solved_5x5x5, 'URFDLB')
        fake_555.lt_init()
        self.populate_fake_555_for_ULFRBD(fake_555)
        fake_555.group_centers_guts()

        for step in fake_555.solution:
            self.rotate(step)

        log.info("Took %d steps to solve centers" % self.get_solution_len_minus_rotates(self.solution))
 def get_fake_555(self):
     if self.fake_555 is None:
         if self.fake_777 and self.fake_777.fake_555:
             self.fake_555 = self.fake_777.fake_555
             self.fake_555.cpu_mode = self.cpu_mode
             self.fake_555.re_init()
             self.fake_555.enable_print_cube = False
         else:
             # Because our centers are already solved we get very little benefit
             # from using the more advanced 555 edge pairing code path...and it
             # takes much longer to run.  For now use the old L4E way it is only
             # about 1 move longer if the centers are solved but runs 3x faster.
             self.fake_555 = RubiksCube555(solved_555, "URFDLB")
             self.fake_555.cpu_mode = self.cpu_mode
             self.fake_555.lt_init()
             self.fake_555.enable_print_cube = False
     else:
         self.fake_555.re_init()
     return self.fake_555
Пример #5
0
def stage_centers_555(cube_count: int, move_count: int, batch_size: int,
                      filename: str) -> None:
    cube = RubiksCube555(solved_555, "URFDLB")
    cube.cpu_mode = "normal"
    cube.lt_init()
    cube.re_init()
    original_state = cube.state[:]

    with open(filename, "w") as fh_nn:  # noqa: F841
        # fh_nn.write(",".join([f"PT{x}" for x in range(pt_count)]))
        # fh_nn.write(",COST\n")

        # scramble CUBE_COUNT cubes up to MOVE_COUNT random moves
        for x in range(cube_count):
            cube.state = original_state[:]

            for y in range(move_count):
                cube.randomize(count=1)

            cube.print_cube()
Пример #6
0
def print_symmetry_swaps(size):
    order = 'ULFRBD'

    if size == 2:
        cube = RubiksCube222(solved_222, 'URFDLB')
        rotate_xxx = rotate_222
    elif size == 3:
        cube = RubiksCube333(solved_333, 'URFDLB')
        rotate_xxx = rotate_333
    elif size == 4:
        cube = RubiksCube444(solved_444, 'URFDLB')
        rotate_xxx = rotate_444
    elif size == 5:
        cube = RubiksCube555(solved_555, 'URFDLB')
        rotate_xxx = rotate_555
    elif size == 6:
        cube = RubiksCube666(solved_666, 'URFDLB')
        rotate_xxx = rotate_666
    elif size == 7:
        cube = RubiksCube777(solved_777, 'URFDLB')
        rotate_xxx = rotate_777
    else:
        assert False

    for (index, _) in enumerate(cube.state):
        cube.state[index] = str(index)

    orig_state = cube.state[:]
    cube.print_cube()

    for seq in symmetry_48:
        cube.state = orig_state[:]
        seq_str = ' '.join(seq)

        if seq_str in ("", "x", "x'", "y", "y'", "z", "z'"):
            continue

        for step in seq:
            cube.state = rotate_xxx(cube.state[:], step)

        print('    "%s" : (%s),' % (' '.join(seq), ', '.join(cube.state)))
Пример #7
0
        from rubikscubennnsolver.RubiksCube444 import RubiksCube444, solved_444
        cube = RubiksCube444(args.state,
                             args.order,
                             args.colormap,
                             avoid_pll=True,
                             debug=args.debug)
    elif size == 5:
        from rubikscubennnsolver.RubiksCube555 import solved_555

        if cpu_mode == "fast":
            from rubikscubennnsolver.RubiksCube555ForNNN import RubiksCube555ForNNN
            cube = RubiksCube555ForNNN(args.state, args.order, args.colormap,
                                       args.debug)
        else:
            from rubikscubennnsolver.RubiksCube555 import RubiksCube555
            cube = RubiksCube555(args.state, args.order, args.colormap,
                                 args.debug)

    elif size == 6:
        from rubikscubennnsolver.RubiksCube666 import RubiksCube666
        cube = RubiksCube666(args.state, args.order, args.colormap, args.debug)
    elif size == 7:
        from rubikscubennnsolver.RubiksCube777 import RubiksCube777
        cube = RubiksCube777(args.state, args.order, args.colormap, args.debug)
    elif size % 2 == 0:
        from rubikscubennnsolver.RubiksCubeNNNEven import RubiksCubeNNNEven
        cube = RubiksCubeNNNEven(args.state, args.order, args.colormap,
                                 args.debug)
    else:
        from rubikscubennnsolver.RubiksCubeNNNOdd import RubiksCubeNNNOdd
        cube = RubiksCubeNNNOdd(args.state, args.order, args.colormap,
                                args.debug)
    level=logging.INFO,
    format="%(asctime)s %(filename)20s %(levelname)8s: %(message)s")
log = logging.getLogger(__name__)

filename = sys.argv[1]

with open(filename, "r") as fh:

    if "2x2x2" in filename:
        cube = RubiksCube222(solved_222, "URFDLB")
    elif "3x3x3" in filename:
        cube = RubiksCube333(solved_333, "URFDLB")
    elif "4x4x4" in filename:
        cube = RubiksCube444(solved_444, "URFDLB")
    elif "5x5x5" in filename:
        cube = RubiksCube555(solved_555, "URFDLB")
    elif "6x6x6" in filename:
        cube = RubiksCube666(solved_666, "URFDLB")
    elif "7x7x7" in filename:
        cube = RubiksCube777(solved_777, "URFDLB")
    else:
        raise Exception("What size cube?")

    for line in fh:
        (state, steps_to_solve) = line.strip().split(":")
        cube.re_init()
        cube.nuke_corners()
        # cube.nuke_edges()
        # cube.nuke_centers()
        steps_to_solve = steps_to_solve.split()
        steps_to_scramble = reverse_steps(steps_to_solve)
Пример #9
0
    def pair_edge_orbit_via_555(self, orbit):
        log.info("%s: pair_edge_orbit_via_555 for %d" % (self, orbit))
        fake_555 = RubiksCube555(solved_555, 'URFDLB')
        fake_555.lt_init()

        # Fill in the corners so we can avoid certain types of parity
        start_555 = 0
        start_nnn = 0

        for x in range(6):
            fake_555.state[start_555 + 1] = self.state[start_nnn + 1]
            fake_555.state[start_555 + 5] = self.state[start_nnn + self.size]
            fake_555.state[start_555 +
                           21] = self.state[start_nnn +
                                            (self.size * self.size) -
                                            self.size + 1]
            fake_555.state[start_555 +
                           25] = self.state[start_nnn +
                                            (self.size * self.size)]
            start_nnn += self.size * self.size
            start_555 += 25

        # Fill in the edges
        start_555 = 0
        start_nnn = 0
        half_size = int(self.size / 2)
        max_orbit = int((self.size - 2) / 2) - 1

        for x in range(6):
            row1_col2 = start_nnn + half_size
            row1_col1 = row1_col2 - (max_orbit - orbit)
            row1_col3 = row1_col2 + (max_orbit - orbit) + 1

            row2_col1 = start_nnn + ((orbit + 1) * self.size) + 1
            row2_col3 = row2_col1 + self.size - 1

            row3_col1 = start_nnn + (self.size * (half_size - 1)) + 1
            row3_col3 = row3_col1 + self.size - 1

            row4_col1 = start_nnn + (self.size * self.size) - (
                (orbit + 2) * self.size) + 1
            row4_col3 = row4_col1 + self.size - 1

            row5_col1 = row1_col1 + ((self.size - 1) * self.size)
            row5_col2 = row1_col2 + ((self.size - 1) * self.size)
            row5_col3 = row1_col3 + ((self.size - 1) * self.size)

            log.info("%d row1: %s, %s, %s" %
                     (x, row1_col1, row1_col2, row1_col3))
            log.info("%d row2: %s, %s" % (x, row2_col1, row2_col3))
            log.info("%d row3: %s, %s" % (x, row3_col1, row3_col3))
            log.info("%d row4: %s, %s" % (x, row4_col1, row4_col3))
            log.info("%d row5: %s, %s, %s" %
                     (x, row5_col1, row5_col2, row5_col3))

            # row1
            fake_555.state[start_555 + 2] = self.state[row1_col1]
            fake_555.state[start_555 + 3] = self.state[row1_col2]
            fake_555.state[start_555 + 4] = self.state[row1_col3]

            # row2
            fake_555.state[start_555 + 6] = self.state[row2_col1]
            fake_555.state[start_555 + 10] = self.state[row2_col3]

            # row3 - The middle of the edge so orbit doesn't matter
            fake_555.state[start_555 + 11] = self.state[row3_col1]
            fake_555.state[start_555 + 15] = self.state[row3_col3]

            # row4
            fake_555.state[start_555 + 16] = self.state[row4_col1]
            fake_555.state[start_555 + 20] = self.state[row4_col3]

            # row5
            fake_555.state[start_555 + 22] = self.state[row5_col1]
            fake_555.state[start_555 + 23] = self.state[row5_col2]
            fake_555.state[start_555 + 24] = self.state[row5_col3]

            start_nnn += self.size * self.size
            start_555 += 25

        fake_555.sanity_check()
        self.print_cube()
        fake_555.print_cube()
        fake_555.avoid_pll = False
        fake_555.group_edges()

        wide_str = str(orbit + 2)
        for step in fake_555.solution:

            if step == 'EDGES_GROUPED':
                continue

            # Rotate the entire cube
            if step.startswith('5'):
                step = str(self.size) + step[1:]

            elif step in ("Uw", "Uw'", "Uw2", "Lw", "Lw'", "Lw2", "Fw", "Fw'",
                          "Fw2", "Rw", "Rw'", "Rw2", "Bw", "Bw'", "Bw2", "Dw",
                          "Dw'", "Dw2"):
                step = wide_str + step

            self.rotate(step)
Пример #10
0
        if args.size != 'all' and size != args.size:
            continue

        # solve the cube
        if size == '2x2x2':
            cube = RubiksCube222(solved_222, order)

        elif size == '3x3x3':
            cube = RubiksCube333(solved_333, order)

        elif size == '4x4x4':
            cube = RubiksCube444(solved_444, order)

        elif size == '5x5x5':
            cube = RubiksCube555(solved_555, order)

        elif size == '6x6x6':
            cube = RubiksCube666(solved_666, order)

        elif size == '7x7x7':
            cube = RubiksCube777(solved_777, order)

        elif size == '8x8x8':
            cube = RubiksCubeNNNEven(solved_888, order)

        elif size == '9x9x9':
            cube = RubiksCubeNNNOdd(solved_999, order)

        elif size == '10x10x10':
            cube = RubiksCubeNNNEven(solved_101010, order)
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(filename)20s %(levelname)8s: %(message)s')
log = logging.getLogger(__name__)

# Color the errors and warnings in red
logging.addLevelName(
    logging.ERROR,
    "\033[91m   %s\033[0m" % logging.getLevelName(logging.ERROR))
logging.addLevelName(
    logging.WARNING,
    "\033[91m %s\033[0m" % logging.getLevelName(logging.WARNING))

filename = sys.argv[1]
with open(filename, "r") as fh:
    cube = RubiksCube555(solved_555, 'URFDLB')

    for line in fh:
        (state, steps_to_solve) = line.strip().split(":")
        cube.re_init()
        cube.nuke_corners()
        #cube.nuke_edges()
        cube.nuke_centers()
        steps_to_solve = steps_to_solve.split()
        steps_to_scramble = reverse_steps(steps_to_solve)

        for step in steps_to_scramble:
            cube.rotate(step)
        cube.print_cube()
        log.info("steps_to_scramble %s" % " ".join(steps_to_scramble))
        log.info("steps_to_solve    %s\n\n" % " ".join(steps_to_solve))
    def pair_edge_orbit_via_555(self, orbit):
        log.warning("pair_edge_orbit_via_555 for %d" % orbit)
        fake_555 = RubiksCube555(solved_5x5x5, 'URFDLB')
        fake_555.lt_init()

        # The corners don't matter but it does make troubleshooting easier if they match
        start_index = 0
        fake_555.state[1] = self.state[start_index+1]
        fake_555.state[5] = self.state[start_index + self.size]
        fake_555.state[21] = self.state[start_index + (self.size * self.size) - self.size + 1]
        fake_555.state[25] = self.state[start_index + (self.size * self.size)]
        start_index += self.size * self.size

        fake_555.state[26] = self.state[start_index+1]
        fake_555.state[30] = self.state[start_index + self.size]
        fake_555.state[46] = self.state[start_index + (self.size * self.size) - self.size + 1]
        fake_555.state[50] = self.state[start_index + (self.size * self.size)]
        start_index += self.size * self.size

        fake_555.state[51] = self.state[start_index+1]
        fake_555.state[55] = self.state[start_index + self.size]
        fake_555.state[71] = self.state[start_index + (self.size * self.size) - self.size + 1]
        fake_555.state[75] = self.state[start_index + (self.size * self.size)]
        start_index += self.size * self.size

        fake_555.state[76] = self.state[start_index+1]
        fake_555.state[80] = self.state[start_index + self.size]
        fake_555.state[96] = self.state[start_index + (self.size * self.size) - self.size + 1]
        fake_555.state[100] = self.state[start_index + (self.size * self.size)]
        start_index += self.size * self.size

        fake_555.state[101] = self.state[start_index+1]
        fake_555.state[105] = self.state[start_index + self.size]
        fake_555.state[121] = self.state[start_index + (self.size * self.size) - self.size + 1]
        fake_555.state[125] = self.state[start_index + (self.size * self.size)]
        start_index += self.size * self.size

        fake_555.state[126] = self.state[start_index+1]
        fake_555.state[130] = self.state[start_index + self.size]
        fake_555.state[146] = self.state[start_index + (self.size * self.size) - self.size + 1]
        fake_555.state[150] = self.state[start_index + (self.size * self.size)]
        start_index += self.size * self.size

        half_size = int(self.size/2)

        # Upper
        start_index = 0
        fake_555.state[2] = self.state[start_index + orbit + 1]
        fake_555.state[3] = self.state[start_index + half_size]
        fake_555.state[4] = self.state[start_index + self.size - orbit]

        fake_555.state[6] = self.state[start_index + (orbit * self.size) + 1]
        fake_555.state[10] = self.state[start_index + (orbit * self.size) + self.size]

        # The middle of the edge so orbit doesn't matter
        fake_555.state[11] = self.state[start_index + (self.size * (half_size - 1)) + 1]
        fake_555.state[15] = self.state[start_index + (self.size * half_size)]

        fake_555.state[16] = self.state[start_index + (self.size * self.size) - (orbit * self.size) - self.size + 1]
        fake_555.state[20] = self.state[start_index + (self.size * self.size) - (orbit * self.size)]

        fake_555.state[22] = self.state[start_index + (self.size * self.size) - self.size + 1 + orbit]
        fake_555.state[23] = self.state[start_index + (self.size * self.size) - half_size]
        fake_555.state[24] = self.state[start_index + (self.size * self.size) - orbit]
        start_index += self.size * self.size


        # Left
        fake_555.state[27] = self.state[start_index + orbit + 1]
        fake_555.state[28] = self.state[start_index + half_size]
        fake_555.state[29] = self.state[start_index + self.size - orbit]

        fake_555.state[31] = self.state[start_index + (orbit * self.size) + 1]
        fake_555.state[35] = self.state[start_index + (orbit * self.size) + self.size]

        # The middle of the edge so orbit doesn't matter
        fake_555.state[36] = self.state[start_index + (self.size * (half_size - 1)) + 1]
        fake_555.state[40] = self.state[start_index + (self.size * half_size)]

        fake_555.state[41] = self.state[start_index + (self.size * self.size) - (orbit * self.size) - self.size + 1]
        fake_555.state[45] = self.state[start_index + (self.size * self.size) - (orbit * self.size)]

        fake_555.state[47] = self.state[start_index + (self.size * self.size) - self.size + 1 + orbit]
        fake_555.state[48] = self.state[start_index + (self.size * self.size) - half_size]
        fake_555.state[49] = self.state[start_index + (self.size * self.size) - orbit]
        start_index += self.size * self.size

        # Front
        fake_555.state[52] = self.state[start_index + orbit + 1]
        fake_555.state[53] = self.state[start_index + half_size]
        fake_555.state[54] = self.state[start_index + self.size - orbit]

        fake_555.state[56] = self.state[start_index + (orbit * self.size) + 1]
        fake_555.state[60] = self.state[start_index + (orbit * self.size) + self.size]

        # The middle of the edge so orbit doesn't matter
        fake_555.state[61] = self.state[start_index + (self.size * (half_size - 1)) + 1]
        fake_555.state[65] = self.state[start_index + (self.size * half_size)]

        fake_555.state[66] = self.state[start_index + (self.size * self.size) - (orbit * self.size) - self.size + 1]
        fake_555.state[70] = self.state[start_index + (self.size * self.size) - (orbit * self.size)]

        fake_555.state[72] = self.state[start_index + (self.size * self.size) - self.size + 1 + orbit]
        fake_555.state[73] = self.state[start_index + (self.size * self.size) - half_size]
        fake_555.state[74] = self.state[start_index + (self.size * self.size) - orbit]
        start_index += self.size * self.size

        # Right
        fake_555.state[77] = self.state[start_index + orbit + 1]
        fake_555.state[78] = self.state[start_index + half_size]
        fake_555.state[79] = self.state[start_index + self.size - orbit]

        fake_555.state[81] = self.state[start_index + (orbit * self.size) + 1]
        fake_555.state[85] = self.state[start_index + (orbit * self.size) + self.size]

        # The middle of the edge so orbit doesn't matter
        fake_555.state[86] = self.state[start_index + (self.size * (half_size - 1)) + 1]
        fake_555.state[90] = self.state[start_index + (self.size * half_size)]

        fake_555.state[91] = self.state[start_index + (self.size * self.size) - (orbit * self.size) - self.size + 1]
        fake_555.state[95] = self.state[start_index + (self.size * self.size) - (orbit * self.size)]

        fake_555.state[97] = self.state[start_index + (self.size * self.size) - self.size + 1 + orbit]
        fake_555.state[98] = self.state[start_index + (self.size * self.size) - half_size]
        fake_555.state[99] = self.state[start_index + (self.size * self.size) - orbit]
        start_index += self.size * self.size

        # Back
        fake_555.state[102] = self.state[start_index + orbit + 1]
        fake_555.state[103] = self.state[start_index + half_size]
        fake_555.state[104] = self.state[start_index + self.size - orbit]

        fake_555.state[106] = self.state[start_index + (orbit * self.size) + 1]
        fake_555.state[110] = self.state[start_index + (orbit * self.size) + self.size]

        # The middle of the edge so orbit doesn't matter
        fake_555.state[111] = self.state[start_index + (self.size * (half_size - 1)) + 1]
        fake_555.state[115] = self.state[start_index + (self.size * half_size)]

        fake_555.state[116] = self.state[start_index + (self.size * self.size) - (orbit * self.size) - self.size + 1]
        fake_555.state[120] = self.state[start_index + (self.size * self.size) - (orbit * self.size)]

        fake_555.state[122] = self.state[start_index + (self.size * self.size) - self.size + 1 + orbit]
        fake_555.state[123] = self.state[start_index + (self.size * self.size) - half_size]
        fake_555.state[124] = self.state[start_index + (self.size * self.size) - orbit]
        start_index += self.size * self.size


        # Down
        fake_555.state[127] = self.state[start_index + orbit + 1]
        fake_555.state[128] = self.state[start_index + half_size]
        fake_555.state[129] = self.state[start_index + self.size - orbit]

        fake_555.state[131] = self.state[start_index + (orbit * self.size) + 1]
        fake_555.state[135] = self.state[start_index + (orbit * self.size) + self.size]

        # The middle of the edge so orbit doesn't matter
        fake_555.state[136] = self.state[start_index + (self.size * (half_size - 1)) + 1]
        fake_555.state[140] = self.state[start_index + (self.size * half_size)]

        fake_555.state[141] = self.state[start_index + (self.size * self.size) - (orbit * self.size) - self.size + 1]
        fake_555.state[145] = self.state[start_index + (self.size * self.size) - (orbit * self.size)]

        fake_555.state[147] = self.state[start_index + (self.size * self.size) - self.size + 1 + orbit]
        fake_555.state[148] = self.state[start_index + (self.size * self.size) - half_size]
        fake_555.state[149] = self.state[start_index + (self.size * self.size) - orbit]
        start_index += self.size * self.size

        self.print_cube()
        fake_555.print_cube()
        fake_555.avoid_pll = False
        fake_555.group_edges()

        # dwalton
        wide_str = str(orbit + 1)
        for step in fake_555.solution:

            if step == 'EDGES_GROUPED':
                continue

            # Rotate the entire cube
            if step.startswith('5'):
                step = str(self.size) + step[1:]

            elif step in ("Uw", "Uw'", "Uw2",
                          "Lw", "Lw'", "Lw2",
                          "Fw", "Fw'", "Fw2",
                          "Rw", "Rw'", "Rw2",
                          "Bw", "Bw'", "Bw2",
                          "Dw", "Dw'", "Dw2"):
                step = wide_str + step

            #log.warning("fake_555 step %s" % step)
            self.rotate(step)
    def pair_outside_edges_via_555(self):
        fake_555 = RubiksCube555(solved_5x5x5, 'URFDLB')
        fake_555.lt_init()

        # The corners matter for avoiding PLL
        fake_555.state[1] = self.state[1]
        fake_555.state[5] = self.state[6]
        fake_555.state[21] = self.state[31]
        fake_555.state[25] = self.state[36]
        fake_555.state[26] = self.state[37]
        fake_555.state[30] = self.state[42]
        fake_555.state[46] = self.state[67]
        fake_555.state[50] = self.state[72]
        fake_555.state[51] = self.state[73]
        fake_555.state[55] = self.state[78]
        fake_555.state[71] = self.state[103]
        fake_555.state[75] = self.state[108]
        fake_555.state[76] = self.state[109]
        fake_555.state[80] = self.state[114]
        fake_555.state[96] = self.state[139]
        fake_555.state[100] = self.state[144]
        fake_555.state[101] = self.state[145]
        fake_555.state[105] = self.state[150]
        fake_555.state[121] = self.state[175]
        fake_555.state[125] = self.state[180]
        fake_555.state[126] = self.state[181]
        fake_555.state[130] = self.state[186]
        fake_555.state[146] = self.state[211]
        fake_555.state[150] = self.state[216]

        # Upper
        fake_555.state[2] = self.state[2]
        fake_555.state[3] = self.state[3]
        fake_555.state[4] = self.state[5]
        fake_555.state[6] = self.state[7]
        fake_555.state[10] = self.state[12]
        fake_555.state[11] = self.state[13]
        fake_555.state[15] = self.state[18]
        fake_555.state[16] = self.state[25]
        fake_555.state[20] = self.state[30]
        fake_555.state[22] = self.state[32]
        fake_555.state[23] = self.state[33]
        fake_555.state[24] = self.state[35]

        # Left
        fake_555.state[27] = self.state[38]
        fake_555.state[28] = self.state[39]
        fake_555.state[29] = self.state[41]
        fake_555.state[31] = self.state[43]
        fake_555.state[35] = self.state[48]
        fake_555.state[36] = self.state[49]
        fake_555.state[40] = self.state[54]
        fake_555.state[41] = self.state[61]
        fake_555.state[45] = self.state[66]
        fake_555.state[47] = self.state[68]
        fake_555.state[48] = self.state[69]
        fake_555.state[49] = self.state[71]

        # Front
        fake_555.state[52] = self.state[74]
        fake_555.state[53] = self.state[75]
        fake_555.state[54] = self.state[77]
        fake_555.state[56] = self.state[79]
        fake_555.state[60] = self.state[84]
        fake_555.state[61] = self.state[85]
        fake_555.state[65] = self.state[90]
        fake_555.state[66] = self.state[97]
        fake_555.state[70] = self.state[102]
        fake_555.state[72] = self.state[104]
        fake_555.state[73] = self.state[105]
        fake_555.state[74] = self.state[107]

        # Right
        fake_555.state[77] = self.state[110]
        fake_555.state[78] = self.state[111]
        fake_555.state[79] = self.state[113]
        fake_555.state[81] = self.state[115]
        fake_555.state[85] = self.state[120]
        fake_555.state[86] = self.state[121]
        fake_555.state[90] = self.state[126]
        fake_555.state[91] = self.state[133]
        fake_555.state[95] = self.state[138]
        fake_555.state[97] = self.state[140]
        fake_555.state[98] = self.state[141]
        fake_555.state[99] = self.state[143]

        # Back
        fake_555.state[102] = self.state[146]
        fake_555.state[103] = self.state[147]
        fake_555.state[104] = self.state[149]
        fake_555.state[106] = self.state[151]
        fake_555.state[110] = self.state[156]
        fake_555.state[111] = self.state[157]
        fake_555.state[115] = self.state[162]
        fake_555.state[116] = self.state[169]
        fake_555.state[120] = self.state[174]
        fake_555.state[122] = self.state[176]
        fake_555.state[123] = self.state[177]
        fake_555.state[124] = self.state[179]

        # Down
        fake_555.state[127] = self.state[182]
        fake_555.state[128] = self.state[183]
        fake_555.state[129] = self.state[185]
        fake_555.state[131] = self.state[187]
        fake_555.state[135] = self.state[192]
        fake_555.state[136] = self.state[193]
        fake_555.state[140] = self.state[198]
        fake_555.state[141] = self.state[205]
        fake_555.state[145] = self.state[210]
        fake_555.state[147] = self.state[212]
        fake_555.state[148] = self.state[213]
        fake_555.state[149] = self.state[215]

        #self.print_cube()
        #fake_555.print_cube()
        fake_555.avoid_pll = True
        fake_555.group_edges()

        for step in fake_555.solution:
            if step == 'EDGES_GROUPED':
                continue

            if step.startswith('5'):
                step = '6' + step[1:]
            elif step.startswith('3'):
                step = '4' + step[1:]

            self.rotate(step)

        log.info("Outside edges are paired, %d steps in" % self.get_solution_len_minus_rotates(self.solution))
Пример #14
0
def getResults(state):
    if sys.version_info < (3, 4):
        raise SystemError("Must be using Python 3.4 or higher")

    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s %(filename)22s %(levelname)8s: %(message)s")
    log = logging.getLogger(__name__)

    log.info("rubiks-cube-solver.py begin")

    start_time = dt.datetime.now()

    parser = argparse.ArgumentParser()
    parser.add_argument("--print-steps",
                        default=False,
                        action="store_true",
                        help="Display animated step-by-step solution")
    parser.add_argument("--debug",
                        default=False,
                        action="store_true",
                        help="set loglevel to DEBUG")
    parser.add_argument("--no-comments",
                        default=False,
                        action="store_true",
                        help="No comments in alg.cubing.net url")

    # CPU mode
    parser.add_argument(
        "--min-memory",
        default=False,
        action="store_true",
        help="Load smaller tables to use less memory...takes longer to run",
    )
    parser.add_argument("--fast",
                        default=True,
                        action="store_true",
                        help="Find a solution quickly")
    parser.add_argument("--normal",
                        default=False,
                        action="store_true",
                        help="Find a shorter solution but takes longer")
    parser.add_argument("--slow",
                        default=False,
                        action="store_true",
                        help="Find shortest solution we can, takes a while")

    action = parser.add_mutually_exclusive_group(required=False)
    parser.add_argument("--openwith",
                        default=None,
                        type=str,
                        help="Colors for sides U, L, etc")
    parser.add_argument("--colormap",
                        default=None,
                        type=str,
                        help="Colors for sides U, L, etc")
    parser.add_argument(
        "--order",
        type=str,
        default="URFDLB",
        help="order of sides in --state, default kociemba URFDLB")
    parser.add_argument("--solution333",
                        type=str,
                        default=None,
                        help="cube explorer optimal steps for solving 3x3x3")
    parser.add_argument(
        "--state",
        type=str,
        help="Cube state",
        # no longer used
        # parser.add_argument('--test', default=False, action='store_true')
        # 2x2x2
        #    default='DLRRFULLDUBFDURDBFBRBLFU')
        #    default='UUUURRRRFFFFDDDDLLLLBBBB')
        # 3x3x3
        #    default='RRBBUFBFBRLRRRFRDDURUBFBBRFLUDUDFLLFFLLLLDFBDDDUUBDLUU')
        #    default='UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB') # solved
        # 4x4x4
        # default='DRFDFRUFDURDDLLUFLDLLBLULFBUUFRBLBFLLUDDUFRBURBBRBDLLDURFFBBRUFUFDRFURBUDLDBDUFFBUDRRLDRBLFBRRLB') # xyzzy test cube
        # default='FLDFDLBDFBLFFRRBDRFRRURBRDUBBDLURUDRRBFFBDLUBLUULUFRRFBLDDUULBDBDFLDBLUBFRFUFBDDUBFLLRFLURDULLRU') # TPR cube
        # default="BRBLLLBRDLBBDDRRFUDFUDUDFUDDDRURBBBUUDRLFRDLLFBRFLRFLFFFBRULDRUBUBBLDBFRDLLUBUDDULFLRRFLFUBFUFUR",
    )
    #    default='UUUUUUUUUUUUUUUURRRRRRRRRRRRRRRRFFFFFFFFFFFFFFFFDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLBBBBBBBBBBBBBBBB') # solved

    # 5x5x5
    #    default='RFFFUDUDURBFULULFDBLRLDUFDBLUBBBDDURLRDRFRUDDBFUFLFURRLDFRRRUBFUUDUFLLBLBBULDDRRUFUUUBUDFFDRFLRBBLRFDLLUUBBRFRFRLLBFRLBRRFRBDLLDDFBLRDLFBBBLBLBDUUFDDD')
    #    https://www.speedsolving.com/forum/threads/arnauds-5x5x5-edge-pairing-method-examples.1447/
    #    default='LDFRDDUUUUFUUUBLUUUFLDFDRFDDFBBRRRULRRRBFRRRURFRFDUBDRUBFFFUBFFFUUFFFRLDLRFDLBDDLDDDRDDDDUDDDDUULDLFBFLFFULLLRFLLLRLLLLRRBLBBRBULULBBBRUBBBRBBBBULBRFB')
    #    default='UDLFDLDDLUFDUBRLBDLFLRBFRBLBBFUDURDULRRBRLFUURBUFLUBDUDRURRRBUFUFFFRUFFLDUURURFFULFFRLFDBRRFRDDBRFBBLBRDFBBBBUDDLLLDBUULUDULDLDDLBRRLRLUBBFFBDLFBDDLFR')
    #    default='UUUUUUUUUUUUUUUUUUUUUUUUURRRRRRRRRRRRRRRRRRRRRRRRRFFFFFFFFFFFFFFFFFFFFFFFFFDDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLLBBBBBBBBBBBBBBBBBBBBBBBBB') # solved
    #    default='DFFURRULDLDLURLBDDRRBFRURFBFBFRBDLBBFRBLRFBRBBFLULDLBLULLFRUBUFLDFFLDULDDLUURRDRFBRLULUDRBDUUUBBRFFDBDFURDBBDDRULBUDRDLLLBDRFDLRDLLFDBBUFBRURFFUFFUUFU') # step10 takes 2s
    #    default='URUBFUUFRDFFUUFLRDBLLBDDDLUULRDLDUBDLRBBLFLBRBFUUBBRBFFUDLFLLBFUFUDRLBFUBBURRLLRUFRDUFFDFRFUBRBBDRFRFLLFURLLFBRBLUDRDDRRDRRFDUDLFLDLUUDUDBRBBBRBDDLDFL') # step10 takes 9s
    #    default='RFUBLFUBRULLUDDRLRLLFFFLUBDBLBFFUFLFURBFFLDDLFFBBRLUUDRRDLLLRDFFLBBLFURUBULBRLBDRUURDRRDFURDBUUBBFBUDRUBURBRBDLFLBDFBDULLDBBDDDRRFURLDUDUBRDFRFFDFDRLU') # step10 takes 6s, centers take 37 steps :(

    # 6x6x6
    #    default='FBDDDFFUDRFBBLFLLURLDLLUFBLRFDUFLBLLFBFLRRBBFDRRDUBUFRBUBRDLUBFDRLBBRLRUFLBRBDUDFFFDBLUDBBLRDFUUDLBBBRRDRUDLBLDFRUDLLFFUUBFBUUFDLRUDUDBRRBBUFFDRRRDBULRRURULFDBRRULDDRUUULBLLFDFRRFDURFFLDUUBRUFDRFUBLDFULFBFDDUDLBLLRBL')
    #    default='UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB') # solved
    #    defult='xxxxxxxDRRLxxLDDBxxLUUDxxFRDUxxxxxxxxxxxxxxBBLBxxURFUxxDRBDxxDFDLxxxxxxxxxxxxxxULLRxxUFLLxxBLFRxxBBRDxxxxxxxxxxxxxxLFBRxxBUUFxxFDDFxxURUFxxxxxxxxxxxxxxRFDLxxURFUxxUBBFxxRULDxxxxxxxxxxxxxxBBLFxxFLLRxxDRBBxxFDRUxxxxxxx') # good step20 IDA test

    # 7x7x7
    #    default='DBDBDDFBDDLUBDLFRFRBRLLDUFFDUFRBRDFDRUFDFDRDBDBULDBDBDBUFBUFFFULLFLDURRBBRRBRLFUUUDUURBRDUUURFFFLRFLRLDLBUFRLDLDFLLFBDFUFRFFUUUFURDRFULBRFURRBUDDRBDLLRLDLLDLUURFRFBUBURBRUDBDDLRBULBULUBDBBUDRBLFFBLRBURRUFULBRLFDUFDDBULBRLBUFULUDDLLDFRDRDBBFBUBBFLFFRRUFFRLRRDRULLLFRLFULBLLBBBLDFDBRBFDULLULRFDBR')

    # 8x8x8
    #    default='DRRRURBDDBFBRBDDBRRDUFLLURFBFLFURLFLFRBRFUBDRFDFUUBLFFFUULBBFDBDFBUBBFRFLRDLFDRBBLLFRLDFDRBURULDDRFFBFUUBLLFBRUUFDUBRDBBRDFLURUUFFUDLBRRFDUBFLRUUFFRLBFRFLRULUDFRUBBDBFFLBBDFDFLDBFRRRDDLFLBRBFBBRULDDUUBLBBURULLDDLDRUDRBUDRLUULDURLRDFLFULUFLFULRDDDUBBULRBRDFBBLFURRLULUBDDULRFBRFURBRLBRUBULBDDFBUFFBBRLRUUUFRULLBFFRFDDFFDULLDLBUDLLLLUUBBLDLLBBULULBDUDDFUBFLLDLDLFRDUDDBRRFRURRFRRLDDDDRD')

    # 9x9x9
    #    default='RFBLRUFLLFFLRRBDUDDBBBDUDFRUDUFFFBBFRBRDURBULFUDDFLLLDLFLRDLDBBBUUBRDBBBDFUFRUURULURBURDLFDUBFFDRDFRUBDUBRFLRRLUDLRLFBLBRRLLRDRBRBLURBLLRFRLDDFFFRBFUFURDFRRUDUFDDRRRLFLLUBBLBFDRRDLBRLUUBRDBBU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RUFFUBBDFFDBLLDBDUBDLDLUDFBFLRULRRBDBLRBLDLUURRLLRULDBLBLLRRFDDRBBRBUBDDULDRFBFBBFLUFBLUULDDFDBRLLUBUBBDFBBLBBUBLULDRUDBLRULDUDLUFRRDLLUDDBUFLFLBUFUURFDRDLBURLLRRRULRBFFRRBRFBUBRBUUFRLRDRDLBBRFLLLDDBRFUFRBULFLFDRDDRRDBF')

    args = parser.parse_args()
    args.state = state
    if "G" in args.state:
        args.state = args.state.replace("G", "F")
        args.state = args.state.replace("Y", "D")
        args.state = args.state.replace("O", "L")
        args.state = args.state.replace("W", "U")

    if args.debug:
        log.setLevel(logging.DEBUG)

    try:
        size = int(sqrt((len(args.state) / 6)))

        if args.slow:
            cpu_mode = "slow"
        elif args.normal:
            cpu_mode = "normal"
        elif args.fast:
            cpu_mode = "fast"
        else:
            raise Exception("What CPU mode to use?")

        if size == 2:
            # rubiks cube libraries
            from rubikscubennnsolver.RubiksCube222 import RubiksCube222

            cube = RubiksCube222(args.state, args.order, args.colormap,
                                 args.debug)
        elif size == 3:
            # rubiks cube libraries
            from rubikscubennnsolver.RubiksCube333 import RubiksCube333

            cube = RubiksCube333(args.state, args.order, args.colormap,
                                 args.debug)
        elif size == 4:
            # rubiks cube libraries
            from rubikscubennnsolver.RubiksCube444 import RubiksCube444

            cube = RubiksCube444(args.state,
                                 args.order,
                                 args.colormap,
                                 avoid_pll=True,
                                 debug=args.debug)
        elif size == 5:
            # rubiks cube libraries
            from rubikscubennnsolver.RubiksCube555 import RubiksCube555

            cube = RubiksCube555(args.state, args.order, args.colormap,
                                 args.debug)
        elif size == 6:
            # rubiks cube libraries
            from rubikscubennnsolver.RubiksCube666 import RubiksCube666

            cube = RubiksCube666(args.state, args.order, args.colormap,
                                 args.debug)
        elif size == 7:
            # rubiks cube libraries
            from rubikscubennnsolver.RubiksCube777 import RubiksCube777

            cube = RubiksCube777(args.state, args.order, args.colormap,
                                 args.debug)
        elif size % 2 == 0:
            # rubiks cube libraries
            from rubikscubennnsolver.RubiksCubeNNNEven import RubiksCubeNNNEven

            cube = RubiksCubeNNNEven(args.state, args.order, args.colormap,
                                     args.debug)
        else:
            # rubiks cube libraries
            from rubikscubennnsolver.RubiksCubeNNNOdd import RubiksCubeNNNOdd

            cube = RubiksCubeNNNOdd(args.state, args.order, args.colormap,
                                    args.debug)

        if args.openwith:
            cube.print_cube()
            for step in args.openwith.split():
                cube.rotate(step)

        cube.cpu_mode = cpu_mode
        log.info("CPU mode %s" % cube.cpu_mode)
        cube.sanity_check()
        cube.print_cube()
        cube.www_header()
        cube.www_write_cube("Initial Cube")

        try:
            if args.solution333:
                solution333 = reverse_steps(args.solution333.split())
            else:
                solution333 = []
            cube.solve(solution333)
        except NotSolving:
            if cube.heuristic_stats:
                log.info("%s: heuristic_stats raw\n%s\n\n" %
                         (cube, pformat(cube.heuristic_stats)))

                for (key, value) in cube.heuristic_stats.items():
                    cube.heuristic_stats[key] = int(median(value))

                log.info("%s: heuristic_stats median\n%s\n\n" %
                         (cube, pformat(cube.heuristic_stats)))
                sys.exit(0)
            else:
                raise

        end_time = dt.datetime.now()
        log.info("Final Cube")
        cube.print_cube()
        res = cube.print_solution(not args.no_comments)

        log.info(
            "*********************************************************************************"
        )
        log.info(
            "See /tmp/rubiks-cube-NxNxN-solver/index.html for more detailed solve instructions"
        )
        log.info(
            "*********************************************************************************\n"
        )

        # Now put the cube back in its initial state and verify the solution solves it
        solution = cube.solution
        cube.re_init()
        len_steps = len(solution)

        for (i, step) in enumerate(solution):

            if args.print_steps:
                print(("Phase     : %s" % cube.phase()))
                print(("Move %d/%d: %s" % (i + 1, len_steps, step)))

            cube.rotate(step)

            www_desc = "Phase: %s<br>\nCube After Move %d/%d: %s<br>\n" % (
                cube.phase(), i + 1, len_steps, step)
            cube.www_write_cube(www_desc)

            if args.print_steps:
                cube.print_cube()
                print("\n\n\n\n")

        cube.www_footer()

        if args.print_steps:
            cube.print_cube()

        if args.min_memory:
            print("\n\n****************************************")
            print("--min-memory has been replaced by --fast")
            print("****************************************\n\n")

        log.info("rubiks-cube-solver.py end")
        log.info("Memory : {:,} bytes".format(
            resource.getrusage(resource.RUSAGE_SELF).ru_maxrss))
        log.info("Time   : %s" % (end_time - start_time))
        log.info("")

        success = True

        if not cube.solved():
            kociemba_string = cube.get_kociemba_string(False)
            # edge_swap_count = cube.get_edge_swap_count(edges_paired=True, orbit=None, debug=True)
            # corner_swap_count = cube.get_corner_swap_count(debug=True)

            # raise SolveError("cube should be solved but is not, edge parity %d, corner parity %d, kociemba %s" %
            #    (edge_swap_count, corner_swap_count, kociemba_string))
            raise SolveError("cube should be solved but is not")

    except (ImplementThis, SolveError, StuckInALoop, NoSteps, KeyError,
            NoPruneTableState, InvalidCubeReduction):
        cube.enable_print_cube = True
        cube.print_cube_layout()
        cube.print_cube()
        res = cube.print_solution(False)
        success = True
        print((cube.get_kociemba_string(True)))
        log.info("rubiks-cube-solver.py end")
        raise

    return res, success
Пример #15
0
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s %(filename)17s %(levelname)8s: %(message)s')
log = logging.getLogger(__name__)

# Color the errors and warnings in red
logging.addLevelName(
    logging.ERROR,
    "\033[91m   %s\033[0m" % logging.getLevelName(logging.ERROR))
logging.addLevelName(
    logging.WARNING,
    "\033[91m %s\033[0m" % logging.getLevelName(logging.WARNING))

cube = RubiksCube555(
    'DFFURRULDLDLURLBDDRRBFRURFBFBFRBDLBBFRBLRFBRBBFLULDLBLULLFRUBUFLDFFLDULDDLUURRDRFBRLULUDRBDUUUBBRFFDBDFURDBBDDRULBUDRDLLLBDRFDLRDLLFDBBUFBRURFFUFFUUFU'
)

lt = LookupTable(cube, 'lookup-table-5x5x5-step10-UD-centers-stage.txt',
                 'UD-centers-stage', '3fe000000001ff', True, moves_5x5x5)

# should not find this one
with open(lt.filename, 'r') as fh:
    print(lt.file_binary_search(fh, '0206f462228611'))

# should find this one
with open(lt.filename, 'r') as fh:
    print(lt.file_binary_search(fh, '3ffec000100012'))

states_to_find = []
with open('states-to-find-lookup-table-5x5x5-step10-UD-centers-stage.txt',
Пример #16
0
def print_cubes(filename):
    state = []
    with open(filename, 'r') as fh:
        for line in fh:
            if line.strip():
                state.append(line)
    state = ''.join(state)
    order = 'ULFRBD'

    len_state = len(state.replace('\n', '').replace(' ', ''))

    if len_state == 24:
        state = parse_ascii_222(state)
        cube = RubiksCube222(state, order)
        rotate_xxx = rotate_222

    elif len_state == 54:
        state = parse_ascii_333(state)
        cube = RubiksCube333(state, order)
        rotate_xxx = rotate_333

    elif len_state == 96:
        state = parse_ascii_444(state)
        cube = RubiksCube444(state, order)
        rotate_xxx = rotate_444

    elif len_state == 150:
        state = parse_ascii_555(state)
        cube = RubiksCube555(state, order)
        rotate_xxx = rotate_555

    elif len_state == 216:
        state = parse_ascii_666(state)
        cube = RubiksCube666(state, order)
        rotate_xxx = rotate_666

    elif len_state == 294:
        state = parse_ascii_777(state)
        cube = RubiksCube777(state, order)
        rotate_xxx = rotate_777

    else:
        raise Exception("cube has %d entries, what size is this?" % len_state)

    #cube.print_cube()
    tmp_state = cube.state[:]

    keepers = []

    for seq in symmetry_48:
        cube.state = tmp_state[:]

        for step in seq:
            cube.state = rotate_xxx(cube.state[:], step)

        if cube.state == tmp_state:
            log.info("================")
            log.info(' '.join(seq))
            log.info("================")
            cube.print_cube()
            log.info("\n\n\n\n\n")
            keepers.append(' '.join(seq))

    print("foo = (\n    \"" + '",\n    "'.join(keepers) + '"\n)')
Пример #17
0
    with open(lt_centers_filename, "r") as fh:
        for line in fh:
            (state, steps) = line.strip().split(':')
            lt_centers[state] = len(steps.split())

    log.info("end loading %s" % lt_centers_filename)

    # Init the workq
    workq = deque()
    for step in moves_555:
        if "w" in step:
            workq.append((1, step))

    # Init misc variables
    cube = RubiksCube555(solved_555, order='URFDLB')
    depth = 1
    kept = 0
    total_processed = 0
    processed = 0
    pruned = 0
    max_depth = args.depth
    min_wide_turns = args.min_wide_turns
    keepers = []
    keepers_count = 0
    keepers_filename = "keepers_555.txt"
    workq_filename = "workq.txt"

    next_workq = []
    next_workq_count = 0