def test_first_step(self):
        goals = [
            'DFR',
            'DFL',
            'BDL',
            'BDR',
            'BRU',
            'BLU',
            'FLU',
        ]

        for goal in goals:
            c = Cube()
            solver = WhiteFaceSolver(c)
            # Muahaha at that range
            for i in range(1 if goal == 'DFR' else 0, 3):
                c.cubies[goal].facings[goal[i % 3]] = 'W'
                c.cubies[goal].facings[goal[(i + 1) % 3]] = 'Y'
                c.cubies[goal].facings[goal[(i + 2) % 3]] = 'O'

                steps = WhiteFaceSolver.first_step(goal, goal[i % 3])

                for s in steps:
                    c.move(Move(s))

                self.assertIn('W', c.cubies['FRU'].colors,
                              "%s --> %d" % (goal, i))
                self.assertIn('Y', c.cubies['FRU'].colors,
                              "%s --> %d" % (goal, i))
                self.assertIn('O', c.cubies['FRU'].colors,
                              "%s --> %d" % (goal, i))
    def test_corner_is_placed(self):
        c = Cube()
        solver = YellowFaceSolver(c)
        for _ in range(4):
            c.move(Move('U'))
            for corner in ['FRU', 'FLU', 'BRU', 'BLU']:
                self.assertTrue(solver.corner_is_placed(corner))
            self.assertTrue(solver.placed_corners())

        for corner in ['FRU', 'FLU', 'BRU', 'BLU']:
            c = Cube()
            solver = YellowFaceSolver(c)
            c.cubies[corner].facings[corner[0]] = 'W'
            self.assertFalse(solver.corner_is_placed(corner))
Exemple #3
0
    def test_steps(self):
        cubies = ['BLU', 'BU', 'BRU', 'LU', 'U', 'RU', 'FLU', 'FU', 'FRU']
        orientations = {
            2: {
                '1': 'BU',
                '3': 'LU',
                '5': 'RU',
                '7': 'FU'
            },
            3: {
                '0': 'BLU',
                '2': 'RBU',
                '6': 'LFU',
                '8': 'FRU'
            }
        }
        cr = Cube()
        for orientation, steps in PLLSolver.STEPS.items():
            c = Cube()
            for i, oriented in enumerate(orientation):
                if i != 4:  # The center cubie doesn't need to be relocated
                    cubie_or = cubies[i]
                    cubie_dest = cubies[int(oriented)]
                    orient_or = orientations[len(cubie_or)][str(i)]
                    orient_dest = orientations[len(cubie_or)][oriented]
                    kwargs = {}
                    for j, orient in enumerate(orient_or):
                        kwargs[orient_dest[j]] = cr.cubies[cubie_or].facings[
                            orient].color
                    c.cubies[cubie_dest] = Cubie(**kwargs)

            for s in steps:
                c.move(Move(s))

            while cr.cubies['F'].facings['F'] != c.cubies['F'].facings['F']:
                c.move(Move('Y'))

            for cubie in cr.cubies:
                for facing in cr.cubies[cubie].facings:
                    self.assertEqual(
                        cr.cubies[cubie].facings[facing],
                        c.cubies[cubie].facings[facing],
                        msg=
                        '%s != %s -> Fail PLL with %s orientation on cubie %s'
                        % (cr.cubies[cubie].facings[facing].color,
                           c.cubies[cubie].facings[facing].color, orientation,
                           cubie))
Exemple #4
0
    def test_solution(self):
        for i in range(1):
            c = Cube()
            cr = Cube()
            c.shuffle(i)
            cross_steps = WhiteCrossSolver(c).solution()
            solution = self._test_solution(c)
            # Align faces
            while cr.cubies['F'].facings['F'] != c.cubies['F'].facings['F']:
                c.move(Move('Y'))

            for cubie in cr.cubies:
                for facing in cr.cubies[cubie].facings:
                    # Upper cubies aren't positioned
                    if 'U' not in cubie:
                        self.assertEqual(cr.cubies[cubie].facings[facing],
                                         c.cubies[cubie].facings[facing])
Exemple #5
0
    def test_steps(self):
        for orientation, steps in OLLSolver.STEPS.items():
            c = Cube()
            for i, cubie in enumerate(
                ['BLU', 'BU', 'BRU', 'LU', 'U', 'RU', 'FLU', 'FU', 'FRU']):
                for facing in cubie:
                    if facing == orientation[i]:
                        c.cubies[cubie].facings[facing].color = 'Y'
                    else:
                        c.cubies[cubie].facings[facing].color = 'W'

            for s in steps:
                c.move(Move(s))

            for i, cubie in enumerate(
                ['BLU', 'BU', 'BRU', 'LU', 'U', 'RU', 'FLU', 'FU', 'FRU']):
                self.assertEqual(
                    c.cubies[cubie].facings['U'].color,
                    'Y',
                    msg='%s != %s -> Fail OLL with %s orientation on cubie %s'
                    % (c.cubies[cubie].facings['U'], 'Y', orientation, cubie))
