コード例 #1
0
def openingStaticImproved(position):
    """ improve the static estimation by adding the number of potential mills and number of double mills """

    piecesDiff = MorrisGame.openingStatic(position)
    num2PiecesConf = count2PiecesConf(position)
    if num2PiecesConf >= 2:
        num3PiecesConf = num2PiecesConf - 1
    else:
        num3PiecesConf = 0

    # staticEs = 6 * piecesDiff + 12 * num2PiecesConf + 7 * num3PiecesConf + 26 * countMills(position)
    # staticEs = piecesDiff + 6 * num2PiecesConf
    staticEs = piecesDiff + 2 * num2PiecesConf + 10 * num3PiecesConf
    return staticEs
コード例 #2
0
def MinMaxOpening(board, depth):
    """ use MINIMAX algorithm 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 = MaxMinOpening(child, depth - 1)
            if minValue > result.value:
                retBoard = result  # for test
                minValue = result.value
                retBoard = child
                retBoard.value = minValue
        return retBoard
コード例 #3
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
コード例 #4
0
def MaxMinABOpening(board, depth, alpha, beta):
    """ use Alpha-Beta pruning to choose the move for 'MAX' """

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

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