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)
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()
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)
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()
def test_beam_orientation(base_forward_interactive_agent_external): playground = SingleRoom(size=(200, 200)) agent = base_forward_interactive_agent_external beam = InvisibleBeam(destination=((50, 50), math.pi/2)) playground.add_agent(agent, ((100, 100), 0)) playground.add_element(beam, ((140, 100), 0)) engine = Engine(playground, time_limit=100) actions = {agent: {agent.longitudinal_force: 1}} while engine.game_on: engine.step(actions) assert agent.position[0] == 50 engine.terminate()
def test_multisteps(base_forward_agent_random, pg_test_class): agent = base_forward_agent_random sensor = Touch(name='touch_1', anchor=agent.base_platform) agent.add_sensor(sensor) playground = pg_test_class() print('Starting Multistep testing of ', pg_test_class.__name__) playground.add_agent(agent) engine = Engine(playground, time_limit=10000) while engine.game_on: actions = {} for agent in engine.agents: actions[agent] = agent.controller.generate_actions() engine.multiple_steps(actions=actions, n_steps=3) engine.update_observations() engine.terminate() playground.remove_agent(agent)