def test_ray_sensors(ray_sensor, resolution, fov, obs_range):

    agent = HeadAgent(controller=RandomContinuous(), interactive=True)

    agent.add_sensor(ray_sensor(anchor=agent.head,
                                   invisible_elements=agent.parts,
                                   fov=fov,
                                   resolution=resolution,
                                   max_range=obs_range
                                  ))

    agent.add_sensor(ray_sensor(anchor=agent.head,
                                   min_range=agent.base_platform.radius,
                                   fov=fov,
                                   resolution=resolution,
                                   max_range=obs_range
                                   ))

    for pg_class in [Basics, Teleports, Interactives, ]:
        playground = pg_class()
        playground.add_agent(agent)

        engine = Engine(playground, time_limit=100)
        engine.run()

        playground.remove_agent(agent)
        playground.reset()
Пример #2
0
def run_engine(agent, pg_class):
    playground = pg_class()
    playground.add_agent(agent)

    engine = Engine(playground, time_limit=100)
    engine.run()

    assert 0 < agent.position[0] < playground.size[0]
    assert 0 < agent.position[1] < playground.size[1]

    playground.remove_agent(agent)
Пример #3
0
def test_sensor_without_params(single_sensor):

    agent = HeadAgent(controller=RandomContinuous(), interactive=True)

    agent.add_sensor(single_sensor(anchor=agent.head,
                                   invisible_elements=agent.parts,
                                  ))

    for pg_class in [Basics, Teleports, Interactives, ]:
        playground = pg_class()
        playground.add_agent(agent)

        engine = Engine(playground, time_limit=100)
        engine.run()

        playground.remove_agent(agent)
        playground.reset()
Пример #4
0
def test_all_test_playgrounds_interactive(base_forward_agent, pg_rl_cls):

    agent = base_forward_agent

    playground = pg_rl_cls()

    playground.add_agent(agent, allow_overlapping=False)

    print('Starting testing of ', pg_rl_cls.__name__)

    engine = Engine(playground, time_limit=1000)
    engine.run()
    assert 0 < agent.position[0] < playground.size[0]
    assert 0 < agent.position[1] < playground.size[1]

    engine.terminate()
    playground.remove_agent(agent)
def test_all_test_playgrounds(base_forward_agent):

    agent = base_forward_agent

    for _, pg_class in PlaygroundRegister.playgrounds['test'].items():
        playground = pg_class()

        playground.add_agent(agent, allow_overlapping=False)

        print('Starting testing of ', pg_class.__name__)

        engine = Engine(playground, time_limit=10000)
        engine.run()
        assert 0 < agent.position[0] < playground.size[0]
        assert 0 < agent.position[1] < playground.size[1]

        engine.terminate()
        playground.remove_agent(agent)
Пример #6
0
def test_rgb_on_teleports(base_forward_agent):

    agent = base_forward_agent

    agent.add_sensor(RgbCamera(anchor=agent.base_platform,
                               invisible_elements=agent.parts,
                               ))

    playground = Teleports()
    playground.add_agent(agent)

    engine = Engine(playground, time_limit=10000)
    engine.run()

    assert 0 < agent.position[0] < playground.size[0]
    assert 0 < agent.position[1] < playground.size[1]

    playground.remove_agent(agent)
    playground.reset()
def test_multiagents_no_overlapping(base_forward_agent):

    for pg_name, pg_class in PlaygroundRegister.playgrounds['test'].items():

        playground = pg_class()
        print('Starting Multiagent testing of ', pg_class.__name__)
        center, shape = playground.area_rooms[(0, 0)]
        pos_area_sampler = CoordinateSampler(center=center,
                                             area_shape='rectangle',
                                             width_length=shape)

        for _ in range(2):
            agent = BaseAgent(controller=RandomContinuous(), interactive=True)
            playground.add_agent(agent, pos_area_sampler)

        assert len(playground.agents) == 2

        engine = Engine(playground, time_limit=100, screen=False)
        engine.run(update_screen=False)
def test_engine_run(base_forward_agent):
    playground = SingleRoom(size=(200, 200))
    agent = base_forward_agent
    playground.add_agent(agent)
    engine = Engine(playground, time_limit=100)

    pos_start = agent.position
    engine.run()
    assert pos_start != agent.position

    playground.remove_agent(agent)
    playground.add_agent(agent)

    engine = Engine(playground, time_limit=100)
    assert len(engine.agents) == 1
    engine.run()

    playground.remove_agent(agent)
    engine = Engine(playground,  time_limit=100)
    playground.add_agent(agent)
    assert len(engine.agents) == 1

    engine.run()
def test_agent_in_different_environments(base_forward_agent):

    print('Testing of agent moving to different environments')

    agent = base_forward_agent
    pg_1 = SingleRoom((300, 300))
    pg_2 = SingleRoom((100, 100))

    # Play in pg 1
    pg_1.add_agent(agent)
    engine = Engine(pg_1, 100)
    engine.run()
    engine.terminate()
    pg_1.remove_agent(agent)

    # Play in pg 2
    pg_2.add_agent(agent)
    engine = Engine(pg_2, 100)
    engine.run()
    engine.terminate()
    pg_2.remove_agent(agent)

    # Alternate between playgrounds
    pg_1.reset()
    pg_2.reset()

    engine_1 = Engine(pg_1, 100)
    engine_2 = Engine(pg_2, 100)

    print('going to playground 1')
    pg_1.add_agent(agent)
    engine_1.run(10)
    pg_1.remove_agent(agent)

    print('going to playground 2')
    pg_2.add_agent(agent)
    engine_2.run(10)
    pg_2.remove_agent(agent)

    print('running playground 1 without agent')
    engine_1.run(10)
    assert engine_1.elapsed_time == 20

    print('agent returning to playground 1')
    pg_1.add_agent(agent)
    engine_1.run()
    engine_1.terminate()
    pg_1.remove_agent(agent)

    print('agent returning to playground 2')
    pg_2.add_agent(agent)
    engine_2.run()
    engine_2.terminate()
    pg_2.remove_agent(agent)

    print(' Fail when adding agent to 2 playgrounds ')
    pg_1.reset()
    pg_2.reset()
    pg_1.add_agent(agent)