Dec-10-2021, 05:51 PM
(This post was last modified: Dec-10-2021, 05:51 PM by deanhystad.)
This
An easy way to figure out these kinds of problems is adding a print.
There are three ways to solve this problem. Correct agentprogram() to have "self" as the first argument, correct agentprogram() to have cls as the first argument, get rid of the Agent class.
This works and it is easy
result = agent.agentprogram(agent_percept)calls
Agent.agentprogram(agent, agent_percept)2 arguments.
An easy way to figure out these kinds of problems is adding a print.
def agentprogram(percept:tuple, *args, **kvargs): print('agentprogram arguments', percept, args, kvargs)When I run this it prints
Output:agentprogram arguments <__main__.Agent object at 0x000002C18ADB8400> (((('A', 'Clean'), ('B', 'Dirty')),
'B'),) {}
2 arguments.There are three ways to solve this problem. Correct agentprogram() to have "self" as the first argument, correct agentprogram() to have cls as the first argument, get rid of the Agent class.
This works and it is easy
def agentprogram(self, percept:tuple):But I don't think it is a good solution. Agent is not a class. Maybe the problem is that you snipped away all the important parts of Agent to make a short example for your post. If so, then use the suggested solution above. If not, look at the Agent class and tell me what it is. The __init__() creates two instance variables, but neither of these are used. The agentprogram() method doesn't use any instance variables. This could be turned into a class method (use @classmethod decorator), but it doesn't use any class variables either. Agent is a useless class wrapper around the agentprogram() function.
def agentprogram(percept:tuple): table = {((('A','Clean'),('B','Clean')),'A'):'NoOp', ((('A','Clean'),('B','Clean')),'B'):'NoOp', ((('A','Clean'),('B','Dirty')),'A'):'Right', ((('A','Clean'),('B','Dirty')),'B'):'Suck', ((('A','Dirty'),('B','Clean')),'A'):'Suck', ((('A','Dirty'),('B','Clean')),'B'):'Left', ((('A','Dirty'),('B','Dirty')),'A'):'Suck', ((('A','Dirty'),('B','Dirty')),'B'):'Suck', } action = table[percept] return action #creating the tuple I will pass agent_percept = ((('A','Clean'),('B','Dirty')),'B') result = agentprogram(agent_percept) print(result)