Ejemplo n.º 1
0
 def test_that_it_can_check_if_the_user_move_is_valid(self, monkeypatch, capsys):
     game_params = {
         'messages': CliMessages(),
         'cli_input': FakeInput("363", "7"),
         'cli_output': Output(),
         'validator': Validator() 
     }
     name = "foo"
     test_input_strategy = InputStrategy()
     result = test_input_strategy.get_move(name, game_params)
     assert result == "7"
Ejemplo n.º 2
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"
Ejemplo n.º 3
0
 def test_that_it_can_check_if_the_user_move_is_invalid(self, monkeypatch, capsys):
     game_params = {
         'messages': CliMessages(),
         'cli_input': FakeInput("568", "4"),
         'cli_output': Output(),
         'validator': Validator() 
     }
     game_params['cli_input'].reset_count()
     name = "foo"
     test_input_strategy = InputStrategy()
     test_input_strategy.get_move(name, game_params)
     captured = capsys.readouterr()
     assert captured.out == "That was an invalid move, please try again. Please select a move between 1 - 9:\nfoo selects square 4. Placing foo's move.\n"
Ejemplo n.º 4
0
 def create_players(self, player_settings, game):
     player_settings['human_player'] = Player(player_settings['name'],
                                              player_settings['icon'],
                                              InputStrategy())
     player_settings['computer_player'] = Player(
         player_settings['computer_name'], player_settings['computer_icon'],
         MinimaxStrategy())
     return self.add_players_to_game(player_settings, game)
Ejemplo n.º 5
0
    def test_that_best_move_returns_a_move(self):
        game_params = {
            'messages': CliMessages(),
            'cli_input': FakeInput("363", "7"),
            'cli_output': Output(),
            'validator': Validator() 
        }
        board = Board()
        rules = Rules(board)
        game = Game(board, rules)
        
        human_player = Player("Player 1", "x", "foo")
        computer_player = Player("Computer", "o", "foo")
        game.add_player(human_player)
        game.add_player(computer_player)
        game.set_current_player(computer_player)

        test_input_strategy = InputStrategy()
        assert test_input_strategy.best_move(game, game_params) == "7"
Ejemplo n.º 6
0
    def test_that_run_returns_a_game_object(self, test_game_params):
        board_array = [["x", "x", "o"], ["o", "x", "o"], ["x", "o", "x"]]
        board = Board(board_array)
        rules = Rules(board)
        game = Game(board, rules)

        human_player = Player("Player 1", "x", InputStrategy())
        computer_player = Player("Computer", "o", "foo")
        game.add_player(human_player)
        game.add_player(computer_player)
        game.set_current_player(human_player)

        test_game_loop = GameLoop()
        result = test_game_loop.run(game, test_game_params)
        assert game == result
Ejemplo n.º 7
0
    def test_that_it_runs_the_loop_again_if_selected_move_is_a_filled_position(
            self, capsys, test_game_params):
        board_array = [["x", "x", "o"], ["o", None, "o"], ["x", "o", "x"]]
        board = Board(board_array)
        rules = Rules(board)
        game = Game(board, rules)

        human_player = Player("Player 1", "x", InputStrategy())
        computer_player = Player("Computer", "o", "foo")
        game.add_player(human_player)
        game.add_player(computer_player)
        game.set_current_player(human_player)

        test_game_loop = GameLoop()
        test_game_loop.place_move(game, test_game_params)
        captured = capsys.readouterr()
        expected_output = "Player 1 selects square 7. Placing Player 1's move.\nThat was an invalid move, please try again. Please select a move between 1 - 9:\nPlayer 1 selects square 5. Placing Player 1's move."
        assert captured.out.split("\n\n")[0] == expected_output
Ejemplo n.º 8
0
    def test_that_game_loop_can_mark_the_board(self, test_game_params):
        board_array = [["x", "x", "o"], ["o", None, "o"], ["x", "o", "x"]]

        expected_board_array = [["x", "x", "o"], ["o", "x", "o"],
                                ["x", "o", "x"]]
        board = Board(board_array)
        rules = Rules(board)
        game = Game(board, rules)

        human_player = Player("Player 1", "x", InputStrategy())
        computer_player = Player("Computer", "o", "foo")
        game.add_player(human_player)
        game.add_player(computer_player)
        game.set_current_player(human_player)

        test_game_loop = GameLoop()
        test_game_loop.mark_board(5, game, test_game_params)

        assert game.get_board().board() == expected_board_array