Beispiel #1
0
    def solve_via_table(self):
        '''
        For grins I built a full lookup table for 2x2x2, it is too large to put in the
        repo though and the solver from stackoverflow works just fine but I'll leave
        this here for a rainy day.

        lookup-table-2x2x2-solve.txt
        ============================
        1 steps has 18 entries (0 percent, 0.00x previous step)
        2 steps has 244 entries (0 percent, 13.56x previous step)
        3 steps has 2,874 entries (0 percent, 11.78x previous step)
        4 steps has 28,000 entries (0 percent, 9.74x previous step)
        5 steps has 205,416 entries (0 percent, 7.34x previous step)
        6 steps has 1,168,516 entries (1 percent, 5.69x previous step)
        7 steps has 5,402,628 entries (6 percent, 4.62x previous step)
        8 steps has 20,776,176 entries (23 percent, 3.85x previous step)
        9 steps has 45,391,616 entries (51 percent, 2.18x previous step)
        10 steps has 15,139,616 entries (17 percent, 0.33x previous step)
        11 steps has 64,736 entries (0 percent, 0.00x previous step)

        Total: 88,179,840 entries
        '''
        self.lt = LookupTable(self, 'lookup-table-2x2x2-solve.txt', 'all',
                              'UUUULLLLFFFFRRRRBBBBDDDD')
        self.lt.solve()
        self.compress_solution()
    def lt_init(self):
        if self.lt_init_called:
            return
        self.lt_init_called = True

        '''
        Stage the inner X-centers
        24!/(8!*16!) is 735,471

        lookup-table-6x6x6-step10-UD-inner-x-centers-stage.txt
        ======================================================
        1 steps has 5 entries (0 percent, 0.00x previous step)
        2 steps has 82 entries (0 percent, 16.40x previous step)
        3 steps has 1,206 entries (0 percent, 14.71x previous step)
        4 steps has 14,116 entries (1 percent, 11.70x previous step)
        5 steps has 123,404 entries (16 percent, 8.74x previous step)
        6 steps has 422,508 entries (57 percent, 3.42x previous step)
        7 steps has 173,254 entries (23 percent, 0.41x previous step)
        8 steps has 896 entries (0 percent, 0.01x previous step)

        Total: 735,471 entries
        '''
        self.lt_UD_inner_x_centers_stage = LookupTable(self,
                                                      'lookup-table-6x6x6-step10-UD-inner-x-centers-stage.txt',
                                                      '666-UD-inner-X-centers-stage',
                                                      '066000000000000000000660',
                                                      True,  # state_hex
                                                      linecount=735471)

        '''
        lookup-table-6x6x6-step21-UD-oblique-edge-pairing-left-only.txt
        lookup-table-6x6x6-step22-UD-oblique-edge-pairing-right-only.txt
        ===============================================================
        1 steps has 3 entries (0 percent, 0.00x previous step)
        2 steps has 29 entries (0 percent, 9.67x previous step)
        3 steps has 238 entries (1 percent, 8.21x previous step)
        4 steps has 742 entries (5 percent, 3.12x previous step)
        5 steps has 1,836 entries (14 percent, 2.47x previous step)
        6 steps has 4,405 entries (34 percent, 2.40x previous step)
        7 steps has 3,774 entries (29 percent, 0.86x previous step)
        8 steps has 1,721 entries (13 percent, 0.46x previous step)
        9 steps has 122 entries (0 percent, 0.07x previous step)

        Total: 12,870 entries
        '''
        self.lt_UD_oblique_edge_pairing_left_only = LookupTable(self,
                                                                'lookup-table-6x6x6-step21-UD-oblique-edge-pairing-left-only.txt',
                                                                '666-UD-oblique-edge-pairing-left-only',
                                                                '990000000099',
                                                                True, # state_hex
                                                                linecount=12870)

        self.lt_UD_oblique_edge_pairing_right_only = LookupTable(self,
                                                                'lookup-table-6x6x6-step22-UD-oblique-edge-pairing-right-only.txt',
                                                                '666-UD-oblique-edge-pairing-right-only',
                                                                '660000000066',
                                                                True, # state_hex
                                                                linecount=12870)

        '''
        Now pair the UD oblique edges so that we can reduce the 6x6x6 centers to a 5x5x5
        (24!/(8!*16!))^2 is 540,917,591,841 so this is too large for us to build so use
        IDA and build it 8 steps deep.

        Our prune tables will be to solve on the left or right oblique edges. Each of these
        tables are 24!/(8!*16!) or 735,471
        735471/540917591841 is 0.0000013596729171

        Originally I did what is described above but the IDA search took 4 minutes
        (on my laptop) for some cubes...I can only imagine how long that would
        take on a 300Mhz EV3.  To speed this up I did something unusual here...I
        rebuilt the step20 table but restricted moves so that UD obliques can
        only move to sides UFDB. The cube will be very scrambled though and
        there will be UD obliques on sides LR.  What I do is "fake move" these
        obliques to side UDFB so that I can use the step20 table.  At that point
        there will only be UD obliques on sides ULDR so I then do a rotate_y()
        one time to make LR free of UD obliques again. Then I do another lookup
        in the step20 table.

        I only build the table to 9-deep, it would have 165 million entries if
        I built it the whole way out but that would be too large tou check into
        the repo so I use IDA.

        lookup-table-6x6x6-step20-UD-oblique-edge-pairing.txt
        =====================================================
        1 steps has 3 entries (0 percent, 0.00x previous step)
        2 steps has 29 entries (0 percent, 9.67x previous step)
        3 steps has 286 entries (0 percent, 9.86x previous step)
        4 steps has 2,052 entries (0 percent, 7.17x previous step)
        5 steps has 16,348 entries (0 percent, 7.97x previous step)
        6 steps has 127,859 entries (0 percent, 7.82x previous step)
        7 steps has 844,248 entries (3 percent, 6.60x previous step)
        8 steps has 4,623,585 entries (18 percent, 5.48x previous step)
        9 steps has 19,019,322 entries (77 percent, 4.11x previous step)

        Total: 24,633,732 entries
        '''
        self.lt_UD_oblique_edge_pairing = LookupTableIDA(self,
                                                         'lookup-table-6x6x6-step20-UD-oblique-edge-pairing.txt',
                                                         '666-UD-oblique-edge-pairing',
                                                         'ff00000000ff',
                                                         True, # state_hex
                                                         moves_6x6x6,

                                                         ("3Rw", "3Rw'", "3Lw", "3Lw'", "3Fw", "3Fw'", "3Bw", "3Bw'", # These would break up the staged UD inner x-centers
                                                          "Fw", "Fw'", "Bw", "Bw'",
                                                          "3Uw", "3Uw'", "3Dw", "3Dw'", "Uw", "Uw'", "Dw", "Dw'"),

                                                         # prune tables
                                                         (self.lt_UD_oblique_edge_pairing_left_only,
                                                          self.lt_UD_oblique_edge_pairing_right_only),
                                                         linecount=24633732)

        '''
        16!/(8!*8!) is 12,870

        lookup-table-6x6x6-step30-LR-inner-x-centers-stage.txt
        ======================================================
        1 steps has 3 entries (0 percent)
        2 steps has 29 entries (0 percent)
        3 steps has 234 entries (1 percent)
        4 steps has 1,246 entries (9 percent)
        5 steps has 4,466 entries (34 percent)
        6 steps has 6,236 entries (48 percent)
        7 steps has 656 entries (5 percent)

        Total: 12,870 entries
        '''
        self.lt_LR_inner_x_centers_stage = LookupTable(self,
                                                      'lookup-table-6x6x6-step30-LR-inner-x-centers-stage.txt',
                                                      '666-LR-inner-X-centers-stage',
                                                      '000006600000066000000000',
                                                      True, # state_hex
                                                      linecount=12870)

        '''
        lookup-table-6x6x6-step41-LR-oblique-pairing-left-only.txt
        lookup-table-6x6x6-step42-LR-oblique-pairing-right-only.txt
        ==========================================================
        1 steps has 3 entries (0 percent, 0.00x previous step)
        2 steps has 29 entries (0 percent, 9.67x previous step)
        3 steps has 238 entries (1 percent, 8.21x previous step)
        4 steps has 742 entries (5 percent, 3.12x previous step)
        5 steps has 1836 entries (14 percent, 2.47x previous step)
        6 steps has 4405 entries (34 percent, 2.40x previous step)
        7 steps has 3774 entries (29 percent, 0.86x previous step)
        8 steps has 1721 entries (13 percent, 0.46x previous step)
        9 steps has 122 entries (0 percent, 0.07x previous step)

        Total: 12870 entries
        '''
        self.lt_LR_oblique_edge_pairing_left_only = LookupTable(self,
                                                                'lookup-table-6x6x6-step41-LR-oblique-pairing-left-only.txt',
                                                                '666-LR-oblique-edge-pairing-left-only',
                                                                '99009900',
                                                                True, # state_hex
                                                                linecount=12870)

        self.lt_LR_oblique_edge_pairing_right_only = LookupTable(self,
                                                                'lookup-table-6x6x6-step42-LR-oblique-pairing-right-only.txt',
                                                                '666-LR-oblique-edge-pairing-right-only',
                                                                '66006600',
                                                                True, # state_hex
                                                                linecount=12870)
        '''
        (16!/(8!*8!))^2 is 165,636,900
        I only built this 8 deep to keep the table in the repo small thus the IDA

        lookup-table-6x6x6-step40-LR-oblique-pairing.txt
        ================================================
        1 steps has 3 entries (0 percent)
        2 steps has 29 entries (0 percent)
        3 steps has 286 entries (0 percent)
        4 steps has 2,052 entries (0 percent)
        5 steps has 16,348 entries (0 percent)
        6 steps has 127,859 entries (0 percent)
        7 steps has 844,248 entries (0 percent)
        8 steps has 4,623,585 entries (2 percent)
        9 steps has 19,019,322 entries (11 percent)
        10 steps has 47,544,426 entries (28 percent)
        11 steps has 61,805,656 entries (37 percent)
        12 steps has 28,890,234 entries (17 percent)
        13 steps has 2,722,462 entries (1 percent)
        14 steps has 40,242 entries (0 percent)
        15 steps has 148 entries (0 percent)

        Total: 165,636,900 entries
        '''
        self.lt_LR_oblique_edge_pairing = LookupTableIDA(self,
                                                         'lookup-table-6x6x6-step40-LR-oblique-pairing.txt',
                                                         '666-LR-oblique-edge-pairing',
                                                         'ff00ff00',
                                                         True, # state_hex
                                                         moves_6x6x6,

                                                         # These would break up the staged UD inner x-centers
                                                         ("3Rw", "3Rw'", "3Lw", "3Lw'", "3Fw", "3Fw'", "3Bw", "3Bw'", # do not mess up UD x-centers
                                                          "Rw", "Rw'", "Lw", "Lw'", "Fw", "Fw'", "Bw", "Bw'",         # do not mess up UD oblique pairs
                                                          "3Uw", "3Uw'", "3Dw", "3Dw'"),                              # do not mess up LR x-centers

                                                         # prune tables
                                                         (self.lt_LR_oblique_edge_pairing_left_only,
                                                          self.lt_LR_oblique_edge_pairing_right_only),
                                                         linecount=5614410)

        '''
        lookup-table-6x6x6-step50-UD-solve-inner-x-center-and-oblique-edges.txt
        ========================================================================
        1 steps has 9 entries (0 percent, 0.00x previous step)
        2 steps has 47 entries (0 percent, 5.22x previous step)
        3 steps has 232 entries (0 percent, 4.94x previous step)
        4 steps has 1,001 entries (0 percent, 4.31x previous step)
        5 steps has 4,266 entries (1 percent, 4.26x previous step)
        6 steps has 16,697 entries (4 percent, 3.91x previous step)
        7 steps has 52,894 entries (15 percent, 3.17x previous step)
        8 steps has 114,134 entries (33 percent, 2.16x previous step)
        9 steps has 113,888 entries (33 percent, 1.00x previous step)
        10 steps has 37,136 entries (10 percent, 0.33x previous step)
        11 steps has 2,696 entries (0 percent, 0.07x previous step)

        Total: 343,000 entries
        '''
        self.lt_UD_solve_inner_x_centers_and_oblique_edges = LookupTable(self,
                                                                         'lookup-table-6x6x6-step50-UD-solve-inner-x-center-and-oblique-edges.txt',
                                                                         '666-UD-centers-oblique-edges-solve',
                                                                         'xUUxUUUUUUUUxUUxxDDxDDDDDDDDxDDx',
                                                                         False, # state_hex
                                                                         linecount=343000)

        '''
        lookup-table-6x6x6-step61-LR-solve-inner-x-center-and-oblique-edges.txt
        ========================================================================
        1 steps has 5 entries (0 percent, 0.00x previous step)
        2 steps has 40 entries (0 percent, 8.00x previous step)
        3 steps has 228 entries (0 percent, 5.70x previous step)
        4 steps has 1,142 entries (0 percent, 5.01x previous step)
        5 steps has 5,240 entries (0 percent, 4.59x previous step)
        6 steps has 20,914 entries (0 percent, 3.99x previous step)
        7 steps has 78,886 entries (0 percent, 3.77x previous step)
        8 steps has 272,733 entries (1 percent, 3.46x previous step)
        9 steps has 844,382 entries (3 percent, 3.10x previous step)
        10 steps has 2,204,738 entries (9 percent, 2.61x previous step)
        11 steps has 4,507,592 entries (18 percent, 2.04x previous step)
        12 steps has 6,560,576 entries (27 percent, 1.46x previous step)
        13 steps has 6,029,508 entries (25 percent, 0.92x previous step)
        14 steps has 2,918,224 entries (12 percent, 0.48x previous step)
        15 steps has 545,008 entries (2 percent, 0.19x previous step)
        16 steps has 20,784 entries (0 percent, 0.04x previous step)
        17 steps has 34 entries (0 percent, 0.00x previous step)

        Total: 24,010,034 entries
        '''
        self.lt_LR_solve_inner_x_centers_and_oblique_edges = LookupTable(self,
                                                                         'lookup-table-6x6x6-step61-LR-solve-inner-x-center-and-oblique-edges.txt',
                                                                         '666-LR-centers-oblique-edges-solve',
                                                                         'xLLxLLLLLLLLxLLxxxxxxFFxxFFxxxxxxRRxRRRRRRRRxRRxxxxxxBBxxBBxxxxx',
                                                                         False, # state_hex
                                                                         linecount=24010034)


        '''
        lookup-table-6x6x6-step60-LFRB-solve-inner-x-center-and-oblique-edges.txt
        ==========================================================================
        1 steps has 5 entries (0 percent, 0.00x previous step)
        2 steps has 54 entries (0 percent, 10.80x previous step)
        3 steps has 420 entries (0 percent, 7.78x previous step)
        4 steps has 2,703 entries (0 percent, 6.44x previous step)
        5 steps has 18,740 entries (0 percent, 6.93x previous step)
        6 steps has 118,707 entries (0 percent, 6.33x previous step)
        7 steps has 707,156 entries (2 percent, 5.96x previous step)
        8 steps has 3,945,650 entries (15 percent, 5.58x previous step)
        9 steps has 20,886,476 entries (81 percent, 5.29x previous step)

        Total: 25,679,911 entries
        '''
        self.lt_LFRB_solve_inner_x_centers_and_oblique_edges = LookupTableIDA(self,
                                                         'lookup-table-6x6x6-step60-LFRB-solve-inner-x-center-and-oblique-edges.txt',
                                                         '666-LFRB-centers-oblique-edges-solve',
                                                         'xLLxLLLLLLLLxLLxxFFxFFFFFFFFxFFxxRRxRRRRRRRRxRRxxBBxBBBBBBBBxBBx',
                                                         False, # state_hex
                                                         moves_6x6x6,

                                                         ("3Rw", "3Rw'", "3Lw", "3Lw'", "3Fw", "3Fw'", "3Bw", "3Bw'", "3Uw", "3Uw'", "3Dw", "3Dw'", # do not mess up staged centers
                                                          "Rw", "Rw'", "Lw", "Lw'", "Fw", "Fw'", "Bw", "Bw'", "Uw", "Uw'", "Dw", "Dw'",             # do not mess up staged centers
                                                          "3Rw2", "3Lw2", "3Fw2", "3Bw2", "Rw2", "Lw2", "Fw2", "Bw2",                               # do not mess up solved UD
                                                          "L", "L'", "L2", "R", "R'", "R2"), # do not mess up LR sides that we staged via self.lt_LR_solve_inner_x_centers_and_oblique_edges.solve()

                                                         # prune tables
                                                         (self.lt_LR_solve_inner_x_centers_and_oblique_edges,),
                                                         linecount=25679911)
Beispiel #3
0
    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',
          'r') as fh:
    for line in fh:
        states_to_find.append(line.strip())
'''