def testVacuum(label, w=4, h=3, dloc=[(1, 1), (2, 1)], vloc=(1, 1), limit=6): print(label) v = VacuumEnvironment(w, h) for loc in dloc: v.add_thing(Dirt(), loc) a = v2.HW2Agent() a = ag.TraceAgent(a) v.add_thing(a, vloc) t = gui.EnvTUI(v) t.mapImageNames({ ag.Wall: '#', Dirt: '@', ag.Agent: 'V', }) t.step(0) t.list_things(Dirt) t.step(limit) if len(t.env.get_things(Dirt)) > 0: t.list_things(Dirt) else: print('All clean!') # Check to continue if input('Do you want to continue [Y/n]? ') == 'n': exit(0) else: print('----------------------------------------')
def testVacuum(student, label, w=4, h=3, dloc=[(1, 1), (2, 1)], vloc=(1, 1), limit=6, points=5.0): print(student + ', ' + label) v = VacuumEnvironment(w, h) dStart = len(dloc) for loc in dloc: v.add_thing(Dirt(), loc) try: a = submissions[student]() a = ag.TraceAgent(a) v.add_thing(a, vloc) t = gui.EnvTUI(v) t.mapImageNames({ ag.Wall: '#', Dirt: '@', ag.Agent: 'V', }) t.step(0) t.list_things(Dirt) t.step(limit) except: traceback.print_exc() dFinish = len(t.env.get_things(Dirt)) if dFinish > 0: t.list_things(Dirt) else: print('All clean!') newPoints = points * (dStart - dFinish) / dStart scores[student].append(newPoints) print(student + ' scores ' + str(newPoints)) # Check to continue if interactive == False: print('----------------------------------------') return True elif input('Continue testing ' + student + ' [Y/n]? ') == 'n': print('----------------------------------------') raise MyException return False else: print('----------------------------------------') return True
else: super(VacuumEnvironment, self).execute_action(agent, action) if action != 'NoOp': agent.performance -= 1 # Launch a Text-Based Environment print('Two Cells, Agent on Left:') v = VacuumEnvironment(4, 3) v.add_thing(Dirt(), (1, 1)) v.add_thing(Dirt(), (2, 1)) a = v2.HW2Agent() a = ag.TraceAgent(a) v.add_thing(a, (1, 1)) t = gui.EnvTUI(v) t.mapImageNames({ ag.Wall: '#', Dirt: '@', ag.Agent: 'V', }) t.step(0) t.list_things(Dirt) t.step(4) if len(t.env.get_things(Dirt)) > 0: t.list_things(Dirt) else: print('All clean!') # Check to continue if input('Do you want to continue [y/N]? ') != 'y':