def MaxMinOpeningImproved(board, depth): """ use MINIMAX algorithm and an improved estimation to choose the move for 'MAX' """ if depth == 0: board.value = openingStaticImproved(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 = MinMaxOpeningImproved(child, depth - 1) if maxValue < result.value: maxValue = result.value retBoard = child retBoard.value = maxValue return retBoard
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