def __init__(self,
                 state,
                 order,
                 colormap=None,
                 avoid_pll=True,
                 debug=False):
        RubiksCube.__init__(self, state, order, colormap, debug)
        self.avoid_pll = avoid_pll

        if debug:
            log.setLevel(logging.DEBUG)
Esempio n. 2
0
    def __init__(self, state: str, order: str, colormap: Dict = None, avoid_pll: bool = True, debug: bool = False):
        RubiksCube.__init__(self, state, order, colormap, debug)
        self.avoid_pll = avoid_pll
        self.edge_mapping = {}

        if RubiksCube444.instantiated:
            logger.warning("Another 4x4x4 instance is being created")
        else:
            RubiksCube444.instantiated = True

        if debug:
            logger.setLevel(logging.DEBUG)
Esempio n. 3
0
    def __init__(self, state, order, colormap=None, avoid_pll=True, debug=False):
        RubiksCube.__init__(self, state, order, colormap, debug)
        self.avoid_pll = avoid_pll
        self.edge_mapping = {}

        if RubiksCube444.instantiated:
            # raise Exception("Another 4x4x4 instance is being created")
            log.warning("Another 4x4x4 instance is being created")
        else:
            RubiksCube444.instantiated = True

        if debug:
            log.setLevel(logging.DEBUG)
test_cases["10x10x10"] = []
test_cases["11x11x11"] = []
test_cases["12x12x12"] = []
test_cases["13x13x13"] = []
test_cases["14x14x14"] = []
test_cases["15x15x15"] = []
test_cases["17x17x17"] = []

cubes = OrderedDict()
# cubes["2x2x2"] = RubiksCube(solved_222, 'URFDLB')
# cubes["3x3x3"] = RubiksCube(solved_333, 'URFDLB')
# cubes["4x4x4"] = RubiksCube(solved_444, 'URFDLB')
# cubes["5x5x5"] = RubiksCube(solved_555, 'URFDLB')
# cubes["6x6x6"] = RubiksCube(solved_666, 'URFDLB')
# cubes["7x7x7"] = RubiksCube(solved_777, 'URFDLB')
cubes["8x8x8"] = RubiksCube(solved_888, "URFDLB")
cubes["9x9x9"] = RubiksCube(solved_999, "URFDLB")
# cubes["10x10x10"] = RubiksCube(solved_101010, 'URFDLB')
# cubes["11x11x11"] = RubiksCube(solved_111111, 'URFDLB')
# cubes["12x12x12"] = RubiksCube(solved_121212, 'URFDLB')
# cubes["13x13x13"] = RubiksCube(solved_131313, 'URFDLB')
# cubes["14x14x14"] = RubiksCube(solved_141414, 'URFDLB')
# cubes["15x15x15"] = RubiksCube(solved_151515, 'URFDLB')
# cubes["17x17x17"] = RubiksCube(solved_171717, 'URFDLB')

for (size, cube) in cubes.items():
    log.info("size %s has cube %s" % (size, cube))
    for x in range(10):
        cube.re_init()
        cube.randomize()
        ks = cube.get_kociemba_string(True)
Esempio n. 5
0
    "6x6x6": [],
    "7x7x7": [],
    "8x8x8": [],
    "9x9x9": [],
    "10x10x10": [],
    "11x11x11": [],
    "12x12x12": [],
    "13x13x13": [],
    "14x14x14": [],
    "15x15x15": [],
    "17x17x17": [],
}

#for x in range(500):
for x in range(5):
    cube = RubiksCube(solved_2x2x2, 'URFDLB')
    cube.randomize()
    ks = cube.get_kociemba_string(True)
    test_cases["2x2x2"].append(ks)

    cube = RubiksCube(solved_3x3x3, 'URFDLB')
    cube.randomize()
    ks = cube.get_kociemba_string(True)
    test_cases["3x3x3"].append(ks)

    cube = RubiksCube(solved_4x4x4, 'URFDLB')
    cube.randomize()
    ks = cube.get_kociemba_string(True)
    test_cases["4x4x4"].append(ks)

    cube = RubiksCube(solved_5x5x5, 'URFDLB')
    def __init__(self, state, order, colormap=None, debug=False):
        RubiksCube.__init__(self, state, order, colormap, debug)

        if debug:
            log.setLevel(logging.DEBUG)
