def test_TableDrivenAgent(): random.seed(10) loc_A, loc_B = (0, 0), (1, 0) # table defining all the possible states of the agent table = { ((loc_A, 'Clean'), ): 'Right', ((loc_A, 'Dirty'), ): 'Suck', ((loc_B, 'Clean'), ): 'Left', ((loc_B, 'Dirty'), ): 'Suck', ((loc_A, 'Dirty'), (loc_A, 'Clean')): 'Right', ((loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck', ((loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck', ((loc_B, 'Dirty'), (loc_B, 'Clean')): 'Left', ((loc_A, 'Dirty'), (loc_A, 'Clean'), (loc_B, 'Dirty')): 'Suck', ((loc_B, 'Dirty'), (loc_B, 'Clean'), (loc_A, 'Dirty')): 'Suck' } # create an program and then an object of the TableDrivenAgent program = TableDrivenAgentProgram(table) agent = Agent(program) # create an object of TrivialVacuumEnvironment environment = TrivialVacuumEnvironment() # initializing some environment status environment.status = {loc_A: 'Dirty', loc_B: 'Dirty'} # add agent to the environment environment.add_thing(agent, location=(1, 0)) # run the environment by single step everytime to check how environment evolves using TableDrivenAgentProgram environment.run(steps=1) assert environment.status == {(1, 0): 'Clean', (0, 0): 'Dirty'} environment.run(steps=1) assert environment.status == {(1, 0): 'Clean', (0, 0): 'Dirty'} environment.run(steps=1) assert environment.status == {(1, 0): 'Clean', (0, 0): 'Clean'}
def test_TableDrivenAgentProgram(): table = { (('foo', 1), ): 'action1', (('foo', 2), ): 'action2', (('bar', 1), ): 'action3', (('bar', 2), ): 'action1', ( ('foo', 1), ('foo', 1), ): 'action2', ( ('foo', 1), ('foo', 2), ): 'action3' } agent_program = TableDrivenAgentProgram(table) assert agent_program(('foo', 1)) == 'action1' assert agent_program(('foo', 2)) == 'action3' assert agent_program(('invalid percept', )) is None