Exemple #1
0
def is_180pos_solved_by_rowcell(facetosolve, rowcell, cube):
    adjrowcell = jbrik_cube.get_adjrowccell_for_rowcell(rowcell)
    adjrowcellcolor = cube.get_cell_val_by_rowcell(adjrowcell)

    # we know rowcellcolor and ccolor match because we solve that in the last phase
    nextpos = jbrik_cube.get_next_centerpos_for_face_rotation(facetosolve,
                                                              rowcell,
                                                              dir="CW")
    nextpos = jbrik_cube.get_next_centerpos_for_face_rotation(facetosolve,
                                                              nextpos,
                                                              dir="CW")

    nextposadjrowcell = jbrik_cube.get_adjrowccell_for_rowcell(nextpos)
    nextposadjrowcellccolor = cube.get_center_color_for_rowcell(
        nextposadjrowcell)

    if nextposadjrowcellccolor == adjrowcellcolor:
        log_utils.log(
            "Current rowcell: " + rowcell + " with adjcolor: " +
            adjrowcellcolor + " moved to 180pos: " + nextpos +
            " will solve 180pos by matching adjcolor to nextpos adj center color: "
            + nextposadjrowcellccolor)
        return True

    return False
def align_oppface_crossrowcell_to_adj_ccolor(facetosolve, cube):
    oppfacecrossrowcells = jbrik_cube.get_cross_rowcell_for_face(facetosolve)

    for crossrowcell in oppfacecrossrowcells:
        ccolor = cube.get_center_color_for_facenum(facetosolve)
        rowcellcolor = cube.get_cell_val_by_rowcell(crossrowcell)
        adjrowcell = jbrik_cube.get_adjrowccell_for_rowcell(crossrowcell)
        adjrowcellcolor = cube.get_cell_val_by_rowcell(adjrowcell)
        adjrowcellccolor = cube.get_center_color_for_rowcell(adjrowcell)

        # will be an issue here if all adjcell have ccolor
        if adjrowcellcolor == ccolor or rowcellcolor == ccolor:
            continue

        # if crossrowcellcolor is not facetosolve ccolor then it must be one of the adj ccolors
        testrowcell = adjrowcell
        testrowcellccolor = adjrowcellccolor
        rotcount = 0
        while adjrowcellcolor != testrowcellccolor:
            if rotcount > 3:
                log_utils.log("No solveface alignment.")
                return cube

            log_utils.log(
                "Rotate face: " + facetosolve.__str__() +
                " CW1 and check for match to adjacent face center color.")
            rotcount = rotcount + 1
            testrowcell = jbrik_cube.get_dest_pos_for_face_rotation(
                testrowcell,
                facetosolve.__str__() + "CW1")
            testrowcellccolor = cube.get_center_color_for_rowcell(testrowcell)

        # we've idetified a match, rotate here
        if rotcount > 0:
            rotstr = facetosolve.__str__() + "CW" + rotcount.__str__()
            log_utils.log("Perform transition: " + rotstr)
            cube = jbrik_solver_move_lib.perform_rotation_str(rotstr, cube)

            adjtestrowcell = jbrik_cube.get_adjrowccell_for_rowcell(
                testrowcell)
            log_utils.log("Solveface orbit rowcell: " + adjtestrowcell +
                          " of color: " + adjrowcellcolor +
                          " is aligned for LR check.")

            cube = perform_lr_solve_on_cross_rowcell(facetosolve,
                                                     adjtestrowcell, cube)
            return cube

    return cube