def main(c: bool) -> None:
    build_rotate_xxx_c = c
    swaps_py = "rubikscubennnsolver/swaps.py"

    if build_rotate_xxx_c:
        print("""
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "rotate_xxx.h"

    """)

    else:
        with open(swaps_py, "w") as fh:
            fh.write("# fmt: off\n")

    for (size, solved_state) in (
        (2, solved_222),
        (3, solved_333),
        (4, solved_444),
        (5, solved_555),
        (6, solved_666),
        (7, solved_777),
    ):

        cube = RubiksCube(solved_state, "URFDLB")
        max_square_index = size * size * 6

        # Change each value to be equal to its square position
        for x in range(1, max_square_index + 1):
            cube.state[x] = str(x)

        original_state = copy(cube.state)

        if size == 2:
            steps = moves_222

        elif size == 3:
            steps = moves_333

        elif size == 4:
            steps = moves_444

        elif size == 5:
            steps = moves_555

        elif size == 6:
            steps = moves_666

        elif size == 7:
            steps = moves_777

        else:
            raise Exception("Add support for size %s" % size)

        steps = list(steps)
        steps.extend(["x", "x'", "x2", "y", "y'", "y2", "z", "z'", "z2"])

        if size in (4, 5, 6, 7):
            steps.extend(["2U", "2U'", "2U2", "2D", "2D'", "2D2"])
            steps.extend(["2L", "2L'", "2L2", "2R", "2R'", "2R2"])
            steps.extend(["2F", "2F'", "2F2", "2B", "2B'", "2B2"])

        if size in (6, 7):
            steps.extend(["3U", "3U'", "3U2", "3D", "3D'", "3D2"])
            steps.extend(["3L", "3L'", "3L2", "3R", "3R'", "3R2"])
            steps.extend(["3F", "3F'", "3F2", "3B", "3B'", "3B2"])

        # middle layer slices
        if size == 5:
            steps.extend(["3U", "3U'", "3U2"])
            steps.extend(["3L", "3L'", "3L2"])
            steps.extend(["3F", "3F'", "3F2"])

        if build_rotate_xxx_c:
            print("void")
            print(
                "rotate_%d%d%d(char *cube, char *cube_tmp, int array_size, move_type move)"
                % (size, size, size))
            print("{")
            print(
                "    /* This was contructed using utils/rotate-printer.py */")
            print("    memcpy(cube_tmp, cube, sizeof(char) * array_size);")
            print("")
            first_step = True

            for step in steps:
                cube.rotate(step)
                cube.print_case_statement_C(step, first_step)
                cube.state = copy(original_state)
                first_step = False

            print(r"""
    default:
        printf("ERROR: invalid move %d\n", move);
        exit(1);
    }
}
    """)

        # build python swaps.py
        else:
            rotate_mapper = {}

            for step in steps:
                cube.rotate(step)
                rotate_mapper[step] = cube.print_case_statement_python()
                cube.state = copy(original_state)

            with open(swaps_py, "a") as fh:
                swaps = pformat(rotate_mapper, width=2048)
                swaps = swaps.replace("{", "{\n ")
                swaps = swaps.replace("}", "\n}\n")
                swaps = swaps.replace(" '", ' "')
                swaps = swaps.replace("':", '":')
                swaps = swaps.replace(' "', '    "')

                # fh.write("swaps_%d%d%d = %s\n" % (size, size, size, pformat(rotate_mapper, width=2048)))
                fh.write("swaps_%d%d%d = %s\n" % (size, size, size, swaps))

    if not build_rotate_xxx_c:
        with open(swaps_py, "a") as fh:
            fh.write("# fmt: on\n")
Esempio n. 8
0
#include <stdio.h>
#include <string.h>
#include "rotate_xxx.h"

""")

for (size, solved_state) in (
    (2, solved_222),
    (3, solved_333),
    (4, solved_444),
    (5, solved_555),
    (6, solved_666),
    (7, solved_777),
    ):

    cube = RubiksCube(solved_state, 'URFDLB')
    max_square_index = size * size * 6

    # Change each value to be equal to its square position
    for x in range(1, max_square_index+1):
        cube.state[x] = str(x)

    original_state = copy(cube.state)

    if size == 2:
        steps = moves_222

    elif size == 3:
        steps = moves_333

    elif size == 4:
Esempio n. 9
0
    "4x4x4": [],
    "5x5x5": [],
    "6x6x6": [],
    "7x7x7": [],
    "8x8x8": [],
    "9x9x9": [],
    "10x10x10": [],
    "11x11x11": [],
    "12x12x12": [],
    "13x13x13": [],
    "14x14x14": [],
    "15x15x15": [],
}

for x in range(500):
    cube = RubiksCube(solved_222, 'URFDLB')
    cube.randomize()
    ks = cube.get_kociemba_string(True)
    test_cases["2x2x2"].append(ks)

    cube = RubiksCube(solved_333, 'URFDLB')
    cube.randomize()
    ks = cube.get_kociemba_string(True)
    test_cases["3x3x3"].append(ks)

    cube = RubiksCube(solved_444, 'URFDLB')
    cube.randomize()
    ks = cube.get_kociemba_string(True)
    test_cases["4x4x4"].append(ks)

    cube = RubiksCube(solved_555, 'URFDLB')
Esempio n. 10
0
}
""")

