Exemple #1
0
def MaxMinMidEndImproved(board, depth):
    numWhite = MorrisGame.countNums(board.position)[0]
    if depth == 0 or numWhite < 3:
        board.value = staticMidEndImproved(board.position, depth)
        MorrisGame.numEvaluate += 1
        return board
    else:
        board.child = MorrisGame.genMoveMidEnd(board.position)

        maxValue = float('-inf')
        retBoard = None
        for child in board.child:
            result = MinMaxMidEndImproved(child, depth - 1)
            if maxValue < result.value:
                maxValue = result.value
                retBoard = child
                retBoard.value = maxValue
        return retBoard
def MaxMinMidEnd(board, depth):
    """ use MINIMAX algorithm to choose the move for 'MAX' """

    numWhite = MorrisGame.countNums(board.position)[0]
    if depth == 0 or numWhite < 3:
        board.value = MorrisGame.staticMidEnd(board.position)
        MorrisGame.numEvaluate += 1
        return board
    else:
        board.child = MorrisGame.genMoveMidEnd(board.position)

        maxValue = float('-inf')
        retBoard = None
        for child in board.child:
            result = MinMaxMidEnd(child, depth - 1)
            if maxValue < result.value:
                # retBoard = result   # for test

                maxValue = result.value
                retBoard = child
                retBoard.value = maxValue
        return retBoard
Exemple #3
0
def MaxMinABMidEnd(board, depth, alpha, beta):
    """ use Alpha-Beta pruning to choose the move for 'MAX' """

    numWhite = MorrisGame.countNums(board.position)[0]
    if depth == 0 or numWhite < 3:
        board.value = MorrisGame.staticMidEnd(board.position)
        MorrisGame.numEvaluate += 1
        return board
    else:
        board.child = MorrisGame.genMoveMidEnd(board.position)

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