def _determine_move(game:Othello, moves:list) -> tuple:
    """
    This function will simulate the opponent's move and return the move with the best result.
    :rtype : tuple
    :param game: Othello
    :param moves: list
    """
    computer_ai = game.current_player()
    result = moves[0]
    win_most = game._game_state.win_with_most
    if win_most:
        best_score = 0
    else:
        best_score = 256
    for move in moves:
        score = 0
        test = copy.deepcopy(game)
        test.move(move[0],move[1])
        if computer_ai == Othello.BLACK:
            score += test.black_score()
        else:
            score += test.white_score()
        if test.current_player() != computer_ai:
            opponent_moves = _find_moves(test)
            for opponent_move in opponent_moves:
                test2 = copy.deepcopy(test)
                test2.move(opponent_move[0], opponent_move[1])
                if win_most:
                    if computer_ai == Othello.BLACK:
                        if score + test.black_score() > best_score:
                            best_score = score + test.black_score()
                            result = move
                        elif score + test.black_score() == best_score:
                            choice = [result, move]
                            result = choice[random.randrange(len(choice))]
                    else:
                        if score + test.white_score() > best_score:
                            best_score = score + test.white_score()
                            result = move
                        elif score + test.white_score() == best_score:
                            choice = [result, move]
                            result = choice[random.randrange(len(choice))]
                else:
                    if computer_ai == Othello.BLACK:
                        if score + test.black_score() < best_score:
                            best_score = score + test.black_score()
                            result = move
                        elif score + test.black_score() == best_score:
                            choice = [result, move]
                            result = choice[random.randrange(len(choice))]
                    else:
                        if score + test.white_score() < best_score:
                            best_score = score + test.white_score()
                            result = move
                        elif score + test.white_score() == best_score:
                            choice = [result, move]
                            result = choice[random.randrange(len(choice))]
    return result
예제 #2
0
def _determine_move(game: Othello, moves: list) -> tuple:
    """
    This function will simulate the opponent's move and return the move with the best result.
    :rtype : tuple
    :param game: Othello
    :param moves: list
    """
    computer_ai = game.current_player()
    result = moves[0]
    win_most = game._game_state.win_with_most
    if win_most:
        best_score = 0
    else:
        best_score = 256
    for move in moves:
        score = 0
        test = copy.deepcopy(game)
        test.move(move[0], move[1])
        if computer_ai == Othello.BLACK:
            score += test.black_score()
        else:
            score += test.white_score()
        if test.current_player() != computer_ai:
            opponent_moves = _find_moves(test)
            for opponent_move in opponent_moves:
                test2 = copy.deepcopy(test)
                test2.move(opponent_move[0], opponent_move[1])
                if win_most:
                    if computer_ai == Othello.BLACK:
                        if score + test.black_score() > best_score:
                            best_score = score + test.black_score()
                            result = move
                        elif score + test.black_score() == best_score:
                            choice = [result, move]
                            result = choice[random.randrange(len(choice))]
                    else:
                        if score + test.white_score() > best_score:
                            best_score = score + test.white_score()
                            result = move
                        elif score + test.white_score() == best_score:
                            choice = [result, move]
                            result = choice[random.randrange(len(choice))]
                else:
                    if computer_ai == Othello.BLACK:
                        if score + test.black_score() < best_score:
                            best_score = score + test.black_score()
                            result = move
                        elif score + test.black_score() == best_score:
                            choice = [result, move]
                            result = choice[random.randrange(len(choice))]
                    else:
                        if score + test.white_score() < best_score:
                            best_score = score + test.white_score()
                            result = move
                        elif score + test.white_score() == best_score:
                            choice = [result, move]
                            result = choice[random.randrange(len(choice))]
    return result
예제 #3
0
def _score_board(game: Othello) -> None:
    """
    This function prints out the score board with the current player.
    :rtype : None
    :param game: Othello
    """
    blackscore = 'Black:  ' + str(game.black_score())
    whitescore = "White:  " + str(game.white_score())
    print()
    print(''.center(50, '-'))
    print('|' + blackscore.center(24, ' ') + whitescore.center(24, ' ') + '|')
    if game.current_player() == Othello.BLACK:
        print('|' + "Black's turn".center(48, ' ') + '|')
    else:
        print('|' + "White's turn".center(48, ' ') + '|')
    print(''.center(50, '-'))