def test_upward_diagonal_win(self): o_token = OToken() grid = Grid(3, 3) grid_controller = GridController() grid_controller.assign_grid(grid) grid.add_token_position(o_token, 0, 2) grid.add_token_position(o_token, 1, 1) grid.add_token_position(o_token, 2, 0) winner = grid_controller.check_for_win() assert winner == o_token
def test_downward_diagonal_win(self): x_token = XToken() grid = Grid(3, 3) grid_controller = GridController() grid_controller.assign_grid(grid) grid.add_token_position(x_token, 0, 0) grid.add_token_position(x_token, 1, 1) grid.add_token_position(x_token, 2, 2) winner = grid_controller.check_for_win() assert winner == x_token
def test_horizontal_win(self): x_token = XToken() grid = Grid(3, 3) grid_controller = GridController() grid_controller.assign_grid(grid) grid.add_token_position(x_token, 0, 0) grid.add_token_position(x_token, 0, 1) grid.add_token_position(x_token, 0, 2) winner = grid_controller.check_for_win() assert winner == x_token
def test_no_winner_board_full(self): x_token = XToken() o_token = OToken() grid = Grid(3, 3) grid_controller = GridController() grid_controller.assign_grid(grid) grid.add_token_position(x_token, 0, 0) grid.add_token_position(x_token, 0, 1) grid.add_token_position(x_token, 1, 2) grid.add_token_position(x_token, 2, 0) grid.add_token_position(x_token, 2, 1) grid.add_token_position(o_token, 0, 2) grid.add_token_position(o_token, 1, 0) grid.add_token_position(o_token, 1, 1) grid.add_token_position(o_token, 2, 2) winner = grid_controller.check_for_win() assert winner is None assert grid_controller.grid_is_full()
def test_entire_game_with_two_AI(self): new_game = Game() new_game.game_mode = 2 token_1 = XToken() token_2 = OToken() tokens = (token_1, token_2) new_game.add_token_options(tokens) game_controller = GameController() game_controller.assign_game(new_game) player_one = Player() player_two = Player() players = [player_one, player_two] game_controller.add_players_to_game(players) player_one_controller = AIPlayerController() player_two_controller = AIPlayerController() player_one_controller.assign_player(player_one) player_two_controller.assign_player(player_two) player_controllers = [player_one_controller, player_two_controller] player_one_controller.determine_name() player_two_controller.determine_name() random.shuffle(player_controllers) game_controller.assign_tokens(player_controllers) new_game.print_players() grid = Grid(3, 3) grid_controller = GridController() grid_controller.assign_grid(grid) while not new_game.game_over: game_controller.play_round(player_controllers, grid_controller)
player_two_controller = AIPlayerController() else: player_one_controller = HumanPlayerController() player_two_controller = HumanPlayerController() player_one_controller.assign_player(player_one) player_two_controller.assign_player(player_two) player_controllers = [player_one_controller, player_two_controller] print(data.PLAYER_ONE_FIRST_MESSAGE) player_one_controller.determine_name() print(data.PLAYER_TWO_NEXT_MESSAGE) player_two_controller.determine_name() print(data.RANDOMLY_SELECT_FIRST_PLAYER) random.shuffle(player_controllers) game_controller.assign_tokens(player_controllers) new_game.print_players() grid = Grid(data.GRID_ROWS, data.GRID_COLUMNS) grid_controller = GridController() grid_controller.assign_grid(grid) while not new_game.game_over: game_controller.play_round(player_controllers, grid_controller) play_again = input(data.PLAY_AGAIN_MESSAGE) if str.lower(play_again) not in ["yes", "y"]: break