예제 #1
0
def MinMaxOpeningImproved(board, depth):
    """ use MINIMAX algorithm and an improved estimation to choose the move for 'MIN' """

    if depth == 0:
        board.value = openingStaticImproved(board.position)
        MorrisGame.numEvaluate += 1
        return board
    else:
        board.child = MorrisGame.genMoveOpeningBlack(board.position)

        minValue = float('inf')
        retBoard = None
        for child in board.child:
            result = MaxMinOpeningImproved(child, depth - 1)
            if minValue > result.value:
                minValue = result.value
                retBoard = child
                retBoard.value = minValue
        return retBoard
예제 #2
0
def MinMaxABOpening(board, depth, alpha, beta):
    """ use Alpha-Beta pruning to choose the move for 'MIN' """

    if depth == 0:
        board.value = MorrisGame.openingStatic(board.position)
        MorrisGame.numEvaluate += 1
        return board
    else:
        board.child = MorrisGame.genMoveOpeningBlack(board.position)

        minValue = float('inf')
        retBoard = None
        for child in board.child:
            result = MaxMinABOpening(child, depth - 1, alpha, beta)
            if minValue > result.value:
                minValue = result.value
                retBoard = child
                retBoard.value = minValue
            if minValue <= alpha:
                return retBoard
            elif minValue < beta:
                beta = minValue
        return retBoard