def create_arena_with_red_wall(t=DEFAULT_TIME_LIMIT): arena = Arena(t=t, items=[]) orientation = np.random.choice(['horizontal', 'vertical']) goal_size = float(np.random.choice([1, 2, 3])) _add_wall_to_arena(arena, orientation='horizontal', position=np.random.randint(10, 30), goal_size=goal_size) if orientation == 'horizontal': arena.items.append( Item(name='GoodGoalMulti', sizes=[Vector3(1, 1, 1)] * 2, positions=[ Vector3(-1, 0, float(np.random.randint(1, 7))), Vector3(-1, 0, 40 - float(np.random.randint(1, 7))) ])) else: arena.items.append( Item(name='GoodGoalMulti', sizes=[Vector3(1, 1, 1)] * 2, positions=[ Vector3(float(np.random.randint(1, 7)), 0, -1), Vector3(40 - float(np.random.randint(1, 7)), 0, -1) ])) return arena
def create_arena_with_different_sizes_green_goal_in_front_of_agent( t=DEFAULT_TIME_LIMIT): arena = Arena(t=t, items=[]) agent, x, z, angle = _create_agent_looking_center_at_random_position() arena.items.append(agent) size_small = DEFAULT_REWARD size_big = DEFAULT_REWARD * 2 angle_big = angle + np.random.randint(-20, 21) angle_small = angle + np.random.randint(-20, 21) while abs(angle_big - angle_small) < 15: angle_small = angle + np.random.randint(-20, 21) arena.items.append( _create_goal_in_front_of_agent(x, z, angle_big, goal_type='GoodGoal', min_distance=5, max_distance=20, size=size_big)) arena.items.append( _create_goal_in_front_of_agent(x, z, angle_small, goal_type='GoodGoal', min_distance=5, max_distance=20, size=size_small)) return arena
def create_arena_with_red_houses(t=DEFAULT_TIME_LIMIT): arena = Arena(t=t, items=[]) centers, radiuses = [], [] for idx in range(4): not_good_center = True while not_good_center: not_good_center = False radius = np.random.uniform(2, 4) center = np.random.randint(5, 35, 2) for _center, _radius in zip(centers, radiuses): distance = np.sqrt(np.sum((center - _center)**2)) if distance < radius + _radius + 4: not_good_center = True centers.append(center) radiuses.append(radius) goal_size = float(np.random.uniform(1, 2)) _add_red_circle_to_arena(arena, center=center, radius=radius, goal_size=goal_size) if idx < 2: arena.items.append( Item(name='GoodGoalMulti', sizes=[Vector3(1, 1, 1)], positions=[Vector3(center[0], 0, center[1])])) return arena
def create_arena_with_same_size_one_close_and_one_farther_goal_in_front_of_agent( t=DEFAULT_TIME_LIMIT): arena = Arena(t=t, items=[]) agent, x, z, angle = _create_agent_looking_center_at_random_position() arena.items.append(agent) size = DEFAULT_REWARD angle_close = angle + np.random.randint(-20, 21) angle_far = angle + np.random.randint(-20, 21) while abs(angle_close - angle_far) < 15: angle_far = angle + np.random.randint(-20, 21) arena.items.append( _create_goal_in_front_of_agent(x, z, angle_close, goal_type='GoodGoal', min_distance=5, max_distance=10, size=size)) arena.items.append( _create_goal_in_front_of_agent(x, z, angle_far, goal_type='GoodGoal', min_distance=19, max_distance=40, size=size)) return arena
def create_arena_with_green_and_yellow_goal_in_front_of_agent( t=DEFAULT_TIME_LIMIT): arena = Arena(t=t, items=[]) agent, x, z, angle = _create_agent_looking_center_at_random_position() arena.items.append(agent) size = np.random.uniform(0.5, DEFAULT_REWARD - 0.5) angle_yellow = angle + np.random.randint(-20, 21) arena.items.append( _create_goal_in_front_of_agent(x, z, angle_yellow, goal_type='GoodGoalMulti', min_distance=5, max_distance=20, size=size)) size = DEFAULT_REWARD - size angle_green = angle + np.random.randint(-20, 21) while abs(angle_yellow - angle_green) < 5: angle_green = angle + np.random.randint(-20, 21) arena.items.append( _create_goal_in_front_of_agent(x, z, angle_green, goal_type='GoodGoal', min_distance=5, max_distance=20, size=size)) return arena
def create_arena_with_obstacles_and_deathzones(t=DEFAULT_TIME_LIMIT): arena = Arena(t=t, items=[]) _add_rewards_to_arena(arena) _add_zones_to_arena(arena, np.random.randint(2, 5)) _add_agent_to_arena(arena) _add_obstacles_to_arena(arena, np.random.randint(5, 10)) _add_badgoals_to_arena(arena, np.random.randint(2, 7)) return arena
def create_arena_with_small_goal(t): arena = Arena(t=t, items=[]) if np.random.randint(0, 2): arena.items.append( Item(name='GoodGoalMulti', sizes=[Vector3(0.5, 0.5, 0.5)])) else: arena.items.append( Item(name='GoodGoal', sizes=[Vector3(0.5, 0.5, 0.5)])) return arena
def create_arena_with_bouncing_goal(t): arena = Arena(t=t, items=[]) size = float(np.random.choice([0.5, 1])) if np.random.randint(0, 2): arena.items.append( Item(name='GoodGoalMultiBounce', sizes=[Vector3(size, size, size)])) else: arena.items.append( Item(name='GoodGoalBounce', sizes=[Vector3(size, size, size)])) return arena
def create_arena_splitted_in_two_with_path_blocked(t): arena = Arena(t=t, items=[]) _split_arena_in_two(arena, block_path=True) for _ in range(DEFAULT_REWARD): _add_simple_goal(arena) _add_badgoals_to_arena(arena, np.random.randint(2, 7)) for _ in range(np.random.randint(2, 4)): _add_random_box(arena) for _ in range(np.random.randint(1, 3)): _add_random_wooden_object(arena) return arena
def create_center_blocked_arena(t): arena = Arena(t=t, items=[]) _add_center_blocking_wall(arena) for _ in range(DEFAULT_REWARD): _add_simple_goal(arena) _add_badgoals_to_arena(arena, np.random.randint(2, 7)) for _ in range(np.random.randint(2, 6)): _add_random_box(arena) if np.random.randint(0, 2): _add_random_wooden_object(arena) return arena
def create_arena_with_red_goal_coming(t=DEFAULT_TIME_LIMIT): arena = Arena(t=t, items=[]) agent, x, z, angle = _create_agent_looking_center_closer_to_center() arena.items.append(agent) arena.items.append( _create_goal_in_front_of_agent(x, z, angle, goal_type='BadGoalBounce', min_distance=15, max_distance=20)) arena = _add_reward_to_arena(arena) return arena
def create_arena_splitted_in_four_deathzone(t): arena = Arena(t=t, items=[]) _split_arena_in_four(arena) for item in arena.items: item.name = 'DeathZone' _add_agent_to_arena(arena) for _ in range(DEFAULT_REWARD): _add_simple_goal(arena) _add_badgoals_to_arena(arena, np.random.randint(2, 7)) for _ in range(np.random.randint(2, 4)): _add_random_box(arena) for _ in range(np.random.randint(1, 3)): _add_random_wooden_object(arena) return arena
def create_arena_with_walls_maze(t, difficulty=None): arena = Arena(t=t, items=[]) if difficulty is None: difficulty = np.random.choice(DIFFICULTY_LEVELS) else: assert difficulty in DIFFICULTY_LEVELS if difficulty == 'easy': n_cells = 3 elif difficulty == 'medium': n_cells = 4 elif difficulty == 'hard': n_cells = 5 else: raise Exception('Unknown difficulty: %s' % difficulty) _add_walls_maze(arena, n_cells=n_cells, wall_thickness=1) _apply_color_to_wall_maze(arena) for _ in range(DEFAULT_REWARD): _add_simple_goal(arena) return arena
def create_death_zone_arena(size, t): arena_config = ArenaConfig() # Put green reward item_goal = Item(name="GoodGoal", positions=None, rotations=None, sizes=[Vector3(x=1, y=1, z=1)], colors=None) # Put Death Zone item_death_zone = Item(name="DeathZone", positions=None, rotations=None, sizes=[size], colors=None) items = [] items.append(item_goal) items.append(item_death_zone) arena = Arena(t=t, items=items, blackouts=None) return arena
def create_arena_with_death_maze(t, difficulty=None): arena = Arena(t=t, items=[]) if difficulty is None: difficulty = np.random.choice(DIFFICULTY_LEVELS) else: assert difficulty in DIFFICULTY_LEVELS if difficulty == 'easy': n_cells = 3 elif difficulty == 'medium': n_cells = np.random.randint(3, 5) elif difficulty == 'hard': n_cells = 4 # 5 seems to be very difficult else: raise Exception('Unknown difficulty: %s' % difficulty) wall_thickness = 4 _add_walls_maze(arena, n_cells=n_cells, wall_thickness=wall_thickness) _replace_walls_by_death_zones(arena) for _ in range(DEFAULT_REWARD): _add_goal_on_fixed_position(arena) _add_agent_to_arena(arena) return arena
def create_arena_with_yellow_goal_separated_by_wall(t=DEFAULT_TIME_LIMIT): arena = Arena(t=t, items=[]) agent, x, z, angle = _create_agent_looking_center_at_random_position() arena.items.append(agent) size_small = DEFAULT_REWARD size_big = DEFAULT_REWARD angle_big = angle + np.random.randint(-20, 21) angle_small = angle + np.random.randint(-20, 21) while abs(angle_big - angle_small) < 15: angle_small = angle + np.random.randint(-20, 21) arena.items.append( _create_goal_in_front_of_agent(x, z, angle_big, goal_type='GoodGoalMulti', min_distance=15, max_distance=20, size=size_big)) arena.items.append( _create_wall_in_front_of_agent(x, z, angle, wall_type='WallTransparent', min_distance=11, max_distance=14)) arena.items.append( _create_goal_in_front_of_agent(x, z, angle_small, goal_type='GoodGoal', min_distance=5, max_distance=10, size=size_small)) return arena
def create_arena_with_platform_maze(t, difficulty=None): arena = Arena(t=t, items=[]) if difficulty is None: difficulty = np.random.choice(DIFFICULTY_LEVELS) else: assert difficulty in DIFFICULTY_LEVELS if difficulty == 'easy': n_cells = 3 elif difficulty == 'medium': n_cells = np.random.randint(3, 5) elif difficulty == 'hard': n_cells = 4 else: raise Exception('Unknown difficulty: %s' % difficulty) wall_thickness = 6 _add_platform_maze(arena, n_cells=n_cells, wall_thickness=wall_thickness) _apply_color_to_platform_maze(arena) _add_goals_and_agent_to_platform_maze(arena, n_cells, wall_thickness) item = Item(name='DeathZone', sizes=[Vector3(40, 0, 40)], positions=[Vector3(20, 0, 20)], rotations=[0]) arena.items.append(item) return arena
def create_arena_with_goal_on_top_of_box(t): arena = Arena(t=t, items=[]) _add_goal_on_top_of_box(arena) if np.random.randint(0, 2): arena.items[-1].name = 'GoodGoal' return arena
def create_arena_with_goal_inside_cillinder(t): arena = Arena(t=t, items=[]) _add_goal_inside_cillinder(arena) if np.random.randint(0, 2): arena.items[-1].name = 'GoodGoal' return arena
def save_arena(items, filename): arenas = {0: Arena(t=250, items=items)} with open('{}.yml'.format(filename), 'w') as outfile: yaml.dump(ArenaConfig(arenas), outfile, default_flow_style=False)