예제 #1
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def search5v1(seq_wa, seq_w):
    cube = RubikCube()
    for m1 in move_set:
        m1inv = -m1 if m1 < 10 else m1
        for m2 in move_set:
            sys.stdout.write('.')
            sys.stdout.flush()
            m2inv = -m2 if m2 < 10 else m2
            for m3 in move_set:
                m3inv = -m3 if m3 < 10 else m3
                for m4 in move_set:
                    m4inv = -m4 if m4 < 10 else m4
                    for m5 in move_set:
                        m5inv = -m5 if m5 < 10 else m5
                        seq = (m1, m2, m3, m4, m5) + seq_w + (
                            m5inv, m4inv, m3inv, m2inv, m1inv)
                        if RubikCube.areEqualMoves(seq, seq_wa):
                            print(m1, m2, m3, m4, m5)
예제 #2
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def edgeAndCornerPerms(state):
    cube = RubikCube()
    cube.setState(state)
    edges = cube.getEdgePermutation()
    corners = cube.getCornerPermutation()
    print(edges)
    print(corners)
    return edges, corners
예제 #3
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def search5v2(state_wa, seq_w):
    state_wa = RubikCube.moves2state(seq_wa)
    cube = RubikCube()
    for m1 in move_set:
        m1inv = -m1 if m1 < 10 else m1
        for m2 in move_set:
            sys.stdout.write('.')
            sys.stdout.flush()
            m2inv = -m2 if m2 < 10 else m2
            for m3 in move_set:
                m3inv = -m3 if m3 < 10 else m3
                for m4 in move_set:
                    m4inv = -m4 if m4 < 10 else m4
                    for m5 in move_set:
                        m5inv = -m5 if m5 < 10 else m5
                        seq = (m1, m2, m3, m4, m5) + seq_w + (
                            m5inv, m4inv, m3inv, m2inv, m1inv)
                        cube.reset()
                        cube.move(seq)
                        if cube.isInState(state_wa):
                            print(m1, m2, m3, m4, m5)
