Minimal algorithm in python

In the minmax algorithm, how to determine when your function reaches the end of the tree and interrupts recursive calls.

I made a max function in which I call the min function. In the min function, what shud am I doing ?? For maximum function, I just return 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 act now? I am not allowed to set a tree depth limit. it must be arbitrary.

+3
source share
4 answers

(, n , ). . , , .

+3

minmax, , .

, , node.

node , node (.. , ).

+1

. :

, , , , . . , . , , .

Amber, , , . , , /can _do, - , , , , , ,

+1

, IronPython: http://blogs.microsoft.co.il/blogs/dhelper/archive/2009/07/13/getting-started-with-ironpython-part-4-minimax-algorithm.aspx

:

The Minimax algorithm is recursive in nature, and as such it requires a stopping condition, in our case either the game ended (there were no more moves) or the desired depth was reached (lines 3-8).

You can avoid using two different functions using Negamax http://en.wikipedia.org/wiki/Negamax

0
source

Source: https://habr.com/ru/post/1757490/


All Articles