在minmax算法中,如何确定函数何时到达树的末尾并中断递归调用。
我做了一个max函数,其中调用了min函数。在最小函数中,我应该做什么??对于max函数,我只返回最高分。

def maxAgent(gameState, depth):
      if (gameState.isWin()):
        return gameState.getScore()
      actions = gameState.getLegalActions(0);
      bestScore = -99999
      bestAction = Directions.STOP

      for action in actions:
        if (action != Directions.STOP):
          score = minAgent(gameState.generateSuccessor(0, action), depth, 1)
          if (score > bestScore):
            bestScore = score
            bestAction = action
      return bestScore

def minvalue(gameState,depth,agentIndex):
       if (gameState.isLose()):
         return gameState.getScore()
       else:
         finalstage = False
         number = gameState.getNumAgents()
         if (agentIndex == number-1):
           finalstage = True
           bestScore = 9999
           for action in gameState.getLegalActions(agentIndex):
             if(action != Directions.STOP

我不明白现在该怎么办?我不允许设置树的深度限制。它必须是任意的。

最佳答案

通常要搜索到一定的递归深度(例如,下棋时n提前移动)。因此,应该将当前递归深度作为参数传递。如果你能不费吹灰之力就做出决定,你可能会在结果没有改善时提前中止。

10-06 07:09