def setup(self): self.gui_config = Config(render=self.render, view=self.render, inputs=False, caption=False, unit_health=True, unit_outline=True, unit_animation=True, audio=self.play_audio, audio_volume=50) if self.engine_config == None: self.engine_config = Engine.Config.defaults() self.engine_config.set_start_oil(self.start_oil) self.engine_config.set_start_gold(self.start_gold) self.engine_config.set_start_lumber(self.start_lumber) self.engine_config.set_start_food(self.start_food) self.engine_config.set_archer(True) self.engine_config.set_instant_town_hall(False) self.engine_config.set_barracks(True) self.game = Game(self.map, n_players=self.number_of_players, engine_config=self.engine_config, gui_config=self.gui_config, terminal_signal=False, fit_to_screen=self.fit_to_screen) self.game.set_max_fps(self.max_fps) self.game.set_max_ups(self.max_ups) self.players = self.game.players self.done = False
def __init__(self, config): engconf = config["engine"] if "engine" in config else {} gconf = config["gui"] if "gui" in config else {} rlconf = config["rl"] if "rl" in config else {} gui_config = Config( render=util.config(gconf, "render", True), view=util.config(gconf, "view", True), inputs=util.config(gconf, "inputs", False), caption=util.config(gconf, "caption", False), unit_health=util.config(gconf, "unit_health", False), unit_outline=util.config(gconf, "unit_outline", False), unit_animation=util.config(gconf, "unit_animation", False), audio=util.config(gconf, "audio", False), audio_volume=util.config(gconf, "audio_volume", 50) ) engine_config: Engine.Config = Engine.Config.defaults() engine_config.set_barracks(True) engine_config.set_footman(True) engine_config.set_instant_town_hall(True) engine_config.set_archer(True) engine_config.set_start_lumber(250) # Enough to create TownHall engine_config.set_start_gold(500) # Enough to create TownHall engine_config.set_start_oil(0) engine_config.set_tick_modifier(util.config(engconf, "tick_modifier", engine_config.tick_modifier)) game = Game( Config.Map.FIFTEEN, n_players=1, engine_config=engine_config, gui_config=gui_config, terminal_signal=False ) c_fps = engconf["fps"] if "fps" in engconf else -1 c_ups = engconf["ups"] if "ups" in engconf else -1 game.set_max_fps(c_fps) game.set_max_ups(c_ups) super().__init__( rlconf, game, #Scenario.GOLD_COLLECT(1000), Scenario.GOLD_COLLECT_INCREMENT(100) )
def __init__(self, map_name, n_players=2, engine_config=Engine.Config.defaults(), gui_config=None, tile_size=32, terminal_signal=False): # This sets working directory, so that the C++ can load files correctly (dir_path not directly accessible in # c++) os.chdir(dir_path) # Override map parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('--map', action="store", dest="map", type=str) args = parser.parse_args() if args.map is not None: map_name = args.map # TODO if engine_config: engine_config.set_terminal_signal(terminal_signal) # Disable terminal signal engine_config.set_terminal_signal(terminal_signal) # Call C++ constructor super(Game, self).__init__(map_name, engine_config) # Event listeners self._listeners = {"on_tile_change": []} self._render_every = 1 self._view_every = 1 self._capture_every = 1 self.gui = GUI( self, tile_size=tile_size, config=gui_config if isinstance(gui_config, Config) else Config()) # Create players for i in range(n_players): self.add_player() # Select first player as default self.set_player(self.players[0]) self.start()
def __init__(self, map_name, n_players=2, engine_config=Engine.Config.defaults(), gui_config=None, tile_size=32, terminal_signal=False): # This sets working directory, so that the C++ can load files correctly (dir_path not directly accessible in # c++) os.chdir(dir_path) # Disable terminal signal engine_config.set_terminal_signal(terminal_signal) # Call C++ constructor super(Game, self).__init__(map_name, engine_config) # Event listeners self._listeners = { "on_tile_change": [] } self._render_every = 1 self._view_every = 1 self._capture_every = 1 self.gui = GUI(self, tile_size=tile_size, config=gui_config if isinstance(gui_config, Config) else Config()) # Create players for i in range(n_players): self.add_player() # Select first player as default self.set_player(self.players[0]) self.start()
def __init__(self, config): engconf = config["engine"] if "engine" in config else {} gconf = config["gui"] if "gui" in config else {} rlconf = config["rl"] if "rl" in config else {} gui_config = Config(render=util.config(gconf, "render", True), view=util.config(gconf, "view", True), inputs=util.config(gconf, "inputs", False), caption=util.config(gconf, "caption", False), unit_health=util.config(gconf, "unit_health", False), unit_outline=util.config(gconf, "unit_outline", False), unit_animation=util.config(gconf, "unit_animation", False), audio=util.config(gconf, "audio", False), audio_volume=util.config(gconf, "audio_volume", 50)) engine_config: Engine.Config = Engine.Config.defaults() engine_config.set_instant_building(True) engine_config.set_instant_town_hall(True) engine_config.set_barracks(True) engine_config.set_farm(True) engine_config.set_footman(True) engine_config.set_archer(True) engine_config.set_start_lumber(500) engine_config.set_start_gold(500) engine_config.set_start_oil(500) engine_config.set_tick_modifier( util.config(engconf, "tick_modifier", engine_config.tick_modifier)) engine_config.set_console_caption_enabled(False) game = Game(Config.Map.TWENTYONE, n_players=2, engine_config=engine_config, gui_config=gui_config, terminal_signal=True) c_fps = engconf["fps"] if "fps" in engconf else -1 c_ups = engconf["ups"] if "ups" in engconf else -1 game.set_max_fps(c_fps) game.set_max_ups(c_ups) super().__init__( rlconf, game, # Scenarios self.GAME_END() # Scenario.DAMAGE_TAKEN(), # Scenario.NUM_FARM(), # Scenario.NUM_TOWN_HALL(), # Scenario.NUM_BARRACK(), # Scenario.GOLD_COLLECT_INCREMENT(100) # Scenario.LUMBER_COLLECT_INCREMENT(), # Scenario.OIL_COLLECT_INCREMENT(), # Scenario.UNITS_CREATED() ) self.DEFAULTS['flatten'] = False
def __init__(self, map_name, n_players=2, engine_config=Engine.Config.defaults(), gui_config=None, tile_size=32, terminal_signal=False, fit_to_screen=False): # This sets working directory, so that the C++ can load files correctly (dir_path not directly accessible in # c++) os.chdir(dir_path) # Disable terminal signal engine_config.set_terminal_signal(terminal_signal) # Call C++ constructor super(Game, self).__init__(map_name, engine_config) # Event listeners self._listeners = { "on_tile_change": [] } self._render_every = 1 self._view_every = 1 self._capture_every = 1 scale_factor = 1 if fit_to_screen: #change tile_size in a way that the map fits the screen #since the map is always a square, we can use only width to do the calculation #sc_width, sc_height = pygame.display.get_surface().get_size() pygame.init() sc_width = pygame.display.Info().current_w while sc_width < self.map.map_width * tile_size / scale_factor and scale_factor <= 4: scale_factor *= 2 self.gui = GUI(self, tile_size=tile_size, config=gui_config if isinstance(gui_config, Config) else Config(), scale_factor = scale_factor) # Create players for i in range(n_players): self.add_player() # Select first player as default self.set_player(self.players[0]) self.start()
import random from DeepRTS import Engine from DeepRTS.python import scenario from DeepRTS.python import Config from DeepRTS.python import Game episodes = 100 steps = 100 MAP = "32.json" gui_config = Config(render=True, view=True, inputs=False, caption=False, unit_health=True, unit_outline=True, unit_animation=True, audio=False, audio_volume=50) engine_config = Engine.Config.defaults() game = Game(MAP, n_players=1, engine_config=engine_config, gui_config=gui_config, terminal_signal=False) game.set_max_fps(1000000) game.set_max_ups(1000000)