Ejemplo n.º 1
0
def test_adapter():
    mode = Director().construct_game_mode(FlexSquareBuilder())
    board = Board(mode)
    adapter = AiAdapter(AI.init())

    move = adapter.get_step(board)
    assert move[:2] != move[2:]
    assert abs(move[0] - move[2]) <= 2 and abs(move[1] - move[3])

    assert board.do_move(*move) is True
Ejemplo n.º 2
0
    def __init__(self, screen: pygame.Surface, operator: GuiOperator):
        self.screen = screen
        self.operator = operator
        self.title = Text(screen, (250, 20), "Выбор режима", 50)
        builders = [
            ClassicModeBuilder(),
            AdvancedModeBuilder(),
            FlexSquareBuilder(),
            KingPoliceModeBuilder(),
            WallModeBuilder(),
            AllUnitsModeBuilder()
        ]

        director = Director()

        modes = [director.construct_game_mode(builder) for builder in builders]

        ai_mode = AiDecorator(
            director.construct_game_mode(FlexSquareBuilder()),
            AiAdapter(AI.init()))
        ai_mode.name = "Диагональные уголки с ИИ"

        modes.append(ai_mode)

        buttons = [
            CheckButton(screen, (100, 100 + 60 * i, 440, 45), modes[i].name)
            for i in range(len(modes))
        ]

        self.mod_pairs = list(zip(buttons, modes))

        self.back_button = Button(screen, (590, 590, 100, 60), 'Назад')
        self.go_button = Button(screen, (100, 590, 180, 60), 'Играть!',
                                colors.RED, colors.WHITE)

        self.chosen_mode = None
        self.checked_button = None
Ejemplo n.º 3
0
def test_decorator():
    mode = Director().construct_game_mode(FlexSquareBuilder())
    adapter = AiAdapter(AI.init())
    new_mode = AiDecorator(mode, adapter)
    assert hasattr(new_mode, 'ai')
    assert ModeFeature.AI in new_mode.features