名称未定义定义函数的错误?

时间:2017-06-04 13:49:17

标签: python python-3.x compiler-errors

我有一个python脚本,我收到以下错误:

File "C:\AIND\AIND-isolation\AIND-Isolation\game_agent.py", line 229, in minimax
  my_minimax(current_location, current_depth, max_depth)
  NameError: name 'my_minimax' is not defined

以下是导致问题的代码:

class MinimaxPlayer(IsolationPlayer):

    def my_minimax(self, current_location, current_depth, max_depth):
        print("my_minimax")

    def minimax(self, game, depth):

        if self.time_left() < self.TIMER_THRESHOLD:
            raise SearchTimeout()

        # TODO: finish this function!
        legal_moves = game.get_legal_moves()

        if not legal_moves:
            return (-1, -1)

        _, move = max([(self.score(game.forecast_move(node), self), node)
                        for node in legal_moves])

        current_depth = 0
        max_depth = depth
        current_location = game.get_player_location(self)

        my_minimax(current_location, current_depth, max_depth)

        return move

我在使用之前定义了该功能。为什么找不到这个功能?

1 个答案:

答案 0 :(得分:2)

my_minimaxMinimaxPlayer的方法。

致电self.my_minimax(...)