예제 #4
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def search5v5(seq_wa, seq_w, Nmax, progIndLvl):
    state_wa = RubikCube.moves2state(seq_wa)
    perm_w = RubikCube.moves2permutation(seq_w)
    #
    cube = RubikCube()
    state0 = cube.getState()
    states = [state0] * Nmax
    indices = [0] * (Nmax + 1)
    idxMax = len(move_set)
    cnt = 0
    while True:
        # increment, track state too
        i = 0
        while i < Nmax:
            if i == progIndLvl:
                sys.stdout.write('.')
                sys.stdout.flush()
            idx = indices[i] + 1
            if idx == idxMax:  # standard increment
                indices[i] = 0  # set 0 for now, will be updated at end
                i += 1
                continue
            indices[i] = idx
            if skipCheck(indices[i + 1],
                         idx):  # skip consecutive repeated moves
                continue
            break  # exit loop with i = last updated counter
        if i == Nmax:  # termination check
            break
        cube.setState(states[i])  # load saved state at lvl i
        cube.move((move_set[indices[i]], ))  # make i-th level move
        for j in range(
                i - 1, -1,
                -1):  # take first valid moves at levels j < i, update states
            while skipCheck(indices[j + 1], indices[j]):
                indices[j] += 1
            states[j] = cube.getState()  # store starting state
            cube.move((move_set[indices[j]], ))  # make level j move
        cnt += 1
        #print(cnt, indices, cube.getState(), move_set)
        perm = cube.state2permutation()
        cube.permute(perm_w)
        cube.invPermute(perm)
        if cube.isInState(state_wa):
            print(tuple([move_set[idx] for idx in indices]))
    print(cnt, 18 * (pow(15, Nmax) - 1) // (15 - 1) + 1)
예제 #5
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def search5v4b(seq_wa, seq_w):
    state_wa = RubikCube.moves2state(seq_wa)
    perm_w = RubikCube.moves2permutation(seq_w)
    cube = RubikCube()
    state0 = cube.getState()
    cnt = 0
    for (i1, m1) in imove_set:
        cube.setState(state0)
        cube.move((m1, ))
        state1 = cube.getState()
        for (i2, m2) in imove_set:
            if skipCheck(i1, i2): continue
            sys.stdout.write('.')
            sys.stdout.flush()
            cube.setState(state1)
            cube.move((m2, ))
            state2 = cube.getState()
            for (i3, m3) in imove_set:
                if skipCheck(i2, i3): continue
                cube.setState(state2)
                cube.move((m3, ))
                state3 = cube.getState()
                for (i4, m4) in imove_set:
                    if skipCheck(i3, i4): continue
                    cube.setState(state3)
                    cube.move((m4, ))
                    state4 = cube.getState()
                    for (i5, m5) in imove_set:
                        if skipCheck(i4, i5): continue
                        cnt += 1
                        cube.setState(state4)
                        cube.move((m5, ))
                        perm = cube.state2permutation()
                        cube.permute(perm_w)
                        cube.invPermute(perm)
                        if cube.isInState(state_wa):
                            print(m1, m2, m3, m4, m5)
    print(cnt,
          18 * (pow(15, 4) + pow(15, 3) + pow(15, 2) + pow(15, 1) + 1) + 1)
예제 #6
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def search5v4(seq_wa, seq_w):
    state_wa = RubikCube.moves2state(seq_wa)
    perm_w = RubikCube.moves2permutation(seq_w)
    cube = RubikCube()
    #cnt = 0
    for (i1, m1) in imove_set:
        for (i2, m2) in imove_set:
            if skipCheck(i1, i2): continue
            sys.stdout.write('.')
            sys.stdout.flush()
            for (i3, m3) in imove_set:
                if skipCheck(i2, i3): continue
                for (i4, m4) in imove_set:
                    if skipCheck(i3, i4): continue
                    cube.reset()
                    cube.move((m1, m2, m3, m4))
                    state4 = cube.getState()
                    for (i5, m5) in imove_set:
                        if skipCheck(i4, i5): continue
                        #cnt += 1
                        cube.setState(state4)
                        cube.move((m5, ))
                        perm = cube.state2permutation()
                        cube.permute(perm_w)
                        cube.invPermute(perm)
                        if cube.isInState(state_wa):
                            print(m1, m2, m3, m4, m5)
예제 #7
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def search5v3b(seq_wa, seq_w):
    state_wa = RubikCube.moves2state(seq_wa)
    perm_w = RubikCube.moves2permutation(seq_w)
    cube = RubikCube()
    #cnt = 0
    for (i1, m1) in imove_set:
        m1inv = -m1 if m1 < 10 else m1
        for (i2, m2) in imove_set:
            if skipCheck(i1, i2): continue
            sys.stdout.write('.')
            sys.stdout.flush()
            m2inv = -m2 if m2 < 10 else m2
            for (i3, m3) in imove_set:
                if skipCheck(i2, i3): continue
                m3inv = -m3 if m3 < 10 else m3
                for (i4, m4) in imove_set:
                    if skipCheck(i3, i4): continue
                    m4inv = -m4 if m4 < 10 else m4
                    for (i5, m5) in imove_set:
                        if skipCheck(i4, i5): continue
                        m5inv = -m5 if m5 < 10 else m5
                        #cnt += 1
                        cube.reset()
                        cube.move((m1, m2, m3, m4, m5))
                        cube.permute(perm_w)
                        cube.move((m5inv, m4inv, m3inv, m2inv, m1inv))
                        if cube.isInState(state_wa):
                            print(m1, m2, m3, m4, m5)
예제 #8
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def search5v3(seq_wa, seq_w):
    state_wa = RubikCube.moves2state(seq_wa)
    perm_w = RubikCube.moves2permutation(seq_w)
    cube = RubikCube()
    for m1 in move_set:
        m1inv = -m1 if m1 < 10 else m1
        for m2 in move_set:
            sys.stdout.write('.')
            sys.stdout.flush()
            m2inv = -m2 if m2 < 10 else m2
            for m3 in move_set:
                m3inv = -m3 if m3 < 10 else m3
                for m4 in move_set:
                    m4inv = -m4 if m4 < 10 else m4
                    for m5 in move_set:
                        m5inv = -m5 if m5 < 10 else m5
                        cube.reset()
                        cube.move((m1, m2, m3, m4, m5))
                        cube.permute(perm_w)
                        cube.move((m5inv, m4inv, m3inv, m2inv, m1inv))
                        if cube.isInState(state_wa):
                            print(m1, m2, m3, m4, m5)
예제 #9
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def find_bflips(wb_edges):
    wb_flipgoal = [j for (i, j) in wb_edges]
    print("goal:", wb_flipgoal)
    for p in itertools.product(range(2), repeat=12):
        # check parity
        if sum(p) & 1 != 0:
            continue
        #print(p)
        # build moves that create given parity
        cube = RubikCube()
        p0 = [0] * 12
        moves = ""
        for i in range(11):
            if p[i] == p0[i]: continue
            m = RubikCube.edge_flips[i][i + 1]
            cube2 = RubikCube()
            cube2.move(m)
            edges = cube2.getEdgePermutation()
            #print(i, edges, p0)
            cube.move(m)
            moves += " " + RubikCube.moves2string(m)
            p0[i] = p[i]
            p0[i + 1] = (p0[i + 1] + edges[i + 1][1]) & 1
        #print(p, p0)
        bflip_perm = cube.state2permutation()
        # construct b^(-1) * w * b
        cube.reset()
        cube.invPermute(bflip_perm)
        cube.invPermute(
            bcycle_perm
        )  # apply edge cycle -> may change edge orientations too
        cube.permute(perm_w)
        cube.permute(bcycle_perm)
        cube.permute(bflip_perm)
        # check result
        if [j for (i, j) in cube.getEdgePermutation()] == wb_flipgoal:
            print(p, moves)
            return p, moves
예제 #10
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def find_atwists(wa_corners):
    wa_twistgoal = [j for (i, j) in wa_corners]
    print("goal:", wa_twistgoal)
    for p in itertools.product(range(3), repeat=8):
        # check parity
        if sum(p) % 3 != 0:
            continue
        #print(p)
        # build moves that create given parity
        cube = RubikCube()
        p0 = [0] * 8
        moves = ""
        for i in range(7):
            if p[i] == p0[i]: continue
            m = RubikCube.corner_twists[i][i + 1]
            cube2 = RubikCube()
            cube2.move(m)
            corners = cube2.getCornerPermutation()
            #print(i, corners, p0)
            if p[i] == (corners[i][1] + p0[i]) % 3:  # if the move works
                p0[i + 1] = (p0[i + 1] + corners[i + 1][1]) % 3
                cube.move(m)
                moves += " " + RubikCube.moves2string(m)
            else:  # otherwise use inverse
                p0[i + 1] = (p0[i + 1] - corners[i + 1][1]) % 3
                cube.move(m, -1)
                moves += " " + RubikCube.invertMoves2String(m)
            p0[i] = p[i]
        #print(p, p0)
        atwist_perm = cube.state2permutation()
        # construct a^(-1) * w * a
        cube.reset()
        cube.invPermute(atwist_perm)
        cube.invPermute(
            acycle_perm
        )  # apply corner cycle -> may change corner orientations too
        cube.permute(perm_w)
        cube.permute(acycle_perm)
        cube.permute(atwist_perm)
        # check result
        if [j for (i, j) in cube.getCornerPermutation()] == wa_twistgoal:
            print(p, moves)
            return p, moves
예제 #11
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def checkMoves(s):
    moves = RubikCube.string2moves(s)
    print(s, "->", moves)
    print("order:", RubikCube.findOrder(moves))
예제 #12
0
파일: lokee_sol.py 프로젝트: dm248/rubik
def checkMoves(s):
    moves = RubikCube.string2moves(s)
    print(s, "->", moves)
    print("order:", RubikCube.findOrder(moves))


wStr = "U R2 F2 R2 D L2 B2 D' F2 D U2 L' R2 U B U F' L2 F R'"
waStr = "B2 D2 U' R2 D U2 B2 L R2 D' U2 L D L2 B L' U L R'"
wbStr = "L2 U L2 R2 U F2 D2 F2 R2 U R' U' L' B L2 R D B2 F' R'"

checkMoves(wStr)
checkMoves(waStr)
checkMoves(wbStr)

# move sequences (ints)
seq_wa = tuple(RubikCube.string2moves(waStr))
seq_wb = tuple(RubikCube.string2moves(wbStr))
seq_w = tuple(RubikCube.string2moves(wStr))

cube = RubikCube()
print("#w_a:")
cube.move(seq_wa)
state_wa = cube.getState()
perm_wa = cube.state2permutation()
cube.print()
print("#w:")
cube.reset()
cube.move(seq_w)
state_w = cube.getState()
perm_w = cube.state2permutation()
cube.print()