最小最大算法蟒蛇 [英] min max algorithm in python
问题描述
在最小最大算法,如何确定当您的函数到达树的端部和打破递归调用
In the minmax algorithm,How to determine when your function reaches the end of the tree and break the recursive calls.
我已经做了最大功能,其中我打电话的分钟功能。在分功能,什么shud我做的?对于最大的功能,我只是返回bestscore。
I have made a max function in which I am calling the min function. In the min function , what shud I do?? For max function, I am just returning the bestscore.
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
我不明白现在该怎么进行呢?我不允许设置树的深度极限。它必须是任意的。
I could not understand how to proceed now?I not allowed to set the limit of depth of tree. it has to be arbitrary.
推荐答案
通常你要搜索,直到一定的递归深度(例如,正提前移动,下棋的时候)。因此,你应该通过当前的递归深度作为参数。您可能会中止更早的时候你的成绩没有改善,如果你能确定毫不费力。
Usually you want to search until a certain recursion depth (e.g. n moves in advance, when playing chess). Therefore, you should pass the current recursion depth as a parameter. You may abort earlier when your results do not improve, if you can determine that with little effort.
这篇关于最小最大算法蟒蛇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!