Exemple #6
0
    def test_steps(self):
        for corner in F2LSolver.STEPS:
            for edge, steps in F2LSolver.STEPS[corner].items():
                c = Cube()
                tmp = c.cubies[Cube._t_key(corner)]
                orig_corner = ''.join([
                    tmp.facings[corner[0]].color, tmp.facings[corner[1]].color,
                    tmp.facings[corner[2]].color
                ])
                tmp = c.cubies[Cube._t_key(edge)]
                orig_edge = ''.join([
                    tmp.facings[edge[0]].color,
                    tmp.facings[edge[1]].color,
                ])

                for s in steps:
                    c.move(Move(s))

                dest_corner = ''.join([
                    c.cubies['DFR'].facings['F'].color,
                    c.cubies['DFR'].facings['R'].color,
                    c.cubies['DFR'].facings['D'].color,
                ])

                dest_edge = ''.join([
                    c.cubies['FR'].facings['F'].color,
                    c.cubies['FR'].facings['R'].color,
                ])

                self.assertEqual(
                    dest_corner,
                    orig_corner,
                    msg='Failed F2L corner check corner:%s edge:%s (%s != %s)'
                    % (corner, edge, dest_corner, orig_corner))
                self.assertEqual(
                    dest_edge,
                    orig_edge,
                    msg='Failed F2L edge check corner:%s edge:%s (%s != %s)' %
                    (corner, edge, dest_edge, orig_edge))
    def test_solution(self):
        cases = [
            ('D', 'F'),
            ('D', 'B'),
            ('D', 'R'),
            ('D', 'L'),
            ('F', 'U'),
            ('F', 'D'),
            ('F', 'R'),
            ('F', 'L'),
            ('B', 'U'),
            ('B', 'D'),
            ('B', 'R'),
            ('B', 'L'),
            ('R', 'U'),
            ('R', 'D'),
            ('R', 'F'),
            ('R', 'B'),
            ('L', 'U'),
            ('L', 'D'),
            ('L', 'F'),
            ('L', 'B'),
        ]

        for c0, c1 in cases:
            c = Cube()
            # Use an "imposible" edge to move, so it is not duped in the cube
            c.cubies[c._t_key(c0 + c1)].facings[c0].color = 'W'
            c.cubies[c._t_key(c0 + c1)].facings[c1].color = 'Y'

            steps = WhiteCrossSolver.first_step(c0, c1)
            for step in steps:
                c.move(Move(step))

            place = c.search_by_colors('W', 'Y')
            self.assertEqual(c.cubies[place].facings['U'], 'W')
            # Weird, but works
            self.assertEqual(c.cubies[place].facings[place.replace('U', '')],
                             'Y')
    def test_second_step(self):
        # Case 1
        c = Cube()
        c.cubies['FRU'].facings['F'] = 'W'
        c.cubies['FRU'].facings['R'] = 'Y'
        c.cubies['FRU'].facings['U'] = 'O'
        steps = WhiteFaceSolver.second_step('F')
        for s in steps:
            c.move(Move(s))

        self.assertEqual(c.cubies['DFR'].facings['D'], 'W')
        self.assertEqual(c.cubies['DFR'].facings['F'], 'O')
        self.assertEqual(c.cubies['DFR'].facings['R'], 'Y')
        # Case 2
        c = Cube()
        c.cubies['FRU'].facings['F'] = 'O'
        c.cubies['FRU'].facings['R'] = 'W'
        c.cubies['FRU'].facings['U'] = 'Y'
        steps = WhiteFaceSolver.second_step('R')
        for s in steps:
            c.move(Move(s))

        self.assertEqual(c.cubies['DFR'].facings['D'], 'W')
        self.assertEqual(c.cubies['DFR'].facings['F'], 'O')
        self.assertEqual(c.cubies['DFR'].facings['R'], 'Y')
        # Case 3
        c = Cube()
        c.cubies['FRU'].facings['F'] = 'O'
        c.cubies['FRU'].facings['R'] = 'Y'
        c.cubies['FRU'].facings['U'] = 'W'
        steps = WhiteFaceSolver.second_step('U')
        for s in steps:
            c.move(Move(s))

        self.assertEqual(c.cubies['DFR'].facings['D'], 'W')
        self.assertEqual(c.cubies['DFR'].facings['F'], 'Y')
        self.assertEqual(c.cubies['DFR'].facings['R'], 'O')
 def test_edges_are_placed(self):
     c = Cube()
     solver = YellowFaceSolver(c)
     for _ in range(4):
         c.move(Move('U'))
         self.assertTrue(solver.edges_are_placed())