From 3bfcdbfb5bc89795254fd3d9746a941014e34e9e Mon Sep 17 00:00:00 2001 From: huangping Date: Tue, 19 Mar 2024 15:14:04 +0800 Subject: [PATCH 1/2] change index align to stretch --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index f7c9f6b..83c5ad0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -14,7 +14,7 @@ CivRealm is an interactive environment for the open-source strategy game [Freeci display: grid; grid-template-columns: 1fr 1fr 1fr; grid-gap: 20px; - align-items: center; + align-items: stretch; } .grid > article { border: 1px solid #ccc; From c03fc5dab6b3cd5aa6dd4cca66a8849dcb1e1d9e Mon Sep 17 00:00:00 2001 From: huangping Date: Wed, 3 Apr 2024 16:00:13 +0800 Subject: [PATCH 2/2] supported minigame fullgame_50_turn_objectives --- src/civrealm/configs/default_settings.yaml | 6 +++++- src/civrealm/envs/freeciv_minitask_env.py | 15 +++++++++++---- src/civrealm/freeciv/civ_controller.py | 3 +++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/civrealm/configs/default_settings.yaml b/src/civrealm/configs/default_settings.yaml index 09b38d0..42b5817 100644 --- a/src/civrealm/configs/default_settings.yaml +++ b/src/civrealm/configs/default_settings.yaml @@ -56,6 +56,8 @@ batch_size_run: 5 epoch_num: 1 # The port used by the first environment; other parallel environments use ports following this port. port_start: 6300 +# The username of minitask +minitask_username: minitask debug: # Records the game state and available actions at every step. @@ -90,7 +92,9 @@ debug: # load_game: "testcontroller_T200_2023-07-31-01_51" # The name of the saved game to be loaded. load_game: "" - + # whether to aitoggle and take the player + take_player: + # whether to use randomly generated seeds for running games. if True, the following random seeds (mapseed, gameseed, agentseed) are ignored randomly_generate_seeds: True # The seed for generating a map. The same seed leads to the same map. diff --git a/src/civrealm/envs/freeciv_minitask_env.py b/src/civrealm/envs/freeciv_minitask_env.py index 88f068c..22392ac 100644 --- a/src/civrealm/envs/freeciv_minitask_env.py +++ b/src/civrealm/envs/freeciv_minitask_env.py @@ -45,7 +45,7 @@ class MinitaskType(ExtendedEnum): MT_BATTLE_ATTACK_CITY = "battle_attack_city" MT_BATTLE_DEFEND_CITY = "battle_defend_city" MT_DIPLOMACY_TRADE_TECH = "diplomacy_trade_tech" - + MT_FULL_GAME_50_TURN = "fullgame_50_turn_objectives" @unique class MinitaskGameStatus(ExtendedEnum): @@ -67,16 +67,17 @@ class MinitaskDifficulty(ExtendedEnum): MD_HARD = 'hard' -DEFAULT_TASK = "minitask" MAX_ID = 999 BATTLE_MINITASK_LIST = [ _minitask for _minitask in MinitaskType.list() if _minitask.startswith("battle")] +FULLGAME_MINITASK_LIST = [ + _minitask for _minitask in MinitaskType.list() if _minitask.startswith("fullgame")] class FreecivMinitaskEnv(FreecivBaseEnv): """ CivRealm environment for mini-game. """ - def __init__(self, username: str = DEFAULT_TASK, client_port: int = fc_args['client_port']): + def __init__(self, username: str = fc_args["minitask_username"], client_port: int = fc_args['client_port']): super().__init__(username=username, client_port=client_port, is_minitask=True) fc_args['username'] = username self.filename = None @@ -99,6 +100,10 @@ def get_minitask(name, minitask_pattern, max_id): if isinstance(minitask_type, list): minitask_type = random.choice(minitask_type) + if minitask_type in FULLGAME_MINITASK_LIST and fc_args['username'] == "minitask": + minitask_level = "normal" + minitask_id = 0 + if minitask_type not in MinitaskType.list(): raise ValueError( f"Not supported type as {minitask_pattern}. The suppported list is {MinitaskType.list()}!") @@ -161,7 +166,9 @@ def set_minitask(self, seed, minitask_pattern, max_id): fc_args['username'], minitask_pattern, max_id) self.filename = minitask self.task_type = re.match( - r"{}_T\d+_task_([a-z]+)_.*".format(fc_args['username']), minitask)[1] + r"{}_T\d+_task_([0-9a-z_]+)_level".format(fc_args['username']), minitask)[1] + if self.task_type in FULLGAME_MINITASK_LIST and fc_args['username'] == "minitask": + self.civ_controller.set_parameter('debug.take_player', "AI*1") self.civ_controller.set_parameter('debug.load_game', minitask) return diff --git a/src/civrealm/freeciv/civ_controller.py b/src/civrealm/freeciv/civ_controller.py index 4145891..7983687 100644 --- a/src/civrealm/freeciv/civ_controller.py +++ b/src/civrealm/freeciv/civ_controller.py @@ -712,6 +712,9 @@ def load_game(self, save_name): self.ws_client.send_message(f"/set victories {fc_args['victories']}") self.ws_client.send_message(f"/set endvictory {fc_args['endvictory']}") self.ws_client.send_message(f"/set advisor {fc_args['advisor']}") + if fc_args['debug.take_player']: + self.clstate.aitoggle_player(fc_args['debug.take_player']) + self.clstate.take_player(fc_args['debug.take_player']) requests.post( f"http://{self.host}:{fc_web_args['port']}/gamesetting?openchatbox={fc_args['openchatbox']}")