Reputation: 131
The following is the code snippet of minimax algorithm for multi-agent pacman where there are multiple ghosts(min players).
def min_max(self, gamestate, current_depth, min_count):
if current_depth == 1:
return (self.evaluationFunction(gamestate),None)
# if max node
if min_count == 0:
min_count = gamestate.getNumAgents() - 1
legal_actions = gamestate.getLegalActions(0)
max_list = []
for action in legal_actions:
max_list.append((self.min_max(gamestate.generateSuccessor(0, action), current_depth - 1, min_count), action))
return max(max_list, key = itemgetter(0))
# if min nodes...
else:
legal_actions = gamestate.getLegalActions(min_count)
min_list = []
for action in legal_actions:
min_list.append((self.min_max(gamestate.generateSuccessor(min_count, action),current_depth - 1, min_count - 1), action))
print(current_depth,min_count)
return min(min_list, key = itemgetter(0))
pacman_move = self.min_max(gameState, self.depth * (no_of_ghosts + 1) + 1, 0)[1]
But I'm getting the following error: ValueError: min() arg is an empty sequence.
Any help is appreciated
Upvotes: 0
Views: 3090
Reputation: 133909
You do not have any legal moves at min-step - and that's why min_list
is empty.
>>> min([])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: min() arg is an empty sequence
Thus handle the case of:
if not legal_actions:
# pass? win? lose?
before doing min()
Upvotes: 1