diff --git a/cooperative_cuisine/game_server.py b/cooperative_cuisine/game_server.py index c017a1d0a38dcebb25e51b63286eb18aadcd60b9..01a3b02cbecd8cf515d929bca83152bc81e71cc1 100644 --- a/cooperative_cuisine/game_server.py +++ b/cooperative_cuisine/game_server.py @@ -41,6 +41,7 @@ from cooperative_cuisine.utils import ( add_list_of_manager_ids_arguments, disable_websocket_logging_arguments, setup_logging, + UUID_CUTOFF, ) log = logging.getLogger(__name__) @@ -162,8 +163,7 @@ class EnvironmentHandler: """ if environment_config.manager_id not in self.allowed_manager: return 1 - env_id = uuid.uuid4().hex - + env_id = f"{environment_config.env_name}_env_{uuid.uuid4().hex[:UUID_CUTOFF]}" # todo uuid cutoff if environment_config.number_players < 1: raise HTTPException( status_code=409, detail="Number players need to be positive." @@ -749,6 +749,7 @@ class CreateEnvironmentConfig(BaseModel): environment_config: str # file content layout_config: str # file content seed: int + env_name: str class ManageEnv(BaseModel): diff --git a/cooperative_cuisine/pygame_2d_vis/gui.py b/cooperative_cuisine/pygame_2d_vis/gui.py index cd5f1795501b97bf711eea1b7b031800b07ff131..df472228b29051133df2872bc8b1b28db9d3d767 100644 --- a/cooperative_cuisine/pygame_2d_vis/gui.py +++ b/cooperative_cuisine/pygame_2d_vis/gui.py @@ -1472,6 +1472,7 @@ class PyGameGUI: environment_config=environment_config, layout_config=layout, seed=seed, + env_name=layout_path.stem ).model_dump(mode="json") # print(CreateEnvironmentConfig.model_validate_json(json_data=creation_json)) diff --git a/cooperative_cuisine/study_server.py b/cooperative_cuisine/study_server.py index ef19419279d33e8107ab8079c2262c7b12eb3f30..27896e71b25d73424f49e90a8fe6aa6ddd5afd23 100644 --- a/cooperative_cuisine/study_server.py +++ b/cooperative_cuisine/study_server.py @@ -18,6 +18,7 @@ import os import random import signal import subprocess +import uuid from pathlib import Path from subprocess import Popen from typing import Tuple, Any @@ -38,6 +39,7 @@ from cooperative_cuisine.utils import ( expand_path, add_study_arguments, deep_update, + UUID_CUTOFF, ) log = logging.getLogger(__name__) @@ -108,6 +110,9 @@ class Study: with open(study_config_path, "r") as file: env_config_f = file.read() + self.study_id = uuid.uuid4().hex[:UUID_CUTOFF] + """Unique ID of the study.""" + self.study_config: StudyConfig = yaml.load( str(env_config_f), Loader=yaml.Loader ) @@ -208,6 +213,7 @@ class Study: environment_config=environment_config, layout_config=layout, seed=seed, + env_name=f"study_{self.study_id}_level_{self.current_level_idx}", ).model_dump(mode="json") env_info = request_game_server( @@ -547,6 +553,7 @@ class StudyManager: environment_config=environment_config, layout_config=layout, seed=1234567890, + env_name="tutorial", ).model_dump(mode="json") # todo async env_info = request_game_server( diff --git a/cooperative_cuisine/utils.py b/cooperative_cuisine/utils.py index 35a5cdecae47c9e416f072f85a201be068522346..88719d54d8fc2fc00cf67d464af0a8c764f9457e 100644 --- a/cooperative_cuisine/utils.py +++ b/cooperative_cuisine/utils.py @@ -35,6 +35,9 @@ DEFAULT_SERVER_PORT = 8080 DEFAULT_GAME_PORT = 8000 """Default game server port.""" +UUID_CUTOFF = 8 +"""The cutoff length for UUIDs.""" + def expand_path(path: str, env_name: str = "") -> str: """Expand a path with VARIABLES to the path variables based on the user's OS or installation location of the Cooperative Cuisine.