Skip to content
Snippets Groups Projects
Commit 5a9b4874 authored by Florian Schröder's avatar Florian Schröder
Browse files

Add docstrings and minor adjustments to cooperative_cuisine

This commit adds detailed docstrings for various methods and classes in the 'cooperative_cuisine' module for enhanced code understanding. Also includes minor changes to the .gitlab-ci.yml and pygame_2d_vis/__init__.py files and adds an image in the docs markdown file. Code readability and maintainability improved with these changes.
parent a96a9cbb
No related branches found
No related tags found
No related merge requests found
Pipeline #47829 passed
...@@ -17,7 +17,7 @@ pages: ...@@ -17,7 +17,7 @@ pages:
- apt-get update -qy - apt-get update -qy
- apt-get install -y python3-dev python3-pip graphviz graphviz-dev - apt-get install -y python3-dev python3-pip graphviz graphviz-dev
- pip install pdoc - pip install pdoc
- pip install ".[rl]" - pip install .
- pdoc --output-dir public cooperative_cuisine !cooperative_cuisine.reinforcement_learning --logo https://gitlab.ub.uni-bielefeld.de/uploads/-/system/project/avatar/6780/Cooking-Vector-Illustration-Icon-Graphics-4267218-1-580x435.jpg --docformat google --favicon overcooked-simulator/cooperative_cuisine/pygame_2d_vis/images/favicon.ico --footer-text "Developed@SCS" - pdoc --output-dir public cooperative_cuisine !cooperative_cuisine.reinforcement_learning --logo https://gitlab.ub.uni-bielefeld.de/uploads/-/system/project/avatar/6780/Cooking-Vector-Illustration-Icon-Graphics-4267218-1-580x435.jpg --docformat google --favicon overcooked-simulator/cooperative_cuisine/pygame_2d_vis/images/favicon.ico --footer-text "Developed@SCS"
artifacts: artifacts:
paths: paths:
......
...@@ -199,6 +199,7 @@ class HookCallbackClass: ...@@ -199,6 +199,7 @@ class HookCallbackClass:
- The **kwargs parameter allows for additional arguments to be passed to the callback function. - The **kwargs parameter allows for additional arguments to be passed to the callback function.
Usage Example: Usage Example:
```python
# Create an instance of HookCallbackClass # Create an instance of HookCallbackClass
callback = HookCallbackClass("my_callback", my_env) callback = HookCallbackClass("my_callback", my_env)
...@@ -212,11 +213,14 @@ class HookCallbackClass: ...@@ -212,11 +213,14 @@ class HookCallbackClass:
# Call the callback # Call the callback
my_callback("hook_reference", my_env) my_callback("hook_reference", my_env)
```
""" """
def __init__(self, name: str, env: Environment, **kwargs): def __init__(self, name: str, env: Environment, **kwargs):
self.name = name self.name = name
"""The name of the callback."""
self.env = env self.env = env
"""Reference to the environment."""
@abstractmethod @abstractmethod
def __call__(self, hook_ref: str, env: Environment, **kwargs): def __call__(self, hook_ref: str, env: Environment, **kwargs):
...@@ -245,6 +249,25 @@ def hooks_via_callback_class( ...@@ -245,6 +249,25 @@ def hooks_via_callback_class(
def add_dummy_callbacks(env): def add_dummy_callbacks(env):
"""Checking the hooks-callback functionality.
Args:
env: The environment object that represents the system environment.
This method adds dummy callbacks to the given environment object. Each callback is registered for a specific hook using the `register_callback_for_hook` method of the environment.
The callbacks are defined using the `partial` function from the `functools` module. This allows us to pass additional arguments to the callback while registering it. The `print_hook
*_callback` function is used as the callback function, and it prints a message to the console.
Here are the hooks and corresponding messages that are registered:
1. SERVE_NOT_ORDERED_MEAL: Prints the message "You tried to serve a meal that was not ordered!"
2. SINK_START_INTERACT: Prints the message "You started to use the Sink!"
3. COMPLETED_ORDER: Prints the message "You completed an order!"
4. TRASHCAN_USAGE: Prints the message "You used the trashcan!"
These dummy callbacks can be used for testing or demonstration purposes.
"""
env.register_callback_for_hook( env.register_callback_for_hook(
SERVE_NOT_ORDERED_MEAL, SERVE_NOT_ORDERED_MEAL,
partial( partial(
......
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
2D visualization of the CooperativeCuisine. 2D visualization of the CooperativeCuisine.
You can select the layout and start an environment: You can select the layout and start an environment:
- You can play the CooperativeCuisine. You can quit the application in the top right or end the level in the bottom right: [Screenshot](https://gitlab.ub.uni-bielefeld.de/scs/cocosy/overcooked-simulator/-/raw/main/overcooked_simulator/pygame_2d_vis/images/overcooked-start-screen.png?ref_type=heads) - 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: [Screenshot](https://gitlab.ub.uni-bielefeld.de/scs/cocosy/overcooked-simulator/-/raw/main/overcooked_simulator/pygame_2d_vis/images/overcooked-level-screen.png?ref_type=heads) - 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: [Screenshot](https://gitlab.ub.uni-bielefeld.de/scs/cocosy/overcooked-simulator/-/raw/main/overcooked_simulator/pygame_2d_vis/images/overcooked-end-screen.png?ref_type=heads) - The final screen after ending a level shows the score
.. include:: images/images_md_for_docs.md
The keys for the control of the players are: The keys for the control of the players are:
...@@ -12,9 +14,12 @@ The keys for the control of the players are: ...@@ -12,9 +14,12 @@ The keys for the control of the players are:
- Movement: `W`, `A`, `S`, `D`, - Movement: `W`, `A`, `S`, `D`,
- Pickup: `E` - Pickup: `E`
- Interact: `F` - Interact: `F`
- Swap Players (if configured): `SPACE`
### Player 2: ### Player 2:
- Movement: `⬆`, `⬅`, `⬇`, `➡` (arrow keys) - Movement: `⬆`, `⬅`, `⬇`, `➡` (arrow keys)
- Pickup: `I` - Pickup: `I`
- Interact: `SPACE` - Interact: `O`
- Swap Players (if configured): `P`
""" """
![image](cooperative_cuisine.png)
\ No newline at end of file
cooperative_cuisine/pygame_2d_vis/images/overcooked-end-screen.png

16.6 KiB

cooperative_cuisine/pygame_2d_vis/images/overcooked-level-screen.png

85.1 KiB

cooperative_cuisine/pygame_2d_vis/images/overcooked-start-screen.png

17.6 KiB

...@@ -78,9 +78,11 @@ class FileRecorder(HookCallbackClass): ...@@ -78,9 +78,11 @@ class FileRecorder(HookCallbackClass):
): ):
super().__init__(name, env, **kwargs) super().__init__(name, env, **kwargs)
self.add_hook_ref = add_hook_ref self.add_hook_ref = add_hook_ref
"""If the name of the hook (the reference) should be included in the recording."""
log_path = log_path.replace("LOG_RECORD_NAME", name) log_path = log_path.replace("LOG_RECORD_NAME", name)
log_path = Path(expand_path(log_path, env_name=env.env_name)) log_path = Path(expand_path(log_path, env_name=env.env_name))
self.log_path = log_path self.log_path = log_path
"""The path to the recording file."""
log.info(f"Recorder record for {name} in file://{log_path}") log.info(f"Recorder record for {name} in file://{log_path}")
os.makedirs(log_path.parent, exist_ok=True) os.makedirs(log_path.parent, exist_ok=True)
......
...@@ -84,9 +84,13 @@ class ScoreViaHooks(HookCallbackClass): ...@@ -84,9 +84,13 @@ class ScoreViaHooks(HookCallbackClass):
): ):
super().__init__(name, env, **kwargs) super().__init__(name, env, **kwargs)
self.score_map = score_map self.score_map = score_map
"""Mapping of hook references to scores."""
self.static_score = static_score self.static_score = static_score
"""The static score to be added if no other conditions are met."""
self.kwarg_filter = kwarg_filter self.kwarg_filter = kwarg_filter
"""Filtering condition for keyword arguments."""
self.score_on_specific_kwarg = score_on_specific_kwarg self.score_on_specific_kwarg = score_on_specific_kwarg
"""The specific keyword argument to score on."""
def __call__(self, hook_ref: str, env: Environment, **kwargs): def __call__(self, hook_ref: str, env: Environment, **kwargs):
if self.score_on_specific_kwarg: if self.score_on_specific_kwarg:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment