From 2bd77a93ac2b64e2cb744f4467f42af141270e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Schr=C3=B6der?= <fschroeder@techfak.uni-bielefeld.de> Date: Sat, 9 Mar 2024 20:50:24 +0100 Subject: [PATCH] Refactor docstrings for consistency and update environment name Docstrings across classes and functions in different modules have been adjusted for consistency, specifically in how Return and Raise explanations are formatted. This makes the code more readable and uniform. Additionally, the environment name in 'environment.py' has been updated from "overcooked_sim" to "cooperative_cuisine_1". --- cooperative_cuisine/counters.py | 7 +++-- cooperative_cuisine/environment.py | 9 +++--- cooperative_cuisine/game_server.py | 4 +-- cooperative_cuisine/pygame_2d_vis/__init__.py | 2 +- cooperative_cuisine/study_server.py | 31 +++++++++++++------ cooperative_cuisine/utils.py | 3 +- 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/cooperative_cuisine/counters.py b/cooperative_cuisine/counters.py index 991074a3..7220f1ba 100644 --- a/cooperative_cuisine/counters.py +++ b/cooperative_cuisine/counters.py @@ -157,7 +157,8 @@ class Counter: on_hands: Will the item be put on empty hands or on a cooking equipment. player: The player name that tries to pick up from the counter. - Returns: The item which the counter is occupied by. None if nothing is there. + Returns: + The item which the counter is occupied by. None if nothing is there. """ self.hook(PRE_COUNTER_PICK_UP, counter=self, on_hands=on_hands, player=player) if on_hands: @@ -202,8 +203,8 @@ class Counter: item: The item for which to check, if it can be placed on the counter. - Returns: True if the item can be placed on the counter, False if not. - + Returns: + True if the item can be placed on the counter, False if not. """ return self.occupied_by is None or self.occupied_by.can_combine(item) diff --git a/cooperative_cuisine/environment.py b/cooperative_cuisine/environment.py index 57c957ae..04e1409c 100644 --- a/cooperative_cuisine/environment.py +++ b/cooperative_cuisine/environment.py @@ -107,7 +107,7 @@ class Environment: layout_config: Path | str, item_info: Path | str, as_files: bool = True, - env_name: str = "overcooked_sim", + env_name: str = "cooperative_cuisine_1", seed: int = 56789223842348, ): """Constructor of the Environment. @@ -471,8 +471,8 @@ class Environment: player_id: The player for which to get the state. additional_key_values: Additional dict that is added to the state - Returns: The state of the game as a dict. - + Returns: + The state of the game as a dict. """ if player_id in self.players: self.hook(PRE_STATE, player_id=player_id) @@ -524,7 +524,8 @@ class Environment: player_id: The player for which to get the state. additional_key_values: Additional dict that is added to the state - Returns: The state of the game formatted as a json-string + Returns: + The state of the game formatted as a json-string """ state = self.get_state(player_id, additional_key_values) diff --git a/cooperative_cuisine/game_server.py b/cooperative_cuisine/game_server.py index 093f3076..f9b2fbdb 100644 --- a/cooperative_cuisine/game_server.py +++ b/cooperative_cuisine/game_server.py @@ -280,9 +280,9 @@ class EnvironmentHandler: Args: player_hash (str): The unique identifier of the player. - Returns: str: The state representation of the environment for a player. Is + Returns: + str: The state representation of the environment for a player. Is `cooperative_cuisine.state_representation.StateRepresentation` as a json. - """ if ( player_hash in self.player_data diff --git a/cooperative_cuisine/pygame_2d_vis/__init__.py b/cooperative_cuisine/pygame_2d_vis/__init__.py index a90ff6d1..c6af81b3 100644 --- a/cooperative_cuisine/pygame_2d_vis/__init__.py +++ b/cooperative_cuisine/pygame_2d_vis/__init__.py @@ -1,7 +1,7 @@ """ 2D visualization of the CooperativeCuisine. -You can select the layout and start an environment: +You will play the levels accordingly to the study config: - You can play the CooperativeCuisine. You can quit the application in the top right or end the level in the bottom right - The orders are pictured in the top, the current score in the bottom left and the remaining time in the bottom - The final screen after ending a level shows the score diff --git a/cooperative_cuisine/study_server.py b/cooperative_cuisine/study_server.py index 2f794f0e..fe69626b 100644 --- a/cooperative_cuisine/study_server.py +++ b/cooperative_cuisine/study_server.py @@ -150,7 +150,8 @@ class Study: Args: num_participants: Number of participants wished to be added. - Returns: True of the participants fit in this study, False if not. + Returns: + True of the participants fit in this study, False if not. """ filled = ( self.num_connected_players + num_participants @@ -165,8 +166,11 @@ class Study: Args: level: LevelConfig which contains the paths to the env config, layout and item info files. - Returns: EnvironmentData which contains information about the newly created environment. - Raises: ValueError if the gameserver returned a conflict, HTTPError with 500 if the game server crashes. + Returns: + EnvironmentData which contains information about the newly created environment. + + Raises: + ValueError if the gameserver returned a conflict, HTTPError with 500 if the game server crashes. """ item_info_path = expand_path(level["item_info_path"]) @@ -279,9 +283,12 @@ class Study: Args: participant_id: The participant id which requests the connections. - Returns: The player info for the game server connections, level name and - information if the level is the last one and which recipes are possible in the level. - Raises: HTTPException(409) if the player is not found in the dictionary keys which saves the connections. + Returns: + The player info for the game server connections, level name and information if the level is the last + one and which recipes are possible in the level. + + Raises: + HTTPException(409) if the player is not found in the dictionary keys which saves the connections. """ if participant_id in self.participant_id_to_player_info.keys(): player_info = self.participant_id_to_player_info[participant_id] @@ -446,9 +453,12 @@ class StudyManager: Args: participant_id: ID of the participant. - Returns: The player info for the game server connections, level name and - information if the level is the last one and which recipes are possible in the level. - Raises: HTTPException(409) if the player not registered in any study. + Returns: + The player info for the game server connections, level name and information if the level is the last one and + which recipes are possible in the level. + + Raises: + HTTPException(409) if the player not registered in any study. """ if participant_id in self.running_tutorials.keys(): tutorial_env = self.running_tutorials[participant_id] @@ -596,7 +606,8 @@ async def get_game_connection( Args: participant_id: ID of the requesting participant. - Returns: A dict containing the game server connection information and information about the current level. + Returns: + A dict containing the game server connection information and information about the current level. """ player_info, level_info = study_manager.get_participant_game_connection( diff --git a/cooperative_cuisine/utils.py b/cooperative_cuisine/utils.py index fd1effc4..102c340a 100644 --- a/cooperative_cuisine/utils.py +++ b/cooperative_cuisine/utils.py @@ -170,7 +170,8 @@ def get_closest(point: npt.NDArray[float], counters: list[Counter]): point: The point in the env for which to find the closest counter counters: List of objects with a `pos` attribute to compare to. - Returns: The closest counter for the given point. + Returns: + The closest counter for the given point. """ return counters[ -- GitLab