我在下面有以下代码
def runRobot(self):
allActions = ('North','South','East','West','Suck')
bestActionUtility = 0
toDo = 'Suck'
for a in allActions:
actionUtility = self.getActionUtility(a)
if(actionUtility > bestActionUtility):
toDo = a
bestActionUtility = actionUtility
# Do lots of robot stuff here!
self.action = random.choice(['North','South','East','West','Suck'])
def getActionUtility(action):
return 0
当调用runRobot时,我一直收到错误,告诉我我正在为getActionUtility(action)
提供两个参数。我不知道这是怎么可能的。我的for循环我认为剥离allActions
列表的每个元素(数组?或者只是python列表)并为每个动作调用getActionUtility
。我错了吗?
如果需要更多代码,请告诉我,但我认为这应该涵盖整个问题。
答案 0 :(得分:1)
您需要在self
方法中将getActionUtility
作为第一个参数。当您调用这样的方法时:
self.getActionUtility(a)
隐式传递 self
作为方法的第一个参数。因此,只需将方法签名更改为:
def getActionUtility(self, action):
return 0