Exemplo n.º 1
0
def test_game_ends_if_user_occupies_3_in_diagonal():
    win_config = WinningCombos(3)
    win_config.create_winning_combos()
    game_board = Board()
    game_board.board_state = ["X", "O", "O", "O", "X", "", "O", "", "X"]
    assert EndStates.did_a_player_win(game_board.board_state, 'X',
                                      win_config.winning_combos) == True
Exemplo n.º 2
0
def test_winning_combos_are_created_for_3x3_board():
    win_config = WinningCombos(3)
    win_config.create_winning_combos()
    assert win_config.winning_combos == [
        [0, 1, 2],
        [3, 4, 5],
        [6, 7, 8],
        [0, 3, 6],
        [1, 4, 7],
        [2, 5, 8],
        [0, 4, 8],
        [2, 4, 6],
    ]
Exemplo n.º 3
0
            if EndStates.is_draw(current_state):
                Ui.msg('DRAW. GameOver')
                return True

            if User.current_player == player1:
                User.switch_current_user(User.current_player, player2)
            else:
                User.switch_current_user(User.current_player, player1)


def begin_game(mode_choosen, current_state, player1, player2):
    if mode_choosen == "1":
        return GameModes.human_v_human(current_state, player1, player2)
    if mode_choosen == "2":
        return GameModes.human_v_computer(current_state, player1, player2)
    if mode_choosen == "3":
        return GameModes.computer_v_computer(current_state, player1, player2)


if __name__ == "__main__":
    game_board = Board()
    game_board.new_game(3)
    win_config = WinningCombos(3)
    win_config.create_winning_combos()
    player1 = User("X")
    player2 = User("O")
    mode_choice = UserActions.pick_game_mode()
    begin_game(mode_choice, game_board.board_state, player1.symbol,
               player2.symbol)