Пример #1
0
    def test_that_run_returns_a_game_over_message(self, capsys):
        board = [
            ["@", "x", "x"],
            ["x", "@", "x"],
            ["@", "x", "@"],
        ]
        test_board = Board(board)
        test_rules = Rules(test_board)
        test_game = Game(test_board, test_rules)
        test_game_over = GameOver()

        game_params = {
            'messages': FakeCliMessages(),
            'game_input': Input(),
            'cli_output': Output(),
            'validator': Validator()
        }

        human_player = Player("Player 1", "x", "foo")
        computer_player = Player("Computer", "@", "foo")
        test_game.add_player(human_player)
        test_game.add_player(computer_player)

        test_game.set_current_player(computer_player)

        test_game_over.run(test_game, game_params)
        captured = capsys.readouterr()
        assert captured.out.strip().split("\n")[-1] == "game has ended"
Пример #2
0
 def test_valid_game_config(self):
     game_params = {
         'messages': CliMessages(),
         'cli_input': Input(),
         'cli_output': Output(),
         'validator': Validator()
     }
     return game_params
Пример #3
0
 def test_that_it_can_return_a_user_move(self, monkeypatch):
     game_params = {
         'messages': CliMessages(),
         'cli_input': Input(),
         'cli_output': Output(),
         'validator': Validator() 
     }
     test_input_strategy = InputStrategy()
     monkeypatch.setattr('builtins.input', lambda x: " 5  ")
     i = test_input_strategy.get_move("player name", game_params)
     assert i == "5"
Пример #4
0
    def test_input_move(self):
        game_params = {
            'messages': CliMessages(),
            'cli_input': Input(),
            'cli_output': Output(),
            'validator': Validator()
        }
        board = Board()
        rules = Rules(board)
        game = Game(board, rules)

        strategy = FakeInputStrategy()
        human_player = Player("player 1", "x", strategy)
        assert human_player.select_move(game, game_params) == 5
Пример #5
0
    def test_minimax_move(self):
        game_params = {
            'messages': CliMessages(),
            'cli_input': Input(),
            'cli_output': Output(),
            'validator': Validator()
        }
        board = Board()
        rules = Rules(board)
        game = Game(board, rules)

        strategy = FakeMinimaxStrategy()
        computer_player = Player("computer", "o", strategy)

        assert computer_player.select_move(game, game_params) == "5"
Пример #6
0
    def run(self):
        messages = CliMessages()
        
        game_params = {
            'messages': messages,
            'cli_input': Input(),
            'cli_output': Output(),
            'validator': Validator()
        }

        board = Board()
        rules = Rules(board)
        game = Game(board, rules)

        game = GameConfig().run(game, game_params)
        game = GameLoop().run(game, game_params)
        GameOver().run(game, game_params)
Пример #7
0
 def test_game_params(self):
     return {
         'messages': CliMessages(),
         'game_input': Input(),
         'validator': Validator(),
     }
Пример #8
0
 def test_it_can_get_user_input(self, monkeypatch):
     monkeypatch.setattr('builtins.input', lambda x: "foo")
     message = "Please enter some text for dummy input"
     test_input = Input()
     assert test_input.get_input(message) == "foo"