Пример #1
0
def test_orientation_transform(orientation, turn):
    cube1 = Cube((3, 3, 3))
    cube2 = Cube((3, 3, 3))

    turn.perform(cube1, orientation)
    origin = Orientation()
    turn.from_orientation(orientation, origin).perform(cube2, origin)

    for side in Side:
        o = Orientation.regular(side)
        assert str(cube1.get_side(o).colors) == str(cube2.get_side(o).colors)
Пример #2
0
    def from_arguments(args: Namespace, cube: Cube, parser: ArgumentParser) -> Optional["Label"]:
        if args.label_data is None:
            return None

        image, scale = args.label_data
        texture = Texture(image, GL_RGBA, flip=True, mipmap=True)
        if args.label_side is not None:
            side = args.label_side
        else:
            side = Side.TOP

        face = cube.get_side(Orientation.regular(side))
        if args.label_position is not None:
            i, j = args.label_position
            if i < 0 or i >= face.rows:
                parser.error(f"invalid label row: it must be between 0 and {face.rows - 1}")
                return None
            if j < 0 or j >= face.columns:
                parser.error(f"invalid label column: it must be between 0 and {face.columns - 1}")
                return None
        else:
            i = face.rows // 2
            j = face.columns // 2

        return Label(scale, texture, side, i, j)
Пример #3
0
    def test_apply_side(self):
        cube = Cube((2, 2, 2))
        colors = [[Color.WHITE, Color.RED], [Color.ORANGE, Color.GREEN]]

        apply_side(cube, self.orientation, colors)
        actual_colors = [[
            cube.get_side(self.orientation).colors[i, j] for j in [0, 1]
        ] for i in [0, 1]]
        assert colors == actual_colors
Пример #4
0
def test_get_side():
    orientation: Orientation = Orientation(Side.LEFT, Side.TOP)
    orientation.get_side_rotation = MagicMock()
    orientation.get_side_rotation.return_value = 0

    cube = Cube((3, 3, 3))
    side = cube.get_side(orientation)
    assert isinstance(side, CubeSide)
    assert side == cube.sides[Side.LEFT]
Пример #5
0
def assert_solved(cube: Cube):
    for front in Side:
        face = cube.get_side(Orientation.regular(front))
        color = None
        for row in range(face.rows):
            for column in range(face.columns):
                c = face.colors[row, column]
                if color is None:
                    color = c
                else:
                    assert c == color
Пример #6
0
def assert_cube(cube: Cube, front: str, right: str, back: str, left: str,
                top: str, bottom: str) -> None:
    orientation = Orientation()
    assert front == side_to_string(cube.get_side(orientation))
    assert right == side_to_string(cube.get_side(orientation.to_right))
    assert back == side_to_string(cube.get_side(orientation.to_right.to_right))
    assert left == side_to_string(cube.get_side(orientation.to_left))
    assert top == side_to_string(cube.get_side(orientation.to_top))
    assert bottom == side_to_string(cube.get_side(orientation.to_bottom))
Пример #7
0
def sample_cube() -> Cube:
    cube = Cube((3, 3, 3))
    orientation = Orientation()
    assert orientation.get_side_rotation() == 0

    red = cube.get_side(orientation)
    _set_side_colors(red, [[Color.ORANGE, Color.RED, Color.GREEN],
                           [Color.YELLOW, Color.RED, Color.GREEN],
                           [Color.BLUE, Color.WHITE, Color.GREEN]])

    green = cube.get_side(orientation.to_right)
    _set_side_colors(green, [[Color.RED, Color.ORANGE, Color.ORANGE],
                             [Color.RED, Color.GREEN, Color.WHITE],
                             [Color.RED, Color.GREEN, Color.WHITE]])

    orange = cube.get_side(orientation.to_left.to_left)
    _set_side_colors(orange, [[Color.YELLOW, Color.YELLOW, Color.RED],
                              [Color.ORANGE, Color.ORANGE, Color.WHITE],
                              [Color.ORANGE, Color.ORANGE, Color.GREEN]])

    blue = cube.get_side(orientation.to_left)
    _set_side_colors(blue, [[Color.YELLOW, Color.YELLOW, Color.YELLOW],
                            [Color.BLUE, Color.BLUE, Color.RED],
                            [Color.ORANGE, Color.WHITE, Color.WHITE]])

    yellow = cube.get_side(orientation.to_top)
    _set_side_colors(yellow, [[Color.BLUE, Color.GREEN, Color.GREEN],
                              [Color.BLUE, Color.YELLOW, Color.YELLOW],
                              [Color.BLUE, Color.BLUE, Color.WHITE]])

    white = cube.get_side(orientation.to_bottom)
    _set_side_colors(white, [[Color.RED, Color.GREEN, Color.YELLOW],
                             [Color.RED, Color.WHITE, Color.ORANGE],
                             [Color.WHITE, Color.BLUE, Color.BLUE]])

    assert_cube(cube, "ORG/YRG/BWG", "ROO/RGW/RGW", "YYR/OOW/OOG",
                "YYY/BBR/OWW", "BGG/BYY/BBW", "RGY/RWO/WBB")
    return cube
Пример #8
0
def main():
    arg_parser = ArgumentParser()
    arg_parser.add_argument("-d",
                            dest="dimension",
                            help="dimensions of a cube",
                            default=3,
                            metavar="N",
                            type=integer_type(2))
    arg_parser.add_argument("-n",
                            dest="turns_num",
                            help="number of turns",
                            type=integer_type(1),
                            default=20)
    arg_parser.add_argument(
        "-a",
        dest="output_args",
        action="store_true",
        help=
        "display the state of the cube after the turns instead of the formula")
    arg_parser.add_argument(
        "-s",
        dest="seed",
        help="the seed for the pseudorandom number generator")
    args = arg_parser.parse_args()
    dim = args.dimension

    if args.seed is not None:
        random.seed(args.seed)

    actions: List[Turn] = []
    prev_side = None
    for i in range(args.turns_num):
        if prev_side is None:
            sides = SIDES
        else:
            sides = [x for x in SIDES if x != prev_side]

        prev_side = random.choice(sides)

        first_index = random.randint(1, dim // 2)
        last_index = random.randint(1, first_index)
        if first_index == last_index:
            indices = [first_index]
        else:
            indices = [last_index, ..., first_index]

        turn = Turn(prev_side, indices, random.randint(1, 3))
        actions.append(turn)

    if not args.output_args:
        for action in actions:
            print(str(action), end="")
        print()
    else:
        cube = Cube((dim, ) * 3)
        orientation = Orientation()
        for action in actions:
            action.perform(cube, orientation)

        print("--front", repr(cube.get_side(orientation).colors))
        print("--right", repr(cube.get_side(orientation.to_right).colors))
        print("--left", repr(cube.get_side(orientation.to_left).colors))
        print("--back",
              repr(cube.get_side(orientation.to_right.to_right).colors))
        print("--top", repr(cube.get_side(orientation.to_top).colors))
        print("--bottom", repr(cube.get_side(orientation.to_bottom).colors))