def swarm_sim(argv): """In the main function first the config is getting parsed and than the swarm_sim_world and the swarm_sim_world item is created. Afterwards the run method of the swarm_sim_world is called in which the simlator is going to start to run""" config_data = config.ConfigData() unique_descriptor = "%s_%s_%s" % (config_data.local_time, config_data.scenario.rsplit('.', 1)[0], config_data.solution.rsplit('.', 1)[0]) logging.basicConfig(filename="outputs/logs/system_%s.log" % unique_descriptor, filemode='w', level=logging.INFO, format='%(message)s') logging.info('Started') read_cmd_args(argv, config_data) create_directory_for_data(config_data, unique_descriptor) random.seed(config_data.seed_value) swarm_sim_world = world.World(config_data) swarm_sim_world.init_scenario(get_scenario(swarm_sim_world.config_data)) reset = True while reset: reset = main_loop(config_data, swarm_sim_world) logging.info('Finished') generate_data(config_data, swarm_sim_world)
def __init__(self, scr_width, scr_height): self.width = scr_width self.height = scr_height self.map_width = scr_width // TILE_SIZE self.map_height = scr_height // TILE_SIZE self.screen = graphics.start(self.width, self.height) self.world = world.World(self.map_width, self.map_height) self.clock = pygame.time.Clock()
def __init__(self, size: Tuple, max_frame_rate: int): self.max_frame_rate: int = max_frame_rate pygame.init() pygame.display.set_caption("pyWorld", "pyWorld") self.surface: pygame.Surface = pygame.display.set_mode(size) self.clock: pygame.time.Clock = pygame.time.Clock() self.world = world.World(self.surface) # self.event_manager = events.EventManager() self.system_manager = system_manager.SystemManager(self.world) self.is_running = True
def __init__(self, net_config, num_agents=1, timestep=0.010, seed=None, update_period=None): if update_period is None: update_period = len(goons) #get config data self.config_data = config.ConfigData() #set up logging unique_descriptor = "%s_%s_%s" % ( self.config_data.local_time, self.config_data.scenario.rsplit( '.', 1)[0], self.config_data.solution.rsplit('.', 1)[0]) logging.basicConfig(filename="outputs/logs/system_%s.log" % unique_descriptor, filemode='w', level=logging.INFO, format='%(message)s') logging.info('Started') read_cmd_args(self.config_data) create_directory_for_data(self.config_data, unique_descriptor) if seed is not None: self.config_data.seed_value = seed # random.seed(seed) # TODO : Move this to be different lol self.config_data.follow_the_leader = net_config.follow self.config_data.flock_rad = net_config.flock_rad self.config_data.flock_vel = net_config.flock_vel self.config_data.conn_class = net_config.conn_class self.config_data.num_agents = num_agents #set up world self.swarm_sim_world = world.World(self.config_data) self.swarm_sim_world.timestep = timestep self.swarm_sim_world.init_scenario(get_scenario( self.swarm_sim_world.config_data), num_agents=num_agents) self.swarm_sim_world.network_formed = False self._init_log(id="custom", scenario=self.config_data.scenario, num_agents=num_agents, seed=self.config_data.seed_value, comms=net_config.conn_class, flock_rad=net_config.flock_rad, flock_vel=net_config.flock_vel, update_period=update_period)
def __init__(self): super(SingleExplorer, self).__init__() # Define action and observation space # They must be gym.spaces objects # Example when using discrete actions: ##may need to alter configdata to be closer to fit our needs. config_data = config.ConfigData() unique_descriptor = "%s_%s_%s" % ( config_data.local_time, config_data.scenario.rsplit( '.', 1)[0], config_data.solution.rsplit('.', 1)[0]) logging.basicConfig(filename="outputs/logs/system_%s.log" % unique_descriptor, filemode='w', level=logging.INFO, format='%(message)s') logging.info('Started') swarmsim.read_cmd_args(config_data) swarmsim.create_directory_for_data(config_data, unique_descriptor) swarmsim.random.seed(config_data.seed_value) self.swarm_sim_world = world.World(config_data) self.ts = 0 self.discovered_items = set() self.explored_points = set() self.swarm_sim_world.init_scenario(swarmsim.get_scenario(config_data)) #self.NUM_AGENTS = self.swarm_sim_world.get_amount_of_agents() #each agent can move one of 9 ways, with #self.action_space = spaces.MultiDiscrete(np.full_like(self.NUM_AGENTS, 9)) # xyz motion self.action_space = spaces.Discrete( len(self.swarm_sim_world.grid.get_directions_list())) #observation of the coordinates of each agent and the 6 neighboring locations #space should be the current position, plus the hops self.observation_space = spaces.Box( np.array([-9999, -9999, -9999] + [0] * len(self.swarm_sim_world.grid.get_directions_list())), np.array([9999, 9999, 9999] + [1] * len(self.swarm_sim_world.grid.get_directions_list())))
def __init__(self): self.world = world.World()
def __init__(self, sdl): self.world = world.World() self.sdl = sdl
def run(self): while not self.done: if self.world_done: if self.world_number < MAX_WORLD: self.world_beat() # Resetting player lives so that it isn't in their best # interest to play easier worlds just to have extra lives. self.player.lives = 3 self.player.life_board.set_text('x' + str(self.player.lives)) self.player.score = 0 self.player.next_bonus = 50000 # Loading the new world self.world_number += 1 if self.world_number == 0: self.new_scene = scene.TutorialScene() elif self.world_number == 1: self.new_scene = scene.ForestScene() elif self.world_number == 2: self.new_scene = scene.RockyScene() elif self.world_number == 3: self.new_scene = scene.PinkScene() if self.world_number > settings_list[WORLD_UNLOCKED]: settings_list[WORLD_UNLOCKED] = self.world_number utility.play_music(self.music_list[self.world_number], True) self.current_world = world.World( self.world_list[self.world_number], self.music_list[self.world_number]) self.current_world.load() self.world_done = False else: self.game_beat() self.check_collision() self.update() self.draw() self.handle_events() pygame.mouse.set_pos(MOUSE_DEFAULT_POSITION) pygame.mouse.get_rel() self.mouse_last_move = pygame.mouse.get_pos() self.timer.tick(FRAMES_PER_SECOND) if self.player.dead: high_score = read_high_scores() if self.player.score < high_score[self.world_number]: end_game_dictionary = { HIGH_SCORE: [ 'High Score For This World: ' + str(high_score[self.world_number]), 'You would need to score ' + str(high_score[self.world_number] - self.player.score) + ' more to beat it!' ], NEXT_WORLD: ['Exit', 'Return To The Menu'] } elif self.player.score == high_score[self.world_number]: end_game_dictionary = { HIGH_SCORE: [ 'High Score For This World: ' + str(high_score[self.world_number]), 'You Tied the High Score!' ], NEXT_WORLD: ['Exit', 'Return To The Menu'] } else: end_game_dictionary = { HIGH_SCORE: [ 'High Score For This World: ' + str(high_score[self.world_number]), 'You Beat the High Score!' ], NEXT_WORLD: ['Exit', 'Return To The Menu'] } high_score[self.world_number] = self.player.score write_high_scores(high_score) utility.dim(128, FILL_COLOR) end_game_menu = menu.Menu( self.screen, self.music_list[self.world_number], self.screen.convert(), [0, SCREEN_HEIGHT / 3, SCREEN_WIDTH, SCREEN_HEIGHT], ['Game Over', 128, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 4], end_game_dictionary) end_game_menu.show() self.done = True utility.fade_music() utility.play_music(self.music_list[MENU_MUSIC], True)
def __init__(self, screen, world_to_start, music_list): self.screen = screen pygame.mouse.set_visible(False) self.done = False self.world_done = False self.high_score = 0 self.bullet_group = pygame.sprite.Group() self.player_group = pygame.sprite.Group() self.powerup_group = pygame.sprite.Group() self.boss_group = pygame.sprite.Group() self.enemy_group = pygame.sprite.Group() self.text_group = pygame.sprite.Group() self.effects_group = pygame.sprite.Group() self.mouse_last_move = MOUSE_DEFAULT_POSITION self.group_list = [ self.powerup_group, self.enemy_group, self.boss_group, self.text_group, self.effects_group ] self.score_board = text.Text(FONT_PATH, 36, FONT_COLOR) self.temp_life_board = text.Text(FONT_PATH, 36, FONT_COLOR) self.temp_life_board.position = vector.Vector2d(48, 40) self.life_board = self.temp_life_board self.life_icon = icon.Icon('life') self.player = player.Player(self.bullet_group, self.effects_group, self.life_board, self.score_board) self.player_group.add(self.player) self.text_group.add(self.score_board) self.text_group.add(self.temp_life_board) self.text_group.add(self.life_icon) self.music_list = music_list self.timer = pygame.time.Clock() # Get rid of the first mouse delta pygame.mouse.get_rel() world1_level0 = [[0, ACTOR_MOONO, 45, 0], [1, ACTOR_MOONO, 120, 0], [2, ACTOR_MOONO, 240, 0], [3, ACTOR_BAAKE, -1, 1], [4, ACTOR_BOSS_TUT, -1, 1], [4, ACTOR_MOONO, 35, 0]] world1_level1 = [[0, ACTOR_MOONO, 40, 0], [1, ACTOR_MOONO, 85, 0], [2, ACTOR_MOONO, 110, 0], [3, ACTOR_BAAKE, -1, 2], [4, ACTOR_BOSS_TUT, -1, 1], [4, ACTOR_MOONO, 30, 0]] world1_level2 = [[0, ACTOR_MOONO, 30, 0], [1, ACTOR_BAAKE, -1, 1], [0, ACTOR_MOONO, 70, 0], [2, ACTOR_BAAKE, -1, 1], [0, ACTOR_MOONO, 130, 0], [3, ACTOR_BAAKE, -1, 1], [0, ACTOR_MOONO, 300, 0], [4, ACTOR_BOSS_TUT, -1, 1], [4, ACTOR_MOONO, 25, 0]] world1_level3 = [[0, ACTOR_MOONO, 25, 0], [1, ACTOR_BAAKE, -1, 1], [1, ACTOR_MOONO, 50, 0], [2, ACTOR_BAAKE, -1, 2], [2, ACTOR_MOONO, 110, 0], [3, ACTOR_BAAKE, -1, 2], [3, ACTOR_MOONO, 210, 0], [4, ACTOR_BOSS_TUT, -1, 1], [4, ACTOR_MOONO, 20, 0]] world2_level0 = [[0, ACTOR_MOONO, 45, 0], [0, ACTOR_HAOYA, 65, 0], [1, ACTOR_BAAKE, -1, 1], [1, ACTOR_MOONO, 70, 0], [2, ACTOR_HAOYA, 75, 0], [3, ACTOR_MOONO, 85, 0], [4, ACTOR_BAAKE_BOSS, -1, 1], [4, ACTOR_HAOYA, 30, 0]] world2_level1 = [[0, ACTOR_BAAKE, -1, 2], [0, ACTOR_BATTO, 150, 0], [0, ACTOR_MOONO, 55, 0], [1, ACTOR_HAOYA, 60, 0], [2, ACTOR_MOONO, 100, 0], [3, ACTOR_BAAKE, -1, 1], [3, ACTOR_BATTO, 280, 0], [4, ACTOR_BAAKE_BOSS, -1, 1], [4, ACTOR_BATTO, 70, 0]] world2_level2 = [[0, ACTOR_ROKUBI, 60, 0], [0, ACTOR_MOONO, 50, 0], [0, ACTOR_BAAKE, -1, 2], [1, ACTOR_BAAKE, -1, 1], [1, ACTOR_BATTO, 160, 0], [2, ACTOR_HAOYA, 60, 0], [3, ACTOR_MOONO, 80, 0], [4, ACTOR_BAAKE_BOSS, -1, 1], [4, ACTOR_ROKUBI, 30, 0]] world2_level3 = [[0, ACTOR_HAOYA, 60, 0], [0, ACTOR_BATTO, 170, 0], [0, ACTOR_ROKUBI, 75, 0], [0, ACTOR_BAAKE, -1, 1], [1, ACTOR_MOONO, 70, 0], [1, ACTOR_BAAKE, -1, 1], [2, ACTOR_BAAKE, -1, 1], [2, ACTOR_ROKUBI, 180, 1], [3, ACTOR_MOONO, 200, 0], [4, ACTOR_BAAKE_BOSS, -1, 1], [4, ACTOR_HAOYA, 100, 0], [4, ACTOR_BATTO, 240, 0], [4, ACTOR_ROKUBI, 90, 0], [4, ACTOR_BAAKE, -1, 1]] world3_level0 = [[0, ACTOR_HAKTA, 35, 0], [0, ACTOR_HAOYA, 65, 0], [1, ACTOR_BOKKO, -1, 1], [2, ACTOR_BOKKO, -1, 1], [2, ACTOR_HAKTA, 75, 0], [3, ACTOR_BOKKO, -1, 1], [4, ACTOR_MOONO_BOSS, -1, 1], [4, ACTOR_HAKTA, 30, 0]] world3_level1 = [[0, ACTOR_RAAYU, 45, 0], [0, ACTOR_HAKTA, 50, 0], [1, ACTOR_BOKKO, -1, 1], [2, ACTOR_RAAYU, 60, 0], [3, ACTOR_BOKKO, -1, 1], [3, ACTOR_ROKUBI, 80, 0], [4, ACTOR_MOONO_BOSS, -1, 1], [4, ACTOR_RAAYU, 25, 0]] world3_level2 = [[0, ACTOR_PAAJO, 95, 0], [0, ACTOR_HAKTA, 40, 0], [1, ACTOR_BOKKO, -1, 2], [2, ACTOR_RAAYU, 80, 0], [3, ACTOR_BOKKO, -1, 1], [4, ACTOR_MOONO_BOSS, -1, 1], [4, ACTOR_PAAJO, 70, 0]] world3_level3 = [[0, ACTOR_HAKTA, 55, 0], [0, ACTOR_RAAYU, 75, 0], [0, ACTOR_PAAJO, 160, 0], [1, ACTOR_BOKKO, -1, 2], [1, ACTOR_ROKUBI, 50, 0], [2, ACTOR_HAOYA, 120, 0], [3, ACTOR_BOKKO, -1, 1], [4, ACTOR_MOONO_BOSS, -1, 1], [4, ACTOR_HAKTA, 60, 0], [4, ACTOR_RAAYU, 50, 0], [4, ACTOR_PAAJO, 110, 0], [4, ACTOR_BOKKO, -1, 1]] tutorial_world = ['Tutorial', self.player, self.group_list] temp_world_1 = [ 'Cloudopolis', self.player, self.group_list, [world1_level0, world1_level1, world1_level2, world1_level3] ] temp_world_2 = [ 'Nightmaria', self.player, self.group_list, [world2_level0, world2_level1, world2_level2, world2_level3] ] temp_world_3 = [ 'Opulent Dream', self.player, self.group_list, [world3_level0, world3_level1, world3_level2, world3_level3] ] self.world_list = [ tutorial_world, temp_world_1, temp_world_2, temp_world_3 ] self.world_number = world_to_start if self.world_number == 0: self.current_world = tutorial.Tutorial( self.world_list[self.world_number]) else: self.current_world = world.World( self.world_list[self.world_number], self.music_list[self.world_number]) self.current_world.load() if self.world_number == 0: self.new_scene = scene.TutorialScene() self.player.lives = 99 self.life_board.set_text('x' + str(self.player.lives)) elif self.world_number == 1: self.new_scene = scene.ForestScene() elif self.world_number == 2: self.new_scene = scene.RockyScene() elif self.world_number == 3: self.new_scene = scene.PinkScene()