Esempio n. 1
0
 def __init__(self,
              human_names,
              computer_strategies,
              deck_file=None,
              total_turns=10):
     self.view = TerminalView()
     self.turns_remaining = total_turns
     self.deck = Deck(deck_file)
     self.discard = Deck()
     self.direction = self.CLOCKWISE
     self.current_player_index = 0
     self.top_card = self.deal_one_card()
     if "wild" in self.top_card.special:
         self.top_card.color = choice(self.COLORS)
     self.players = []
     for name in human_names:
         self.players.append(HumanPlayer(name))
     for i in range(4 - len(human_names) - len(computer_strategies)):
         computer_strategies.append("basic")
     for i, strategy_string in enumerate(
             computer_strategies[:(4 - len(human_names))]):
         if strategy_string.lower() == "random":
             self.players.append(
                 RandomComputerPlayer("Computer {} ({})".format(
                     i, strategy_string)))
         elif strategy_string.lower() == "student":
             self.players.append(
                 StudentComputerPlayer("Computer {} ({})".format(
                     i, strategy_string)))
         else:
             self.players.append(
                 ComputerPlayer("Computer {} ({})".format(
                     i, strategy_string)))
            square = o_player.get_move(game)
        else:
            square = x_player.get_move(game)

        if game.make_move(square, letter):

            if print_game:
                print(letter + f" makes move to square {square}")
                game.print_board()
                print("")

            if game.current_winner:
                if print_game:
                    print(letter + " win !")
                return letter
            # flipping players
            letter = "O" if letter == "X" else "X"

        # small break after each step
        time.sleep(0.8)

    if print_game:
        print("It\'s a tie!")


if __name__ == '__main__':
    x_player = HumanPlayer("X")
    o_player = RandomComputerPlayer("O")
    t = TicTacToe()
    play(t, x_player, o_player, print_game=True)
Esempio n. 3
0
                return letter  # ends the loop and exits the game
            letter = 'O' if letter == 'X' else 'X'  # switches player

        time.sleep(0.8)

    if print_game:
        print('It\'s a tie!')


if __name__ == '__main__':
    x_player = HumanPlayer('X')
    print("You are the X player.")
    while True:
        a = input(
            "do you want to play against random computer player(r) or smart computer player(s) or against another human player(h): "
        )
        if a == "r":
            o_player = RandomComputerPlayer('O')
            break
        elif a == "s":
            o_player = SmartComputerPlayer('O')
            break
        elif a == "h":
            o_player = HumanPlayer('O')
            break
        else:
            print('Enter valid choice!')

    t = TicTacToe()
    play(t, x_player, o_player, print_game=True)
Esempio n. 4
0
    letter = 'X'
    while game.empty_squares():
        if letter == 'O':
            square = o_player.get_move(game)
        else:
            square = x_player.get_move(game)
        if game.make_move(square, letter):

            if print_game:
                print(letter + ' makes a move to square {}'.format(square))
                game.print_board()
                print('')

            if game.current_winner:
                if print_game:
                    print(letter + ' wins!')
                return letter  # ends the loop and exits the game
            letter = 'O' if letter == 'X' else 'X'  # switches player

        time.sleep(.8)

    if print_game:
        print('It\'s a tie!')


if __name__ == '__main__':
    x_player = RandomComputerPlayer('X')
    o_player = HumanPlayer('O')
    t = TicTacToe()
    play(t, x_player, o_player, print_game=True)
Esempio n. 5
0
    while tipo_partida == "A":
        type = input(
            "Que tipo de jogo você deseja?\nA - Humano x Humano\nB - Humano - Computador"
            "\nC - Computador - Computador\n").capitalize()

        if type == "A":
            x_player = HumanPlayer("X")
            o_player = HumanPlayer("O")
        elif type == "B":
            dificuldade = input(
                "Qual nível de computador você quer enfrentar?\nA - Fácil\nB - Difícil\n"
            ).capitalize()

            if dificuldade == "A":
                x_player = HumanPlayer("X")
                o_player = RandomComputerPlayer("O")
            else:
                x_player = HumanPlayer("X")
                o_player = GeniusComputerPlayer("O")
        else:
            nivel_pc1 = input(
                "Qual nível do computador 1?\nA - Fácil\nB - Difícil\n"
            ).capitalize()
            nivel_pc2 = input(
                "Qual nível do computador 2?\nA - Fácil\nB - Difícil\n"
            ).capitalize()

            x_player = RandomComputerPlayer(
                "X") if nivel_pc1 == "A" else GeniusComputerPlayer("X")
            o_player = RandomComputerPlayer(
                "O") if nivel_pc2 == "A" else GeniusComputerPlayer("O")