def perform_lr_solve_on_cross_rowcell(facetosolve, crossrowcell, cube):
    crossrowcellcolor = cube.get_cell_val_by_rowcell(crossrowcell)
    adjrowcell = jbrik_cube.get_adjrowccell_for_rowcell(crossrowcell)
    adjrowcellcolor = cube.get_cell_val_by_rowcell(adjrowcell)
    adjrowcellcolorccolor = cube.get_center_color_for_rowcell(adjrowcell)

    # if this rowcell is already aligned with adjacent color same as center color
    if adjrowcellcolor == adjrowcellcolorccolor:
        adjrowcell = jbrik_cube.get_adjrowccell_for_rowcell(crossrowcell)
        lrrowcells = jbrik_cube.get_oppface_centerrowcell_lr_middle_destcells(
            crossrowcell)
        lcrossrowcell = lrrowcells.split(" ")[0]
        rcrossrowcell = lrrowcells.split(" ")[1]

        lcrossccolor = cube.get_center_color_for_rowcell(lcrossrowcell)
        rcrossccolor = cube.get_center_color_for_rowcell(rcrossrowcell)

        if crossrowcellcolor == lcrossccolor:
            log_utils.log("Perform an L cross solve on: " + crossrowcell)
            solutionlist = get_lrcross_solution_list(facetosolve,
                                                     lcrossrowcell, adjrowcell,
                                                     "L")

            for lmove in solutionlist:
                cube = jbrik_solver_move_lib.perform_rotation_str(lmove, cube)

            if not is_middle_rowcell_solved(lcrossrowcell, cube):
                cube = swap_backwards_oriented_mid_rowcell(
                    facetosolve, lcrossrowcell, "swap", cube)

        elif crossrowcellcolor == rcrossccolor:
            log_utils.log("Perform a R cross solve on: " + crossrowcell)
            solutionlist = get_lrcross_solution_list(facetosolve,
                                                     rcrossrowcell, adjrowcell,
                                                     "R")

            for rmove in solutionlist:
                cube = jbrik_solver_move_lib.perform_rotation_str(rmove, cube)

            if not is_middle_rowcell_solved(rcrossrowcell, cube):
                cube = swap_backwards_oriented_mid_rowcell(
                    facetosolve, rcrossrowcell, "swap", cube)

    return cube
def is_middle_rowcell_solved(rowcell, cube):
    rowcellcolor = cube.get_cell_val_by_rowcell(rowcell)
    rowcellccolor = cube.get_center_color_for_rowcell(rowcell)
    adjrowcell = jbrik_cube.get_adjrowccell_for_rowcell(rowcell)
    adjrowcellcolor = cube.get_cell_val_by_rowcell(adjrowcell)
    adjrowcellccolor = cube.get_center_color_for_rowcell(adjrowcell)

    if rowcellcolor != rowcellccolor or adjrowcellcolor != adjrowcellccolor:
        return False

    return True
Exemple #5
0
def is_rowcell_solved(facetosolve, rowcell, cube):
    ccolor = cube.get_center_color_for_facenum(facetosolve)

    crosscellcolor = cube.get_cell_val_by_rowcell(rowcell)
    adjrowcell = jbrik_cube.get_adjrowccell_for_rowcell(rowcell)
    adjrowcellcolor = cube.get_cell_val_by_rowcell(adjrowcell)
    adjrowcellccolor = cube.get_center_color_for_rowcell(adjrowcell)

    if crosscellcolor != ccolor or adjrowcellcolor != adjrowcellccolor:
        return False

    return True
Exemple #6
0
def is_crosscorner_solved((cube, rowcell)):
    facenum = jbrik_cube.get_face_for_rowcell(rowcell)

    ccolor = cube.get_center_color_for_facenum(facenum)
    if cube.get_cell_val_by_rowcell(rowcell) != ccolor:
        return False

    adjrowcells = jbrik_cube.get_adjrowccell_for_rowcell(rowcell)
    for adjrowcell in adjrowcells:
        if cube.get_cell_val_by_rowcell(
                adjrowcell) != cube.get_center_color_for_rowcell(adjrowcell):
            return False

    return True
def swap_non_oriented_mid_rowcells_to_top(facetosolve, cube):
    # change this to get all mid row cells
    for rowcell in jbrik_cube.MIDDLE_ROWCCELLS:
        rowcellcolor = cube.get_cell_val_by_rowcell(rowcell)
        rowcellccolor = cube.get_center_color_for_rowcell(rowcell)
        adjrowcell = jbrik_cube.get_adjrowccell_for_rowcell(rowcell)
        adjrowcellcolor = cube.get_cell_val_by_rowcell(adjrowcell)
        adjrowcellccolor = cube.get_center_color_for_rowcell(adjrowcell)
        ccolor = cube.get_center_color_for_facenum(facetosolve)

        if (rowcellcolor != rowcellccolor and adjrowcellcolor != adjrowcellccolor and rowcellcolor != ccolor
            and adjrowcellcolor != ccolor) \
           or (rowcellcolor == rowcellccolor and adjrowcellcolor == ccolor):

            log_utils.log(
                "Rowcell: " + rowcell +
                " is either a total missalign or solved by an LR swap, with "
                "cell color: " + rowcellcolor + " and adjacent color: " +
                adjrowcellcolor)

            movedir = jbrik_cube.get_centerrow_orbit_trans_dir(rowcell)

            # get middle cell in the direction of movement and if it's solved skip this transition
            midlrs = jbrik_cube.MIDDLE_ROWCCELLS_LR_ADJ[rowcell]

            movestrlist = ""
            if movedir == "L":
                if is_middle_rowcell_solved(midlrs.split(" ")[0], cube):
                    return cube

                movestrlist = get_lrcross_solution_list(
                    facetosolve, adjrowcell, rowcell, "L")
            else:
                if is_middle_rowcell_solved(midlrs.split(" ")[1], cube):
                    return cube

                movestrlist = get_lrcross_solution_list(
                    facetosolve, adjrowcell, rowcell, "R")

            movestrlist.append(facetosolve.__str__() + "CW2")

            # one time put is in the right place but reverse
            for i in range(0, 3):
                for rmove in movestrlist:
                    cube = jbrik_solver_move_lib.perform_rotation_str(
                        rmove, cube)

            return cube

    return cube
