Exemple #1
0
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
Exemple #3
0
 def startSim(self):
     self.vacuumEnvironment.add_thing(agents.TraceAgent(agents.ReflexVacuumAgent()))
     #self.vacuumEnvironment.add_thing(agents.TraceAgent(agents.TableDrivenVacuumAgent()))
     self.vacuumEnvironment.run(10)
Exemple #4
0
# a = ag.TraceAgent(a)
# v.add_agent(a)
# g = gui.EnvGUI(v, 'Vaccuum')
# c = g.getCanvas()
# c.mapImageNames({
#     Dirt: 'images/dirt.png',
#     ag.Wall: 'images/wall.jpg',
#     # Floor: 'images/floor.png',
#     ag.Agent: 'images/vacuum.png',
# })
# c.update()
# g.mainloop()

# Launch GUI of more complex environment
v = VacuumEnvironment(5, 4)
#a = ModelBasedVacuumAgent()
a = RandomVacuumAgent()
a = ag.TraceAgent(a)
loc = v.random_location_inbounds()
v.add_thing(a, location=loc)
v.scatter_things(Dirt)
g = gui.EnvGUI(v, 'Vaccuum')
c = g.getCanvas()
c.mapImageNames({
    ag.Wall: 'submissions/Becker/wall.jpg',
    # Floor: 'images/floor.png',
    Dirt: 'images/dirt.png',
    ag.Agent: 'images/vacuum.png',
})
c.update()
g.mainloop()