for (size, solved_state) in (
    (2, solved_222),
    (3, solved_333),
    (4, solved_444),
    (5, solved_555),
    (6, solved_666),
    (7, solved_777),
    (8, solved_888),
    (9, solved_999),
    (10, solved_101010),
):

    cube = RubiksCube(solved_state, 'URFDLB')
    max_square_index = size * size * 6

    # Change each value to be equal to its square position
    for x in range(1, max_square_index + 1):
        cube.state[x] = str(x)

    original_state = copy(cube.state)

    if size == 2:
        steps = moves_222

    elif size == 3:
        steps = moves_333

    elif size == 4:
Esempio n. 11
0
test_cases["9x9x9"] = []
test_cases["10x10x10"] = []
test_cases["11x11x11"] = []
test_cases["12x12x12"] = []
test_cases["13x13x13"] = []
test_cases["14x14x14"] = []
test_cases["15x15x15"] = []
test_cases["17x17x17"] = []

cubes = OrderedDict()
#cubes["2x2x2"] = RubiksCube(solved_222, 'URFDLB')
#cubes["3x3x3"] = RubiksCube(solved_333, 'URFDLB')
#cubes["4x4x4"] = RubiksCube(solved_444, 'URFDLB')
#cubes["5x5x5"] = RubiksCube(solved_555, 'URFDLB')
#cubes["6x6x6"] = RubiksCube(solved_666, 'URFDLB')
cubes["7x7x7"] = RubiksCube(solved_777, 'URFDLB')
#cubes["8x8x8"] = RubiksCube(solved_888, 'URFDLB')
#cubes["9x9x9"] = RubiksCube(solved_999, 'URFDLB')
#cubes["10x10x10"] = RubiksCube(solved_101010, 'URFDLB')
#cubes["11x11x11"] = RubiksCube(solved_111111, 'URFDLB')
#cubes["12x12x12"] = RubiksCube(solved_121212, 'URFDLB')
#cubes["13x13x13"] = RubiksCube(solved_131313, 'URFDLB')
#cubes["14x14x14"] = RubiksCube(solved_141414, 'URFDLB')
#cubes["15x15x15"] = RubiksCube(solved_151515, 'URFDLB')
#cubes["17x17x17"] = RubiksCube(solved_171717, 'URFDLB')

for (size, cube) in cubes.items():
    log.info("size %s has cube %s" % (size, cube))
    for x in range(5):
        cube.re_init()
        cube.randomize()
Esempio n. 12
0
        logging.WARNING,
        "\033[91m %s\033[0m" % logging.getLevelName(logging.WARNING))

    parser = argparse.ArgumentParser()
    parser.add_argument('--input',
                        default='workq.txt',
                        type=str,
                        help="input filename")
    parser.add_argument('--output',
                        default='workq-results.txt',
                        type=str,
                        help="output filename")
    args = parser.parse_args()

    solved_444 = 'UUUUUUUUUUUUUUUURRRRRRRRRRRRRRRRFFFFFFFFFFFFFFFFDDDDDDDDDDDDDDDDLLLLLLLLLLLLLLLLBBBBBBBBBBBBBBBB'
    cube = RubiksCube(solved_444)
    original_state = copy(cube.state)

    prev_steps = None
    prev_steps_len = 0
    prev_state = None
    rotate_calls = 0

    with open(args.input, 'r') as fh_read:
        with open(args.output, 'w') as fh_write:
            for line in sorted(fh_read.readlines()):
                steps = line.strip().split()
                steps_len = len(steps)
                last_step = steps[-1]
                #log.info("steps (%d) %s, prev (%d) %s" %
                #    (steps_len, pformat(steps), prev_steps_len, pformat(prev_steps)))