예제 #1
0
def p1vsai():
    clearScreen()

    diff = difficulty()
    time.sleep(1.5)

    board = Board()
    turns_taken = 0
    possible_nums = [str(i) for i in range(1, 10)]
    last_move, AI_XO, p1_XO = chooseXO()

    while turns_taken < 9:
        clearScreen()
        board.print_board()

        if last_move == "p1":
            print("Bot's turn")
            time.sleep(1.5)
            if diff == "E":
                possible_nums = AI_turn_easy(board, possible_nums, AI_XO,
                                             p1_XO)
            elif diff == "H":
                possible_nums = AI_turn_hard(board, possible_nums, AI_XO,
                                             p1_XO)
            elif diff == "I":
                possible_nums = AI_turn_impossible(board, possible_nums, AI_XO,
                                                   p1_XO)
            last_move = "AI"

        elif last_move == "AI":
            print("Player 1's turn")
            possible_nums = p1_turn(board, possible_nums, p1_XO)
            last_move = "p1"

        win = check_win(board, turns_taken)
        if win == None:
            pass
        else:
            break

        turns_taken += 1

    clearScreen()
    board.print_board()

    if win == AI_XO:
        print("Bot wins. You lose :(")
        time.sleep(1.5)
    elif win == p1_XO:
        print("You win :) Congratulations!")
        time.sleep(1.5)
    else:
        print("It was a draw")
        time.sleep(1.5)

    time.sleep(1.5)
예제 #2
0
def aivsai():
    clearScreen()

    board = Board()
    turns_taken = 0
    possible_nums = [str(i) for i in range(1, 10)]
    print("Bot 1 is 'O' and will go first")
    print("Bot 2 is 'X' and will go second")
    time.sleep(2)
    AI1_XO = "O"
    AI2_XO = "X"
    last_move = "AI2"

    AI1_moves = [AI_turn_easy, AI_turn_hard, AI_turn_impossible]
    AI2_moves = [AI_turn_easy, AI_turn_hard, AI_turn_impossible]

    while turns_taken < 9:
        clearScreen()
        board.print_board()

        if last_move == "AI2":
            print("Bot 1's Turn")
            time.sleep(1.5)
            possible_nums = random.choice(AI1_moves)(board, possible_nums,
                                                     AI1_XO, AI2_XO)
            last_move = "AI1"
        elif last_move == "AI1":
            print("Bot 2's turn")
            time.sleep(1.5)
            possible_nums = random.choice(AI2_moves)(board, possible_nums,
                                                     AI2_XO, AI1_XO)
            last_move = "AI2"

        win = check_win(board, turns_taken)
        if win == None:
            pass
        else:
            break

        turns_taken += 1

    clearScreen()
    board.print_board()

    if win == AI1_XO:
        print("Bot 1 wins!")
        time.sleep(1.5)
    elif win == AI2_XO:
        print("Bot 2 wins!")
        time.sleep(1.5)
    else:
        print("It was a draw")
        time.sleep(1.5)

    time.sleep(1.5)
예제 #3
0
    def play_game(self):
        P1 = Player(self.player_1_type, 1)
        P2 = Player(self.player_2_type, 2)
        B = Board()
        player_list = [P1, P2]
        turn_count = 0
        error_count = 0
        winner_id = ''

        while turn_count < 42:
            current_player = player_list[turn_count % 2]
            move, piece = current_player.make_move_master(B.board_dict)
            # print("You are here. This is move we got coming in: " + str(move))

            if B.is_error(move) != 0:
                if B.is_error(int(move)) == 1:
                    print('ERROR CODE 1 move not int!')
                    error_count += 1
                    # print('Error count: ' + str(error_count))
                    continue
                if B.is_error(int(move)) == 2:
                    print('ERROR CODE 2 move not 1-7!')
                    error_count += 1
                    # print('Error count: ' + str(error_count))
                    if current_player.player_type == 'Human':
                        continue
                    else:
                        break
                if B.is_error(int(move)) == 3:
                    # print('ERROR CODE 3 move off board')
                    error_count += 1
                    # print('Error count: ' + str(error_count))
                    continue
            error_count = 0

            B.board_move(move, piece)
            if self.print_status == 2:
                B.print_board()
            if B.is_win() is True:
                winner_id = (turn_count % 2) + 1
                print("Game Won!!!")
                break
            turn_count += 1
        if winner_id == '':
            winner_id = 3

        if self.print_status == 1 or self.print_status == 2:
            print("FINAL BOARD: ")
            B.print_board()
            print(B.board_dict)
            print('')
            print(B.move_list)

        return winner_id, B.board_dict
예제 #4
0
 def make_move_human(self, board_dict):
     temp_B = Board()
     temp_B.board_dict = board_dict.copy()
     temp_B.print_board()
     user_move = input("Make move: ")
     return int(user_move)