Beispiel #1
0
def test_a_completed_game_is_no_longer_in_progress(players):
    game_over_board = Board(['X', 'X', 'X', ' ', ' ', ' ', ' ', ' ', ' '])
    game = Game(players[0], players[1], game_over_board)
    console_io = MockConsoleIO()
    console = Console(console_io)
    game.game_over(console)

    assert not game.in_progress()
Beispiel #2
0
def test_displays_the_board_and_a_message_on_game_over(players):
    game_over_board = Board(['X', 'X', 'X', ' ', ' ', ' ', ' ', ' ', ' '])
    game = Game(players[0], players[1], game_over_board)
    console_io = MockConsoleIO()
    console = Console(console_io)
    game.game_over(console)

    assert console_io.print_output_call_count == 2
def test_accepts_data_from_networked_connection_then_converts_to_computer_readable_index(
):
    server = MockServer(input='1')
    player_1 = NetworkedHumanPlayer('Player 1', 'X', server)
    player_2 = SimpleComputerPlayer('Player 2', 'O')
    game = Game(player_1, player_2)

    assert player_1.get_move(game) == 0
def test_sends_a_json_representation_of_the_game_to_be_saved(save_game_json_data):
    persister_io = MockPersisterIO()
    persister = Persister(persister_io)
    board = Board(['X', 'O', 'X', 'O', '5', '6', '7', '8', '9'])
    player_1 = SimpleComputerPlayer('Player 1', 'O')
    player_2 = SimpleComputerPlayer('Player 2', 'X')
    game = Game(player_1, player_2, board)

    persister.save('myfile.txt', game)

    assert persister_io.saved_data == save_game_json_data
Beispiel #5
0
def test_a_game_which_is_stopped_while_in_progress_gets_saved():
    player_1 = MockPlayer('player 1', 'O', [])
    player_2 = MockPlayer('player 2', 'X', [])
    io = MockConsoleIO([])
    persister_io = MockPersisterIO()
    persister = Persister(persister_io)
    game_runner = GameRunner(Console(io), persister)
    game_runner._game = Game(player_1, player_2)


    game_runner.stop()

    assert persister_io.saved_data is not None
def test_if_save_data_exists_new_save_is_added_with_an_incremented_save_id(save_game_json_data):
    persister_io = MockPersisterIO(save_game_json_data)
    persister = Persister(persister_io)
    board = Board(['X', 'O', 'X', 'O', '5', '6', '7', '8', '9'])
    player_1 = SimpleComputerPlayer('Player 1', 'O')
    player_2 = SimpleComputerPlayer('Player 2', 'X')
    game = Game(player_1, player_2, board)

    persister.save('myfile.txt', game)

    updated_data = json.loads(persister_io.saved_data)

    assert len(updated_data) == 2
    assert '2' in list(updated_data.keys())
Beispiel #7
0
def game(players):
    return Game(first_player=players[0], second_player=players[1])
Beispiel #8
0
    def setup_game(self, board_state):
        board = Board(board_state)
        player_1 = SmartComputerPlayer('Player 1', 'X')
        player_2 = SmartComputerPlayer('Player 2', 'O')

        return Game(player_1, player_2, board)