Exemplo n.º 1
0
def test_rgb_on_teleports(base_forward_agent_random):

    agent = base_forward_agent_random

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

    agent.add_sensor(
        RgbCamera(
            anchor=agent.base_platform,
            min_range=agent.base_platform.radius,
        ))

    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()
Exemplo n.º 2
0
def test_pose_sensors(pg_sensor_class):

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

    agent.add_sensor(Position(anchor=agent.head))
    agent.add_sensor(Velocity(anchor=agent.head))

    playground = pg_sensor_class()
    playground.add_agent(agent)

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

    head = agent.head

    pos_values = agent.sensors[0].sensor_values
    assert head.position[0] == pos_values[0]
    assert head.position[1] == pos_values[1]
    assert head.angle == pos_values[2]

    vel_values = agent.sensors[1].sensor_values
    assert head.velocity[0] == vel_values[0]
    assert head.velocity[1] == vel_values[1]
    assert head.angular_velocity == vel_values[2]

    playground.remove_agent(agent)
    playground.reset()
Exemplo n.º 3
0
def test_ray_sensors(ray_sensor, resolution, fov, obs_range, pg_sensor_class):

    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))

    playground = pg_sensor_class()
    playground.add_agent(agent)

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

    playground.remove_agent(agent)
    playground.reset()
Exemplo n.º 4
0
def run_engine(base_agent, pg_class, **pg_params):
    playground = pg_class(**pg_params)
    playground.add_agent(base_agent, allow_overlapping=False)

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

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

    playground.remove_agent(base_agent)
Exemplo n.º 5
0
def test_multiagents_no_overlapping(pg_test_class):

    playground = pg_test_class()

    print('Starting Multiagent testing of ', pg_test_class.__name__)

    for _ in range(4):
        agent = BaseAgent(controller=RandomContinuous(), interactive=True)
        playground.add_agent(agent, allow_overlapping=False)

    assert len(playground.agents) == 4

    engine = Engine(playground, time_limit=100)
    engine.run()
Exemplo n.º 6
0
def test_wall_params_texture():

    custom_texture = UniqueRandomTilesTexture(color_min=(0, 100, 0),
                                              color_max=(250, 100, 0),
                                              n_colors=10)

    my_playground = GridRooms(size=(600, 600),
                              room_layout=(3, 3),
                              random_doorstep_position=False,
                              doorstep_size=80,
                              wall_texture=custom_texture)

    engine = Engine(time_limit=10000, playground=my_playground)
    engine.run()
    engine.terminate()
Exemplo n.º 7
0
def test_all_rl_playgrounds(base_forward_agent_random, pg_rl_class):

    agent = base_forward_agent_random

    playground = pg_rl_class()

    playground.add_agent(agent, allow_overlapping=False)

    print('Starting testing of ', pg_rl_class.__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)
Exemplo n.º 8
0
def test_multiagents(pg_test_class):

    playground = pg_test_class()

    print('Starting Multiagent testing of ', pg_test_class.__name__)

    pos_area_sampler = playground.initial_agent_coordinates

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

    assert len(playground.agents) == 100

    engine = Engine(playground, time_limit=100)
    engine.run()
    engine.terminate()
Exemplo n.º 9
0
def test_time_sensor(pg_sensor_class):

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

    agent.add_sensor(Time(anchor=agent.head))

    playground = pg_sensor_class()
    playground.add_agent(agent)

    engine = Engine(playground, time_limit=100)

    for _ in range(100):
        engine.run(1)
        time_value = agent.sensors[0].sensor_values
        assert engine.elapsed_time == time_value

    engine.reset()
    engine.run(1)
    time_value = agent.sensors[0].sensor_values
    assert 1 == time_value

    playground.remove_agent(agent)
    playground.reset()
Exemplo n.º 10
0
def test_sensor_without_params(any_sensor, pg_sensor_class):

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

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

    agent.add_sensor(
        RgbCamera(
            anchor=agent.base_platform,
            min_range=agent.base_platform.radius,
        ))

    playground = pg_sensor_class()
    playground.add_agent(agent)

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

    playground.remove_agent(agent)
    playground.reset()
Exemplo n.º 11
0
def test_engine_run(base_forward_agent_random):
    playground = SingleRoom(size=(200, 200))
    agent = base_forward_agent_random
    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()
Exemplo n.º 12
0
def test_agent_in_different_environments(base_forward_agent_random):

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

    agent = base_forward_agent_random
    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)