def swap_backwards_oriented_mid_rowcell(facetosolve, rowcell, swaptype, cube):
    rowcellcolor = cube.get_cell_val_by_rowcell(rowcell)
    rowcellccolor = cube.get_center_color_for_rowcell(rowcell)
    adjrowcell = jbrik_cube.get_adjrowccell_for_rowcell(rowcell)
    adjrowcellcolor = cube.get_cell_val_by_rowcell(adjrowcell)
    adjrowcellccolor = cube.get_center_color_for_rowcell(adjrowcell)

    # check orientation
    if rowcellcolor == adjrowcellccolor and adjrowcellcolor == rowcellccolor:
        log_utils.log("Rowcell: " + rowcell +
                      " is backwards oriented, swapping.")
        if jbrik_cube.FIVESIXMIDROWCROSSROWCELLS_L.__contains__(rowcell):
            # its a leftswap
            #movestrlist = get_leftcross_solution_list(facetosolve, adjrowcell, rowcell)
            movestrlist = get_lrcross_solution_list(facetosolve, adjrowcell,
                                                    rowcell, "L")
            log_utils.log("leftswap " + swaptype + " rowcell: " + rowcell +
                          " of color: " + rowcellccolor +
                          " and adjacent cell: " + adjrowcell +
                          " with color: " + adjrowcellcolor)
        else:
            # its a rightswap
            #movestrlist = get_rightcross_solution_list(facetosolve, adjrowcell, rowcell)
            movestrlist = get_lrcross_solution_list(facetosolve, adjrowcell,
                                                    rowcell, "R")
            log_utils.log("Rightswap " + swaptype + " rowcell: " + rowcell +
                          " of color: " + rowcellccolor +
                          " and adjacent cell: " + adjrowcell +
                          " with color: " + adjrowcellcolor)

        for rmove in movestrlist:
            cube = jbrik_solver_move_lib.perform_rotation_str(rmove, cube)

        cube = jbrik_solver_move_lib.perform_rotation_str("3CW2", cube)

        if swaptype != "back":
            for rmove in movestrlist:
                cube = jbrik_solver_move_lib.perform_rotation_str(rmove, cube)

    return cube
Exemple #9
0
def move_oppface_corner_into_oppfaceorbit(cube, oppface, ccolor):
    # we know solveface is one because we're solving the cross, could dynamically figure out though using oppface
    solveface = 1

    oppfaceorbit = jbrik_cube.FACEORBITS[oppface]
    oppfacecornerrowcells = jbrik_cube.get_cornercell_rowcells_for_face(
        oppface)
    solvefacecornerrowcells = jbrik_cube.get_cornercell_rowcells_for_face(
        solveface)

    unsolvedcorner = ""
    unsolvedadjfaces = []
    # identify first unsolved corner on solveface
    for solverowcell in solvefacecornerrowcells:
        if not is_crosscorner_solved((cube, solverowcell)):
            log_utils.log(solverowcell + " is not solved")
            unsolvedcorner = solverowcell
            solverowcelladjcells = jbrik_cube.get_adjrowccell_for_rowcell(
                solverowcell)
            for solveadjrowcell in solverowcelladjcells:
                unsolvedadjfaces.append(
                    jbrik_cube.get_face_for_rowcell(solveadjrowcell))

            unsolvedadjfaces.sort()

        if unsolvedcorner != "":
            break

    # get first cccolor cell on oppface
    for rowcell in oppfacecornerrowcells:
        if cube.get_cell_val_by_rowcell(rowcell) == ccolor:
            log_utils.log("Move : " + rowcell + " to opposite face orbit.")
            adjcell = jbrik_cube.get_non_oppface_adj_rowcell_for_corner(
                rowcell, oppface)

            # before determining rotface move rowcell to under unsolved corner
            # rotate oppface unit rowcell shares the same adjfaces as solveadjrowcell
            for oppfacecornerrowcell in oppfacecornerrowcells:
                destrowcelladjfaces = []
                destrowcelladjrowcells = jbrik_cube.get_adjrowccell_for_rowcell(
                    oppfacecornerrowcell)
                for destrowcelladjrowcell in destrowcelladjrowcells:
                    destrowcelladjfaces.append(
                        jbrik_cube.get_face_for_rowcell(destrowcelladjrowcell))

                destrowcelladjfaces.sort()
                if destrowcelladjfaces == unsolvedadjfaces:
                    break

            log_utils.log("Rotate face: " + oppface.__str__() + " until " +
                          oppfacecornerrowcell + " is color: " + ccolor)
            rotcount = 0
            destrowcell = rowcell
            while destrowcell != oppfacecornerrowcell:
                destrowcell = jbrik_cube.get_next_pos_for_face_rotation(
                    oppface, destrowcell)
                rotcount += 1

            rotstr = oppface.__str__() + "CW" + rotcount.__str__()
            if rotcount > 0:
                cube = jbrik_solver_move_lib.perform_rotation_str(rotstr, cube)

            # pick a face to rotate, doesn't matter which because oppfacecornerrowcell is under an unsolved rowcell
            rotface = unsolvedadjfaces[0]

            # rotface need to be the face that puts the unsolved corner onto the orbit
            rotdir = "CW"
            # try CW rotation
            destrowcell = jbrik_cube.get_next_pos_for_face_rotation(
                rotface, oppfacecornerrowcell)
            if not oppfaceorbit.__contains__(destrowcell):
                rotdir = "CC"

            rotstr = rotface.__str__() + rotdir + "1"
            unwindmove = jbrik_solver_move_lib.reversetransition(rotstr)
            log_utils.log(
                "Rotate face: " + rotstr +
                " to put target<??> into position for 2nd order solve.")
            cube = jbrik_solver_move_lib.perform_rotation_str(rotstr, cube)

            log_utils.log(
                "Rotate face: " + oppface.__str__() +
                " 180 to move target<??> out of the way of the unwind move: " +
                unwindmove)
            rotstr = oppface.__str__() + rotdir + "2"
            cube = jbrik_solver_move_lib.perform_rotation_str(rotstr, cube)

            log_utils.log("Performing unwind: " + unwindmove)
            cube = jbrik_solver_move_lib.perform_rotation_str(unwindmove, cube)

    return cube
Exemple #10
0
def facecross_o3(cube, ccolor, facetosolve):
    unwindlist = []
    resultpos = ""

    # identify the next rowcell that needs to be faced
    for rowcelltoface in jbrik_cube.get_cross_rowcell_for_face(facetosolve):
        log_utils.log("Checking state of " + rowcelltoface)
        if cube.get_cell_val_by_rowcell(rowcelltoface) != ccolor:
            log_utils.log(rowcelltoface + " is the rowcell to face.\n")
            resultpos = rowcelltoface
            break

    if resultpos == "":
        log_utils.log("No more cross positions to face on face: " +
                      facetosolve.__str__())
        return cube

    # identify the first rowcell we can move into resultpos
    opptosolveface = jbrik_cube.OPPOSITEFACES[facetosolve]
    rowcelltomove = ""
    for facenum in range(1, 7):
        log_utils.log("Checking face: " + facenum.__str__() +
                      " for cross cells that can face: " + resultpos)
        if facenum == facetosolve or facenum == opptosolveface:
            log_utils.log("Skipping solve/opp face: " + facenum.__str__())
            continue

        rowcelltomove = get_centerrowcell_of_color_from_face(
            cube, facenum, ccolor)
        if rowcelltomove != "":
            break

    # rotate rowcell into middle row if needed by checking if CW rotation puts rowcelltomove adj oppface or solveface
    if rowcelltomove != "":
        rotdir = "CW"
        rotface = jbrik_cube.get_face_for_rowcell(rowcelltomove)
        nextpos = jbrik_cube.get_next_centerpos_for_face_rotation(
            rotface, rowcelltomove)
        resultposadjface = jbrik_cube.get_adj_face_for_rowcell(resultpos)

        # if nextpos is not adj to oppface or solveface we want to go there
        rowcelladjtonextpos = jbrik_cube.get_adjrowccell_for_rowcell(nextpos)
        nextposadjface = jbrik_cube.get_face_for_rowcell(rowcelladjtonextpos)
        if nextposadjface != opptosolveface and nextposadjface != facetosolve:
            # first align resultpos to to the face we want to rotate
            rotcount = 0
            while cube.get_cell_val_by_rowcell(resultpos) == ccolor:
                rotcount = rotcount + 1
                cube = jbrik_solver_move_lib.perform_rotation_str(
                    facetosolve.__str__() + "CW1", cube, False)
            if rotcount > 0:
                movestr = facetosolve.__str__() + "CW" + rotcount.__str__()
                log_utils.log("Perform transition: " + movestr)
                cube.get_current_solve_move_list().append(movestr)

            rotface = jbrik_cube.get_face_for_rowcell(rowcelltomove)
            log_utils.log("Rotating face: " + rotface.__str__() + " " +
                          "CW1 to move: " + rowcelltomove +
                          " into position: " + nextpos +
                          " for next rotation to opposite face.")
            movestr = rotface.__str__() + "CW1"
            cube = jbrik_solver_move_lib.perform_rotation_str(movestr, cube)
            rowcelltomove = nextpos

        # Were in the middle row at this point and in o1 position, either use an o1 transition or use a static move set to find face and move
        if nextposadjface == resultposadjface:
            log_utils.log("Rowcell: " + nextpos +
                          " is in first order solve position for: " +
                          resultpos)
            o1move = jbrik_cube.get_crosscenter_solvface_trans(nextpos)
            cube = jbrik_solver_move_lib.perform_rotation_str(o1move, cube)

            return cube

        # we're in o2 position (solveface rotation) but a non midrow because we're on a 4/6 face
        if jbrik_cube.FIVESIXMIDROWCROSSROWCELLS.__contains__(rowcelltomove):
            log_utils.log(
                rowcelltomove +
                " is an o2 position but non mid row because it on a 4/6 face")
            nextposmovestr = jbrik_cube.get_crosscenter_solvface_trans(
                rowcelltomove)
            resultpos = jbrik_cube.get_dest_pos_for_face_rotation(
                rowcelltomove, nextposmovestr)

            rotcount = 0
            while cube.get_cell_val_by_rowcell(resultpos) == ccolor:
                rotcount = rotcount + 1
                cube = jbrik_solver_move_lib.perform_rotation_str(
                    facetosolve.__str__() + "CW1", cube, False)
            if rotcount > 0:
                movestr = facetosolve.__str__() + "CW" + rotcount.__str__()
                log_utils.log("Performed transition: " + movestr)
                cube.get_current_solve_move_list().append(movestr)

            # resultpos is now ready to be faced
            cube = jbrik_solver_move_lib.perform_rotation_str(
                nextposmovestr, cube)

            return cube

        # we're in a middle row but a non o1 position rotate a non face position into the dest cell for nextpos
        if rowcelltomove != opptosolveface and rowcelltomove != facetosolve:
            # identify the destination of the next nextpos rotation
            nextposmovestr = jbrik_cube.get_crosscenter_solvface_trans(
                rowcelltomove)
            resultpos = jbrik_cube.get_dest_pos_for_face_rotation(
                rowcelltomove, nextposmovestr)

            rotcount = 0
            while cube.get_cell_val_by_rowcell(resultpos) == ccolor:
                rotcount = rotcount + 1
                cube = jbrik_solver_move_lib.perform_rotation_str(
                    facetosolve.__str__() + "CW1", cube, False)
            if rotcount > 0:
                movestr = facetosolve.__str__() + "CW" + rotcount.__str__()
                log_utils.log("Perform transition: " + movestr)
                cube.get_current_solve_move_list().append(movestr)

            # resultpos is now ready to be faced
            cube = jbrik_solver_move_lib.perform_rotation_str(
                nextposmovestr, cube)

            return cube

        # we're on the oppface orbit,
        # rotate solveface until rowcelltomove and rowcelltoface share an adjface
        # rotate the adjface until rowcelltoface is ccolor, might be a transition for this get_facetrans_to_resultin_rowcell(rowcelltomove)
        print(" if we made it this far nextpos is on oppface orbit??")

        print("should never get here eject")

    return cube