From 97d33243580e75347f34526e868ae1ce798a6695 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20Schr=C3=B6der?=
 <fschroeder@techfak.uni-bielefeld.de>
Date: Fri, 26 Jan 2024 21:26:27 +0100
Subject: [PATCH] Improve documentation in overcooked_environment and
 counter_factory modules

The code changes include addition of in-line comments and docstrings, which clarify the purpose and functionality of various elements in the overcooked_environment and counter_factory modules. Several new comments explain the use of certain variables and functions, and additional explanations are offered for existing sections. This is part of an ongoing effort to improve the maintainability and readability of the codebase.
---
 overcooked_simulator/counter_factory.py       | 40 +++++++++++++++++++
 .../overcooked_environment.py                 |  7 ++--
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/overcooked_simulator/counter_factory.py b/overcooked_simulator/counter_factory.py
index caa9fb23..5d910aea 100644
--- a/overcooked_simulator/counter_factory.py
+++ b/overcooked_simulator/counter_factory.py
@@ -18,6 +18,15 @@ from overcooked_simulator.game_items import ItemInfo, ItemType, CookingEquipment
 
 
 def convert_words_to_chars(layout_chars_config: dict[str, str]) -> dict[str, str]:
+    """Converts words in a given layout chars configuration dictionary to their corresponding characters.
+
+    Args:
+        layout_chars_config (dict[str, str]): A dictionary containing layout character configurations, where the keys are words
+            representing layout characters and the values are the corresponding character representations.
+
+    Returns:
+        dict[str, str]: A dictionary where the keys are the layout characters and the values are their corresponding words.
+    """
     word_refs = {
         "underscore": "_",
         "hash": "#",
@@ -51,6 +60,10 @@ def convert_words_to_chars(layout_chars_config: dict[str, str]) -> dict[str, str
 
 
 class CounterFactory:
+    """The `CounterFactory` class is responsible for creating counter objects based on the layout configuration and
+    item information provided. It also provides methods for mapping and filtering the item information.
+    """
+
     additional_counter_names = {"Counter"}
 
     def __init__(
@@ -60,6 +73,28 @@ class CounterFactory:
         serving_window_additional_kwargs: dict[str, Any],
         plate_config: PlateConfig,
     ) -> None:
+        """Constructor for the `CounterFactory` class. Set up the attributes necessary to instantiate the counters.
+
+        Args:
+            layout_chars_config (dict[str, str]): A dictionary mapping layout characters to their corresponding names.
+            item_info (dict[str, ItemInfo]): A dictionary containing information about different items.
+            serving_window_additional_kwargs (dict[str, Any]): Additional keyword arguments for serving window configuration.
+            plate_config (PlateConfig): The configuration for plate usage.
+
+        Returns:
+            None
+
+        Initializes the object with the provided parameters. It performs the following tasks:
+        - Converts the layout character configuration from words to characters.
+        - Sets the item information dictionary.
+        - Sets the additional keyword arguments for serving window configuration.
+        - Sets the plate configuration.
+
+        It also sets the following attributes:
+        - `no_counter_chars`: A set of characters that represent counters for agents or free spaces.
+        - `counter_classes`: A dictionary of counter classes imported from the 'overcooked_simulator.counters' module.
+        - `cooking_counter_equipments`: A dictionary mapping cooking counters to the list of equipment items associated with them.
+        """
         self.layout_chars_config = convert_words_to_chars(layout_chars_config)
         self.item_info = item_info
         self.serving_window_additional_kwargs = serving_window_additional_kwargs
@@ -88,6 +123,8 @@ class CounterFactory:
         }
 
     def get_counter_object(self, c: str, pos: npt.NDArray[float]) -> Counter:
+        """Create and returns a counter object based on the provided character and position."""
+
         assert self.can_map(c), f"Can't map counter char {c}"
         counter_class = None
         if self.layout_chars_config[c] in self.item_info:
@@ -136,6 +173,7 @@ class CounterFactory:
         return counter_class(**kwargs)
 
     def can_map(self, char) -> bool:
+        """Check if the provided character can be mapped to a counter object."""
         return char in self.layout_chars_config and (
             not self.is_counter(char)
             or self.layout_chars_config[char] in self.item_info
@@ -143,9 +181,11 @@ class CounterFactory:
         )
 
     def is_counter(self, c: str) -> bool:
+        """Checks if the provided character represents a counter."""
         return c in self.layout_chars_config and c not in self.no_counter_chars
 
     def map_not_counter(self, c: str) -> str:
+        """Maps the provided character to a non-counter word based on the layout configuration."""
         assert self.can_map(c) and not self.is_counter(
             c
         ), "Cannot map char {c} as a 'not counter'"
diff --git a/overcooked_simulator/overcooked_environment.py b/overcooked_simulator/overcooked_environment.py
index c023fa6e..341861a5 100644
--- a/overcooked_simulator/overcooked_environment.py
+++ b/overcooked_simulator/overcooked_environment.py
@@ -103,13 +103,14 @@ class Environment:
         """the player, keyed by their id/name."""
 
         self.as_files = as_files
-
+        """Are the configs just the path to the files."""
         if self.as_files:
             with open(env_config, "r") as file:
                 self.environment_config = yaml.load(file, Loader=yaml.Loader)
         else:
             self.environment_config = yaml.load(env_config, Loader=yaml.Loader)
         self.layout_config = layout_config
+        """The layout config for the environment"""
         # self.counter_side_length = 1  # -> this changed! is 1 now
 
         self.item_info: dict[str, ItemInfo] = self.load_item_info(item_info)
@@ -127,6 +128,7 @@ class Environment:
             self.allowed_meal_names = set(self.environment_config["meals"]["list"])
             """The allowed meals depend on the `environment_config.yml` configured behaviour. Either all meals that 
             are possible or only a limited subset."""
+
         self.order_and_score = OrderAndScoreManager(
             order_config=self.environment_config["orders"],
             available_meals={
@@ -267,9 +269,6 @@ class Environment:
         Counters are arranged in a fixed size grid starting at [0,0]. The center of the first counter is at
         [counter_size/2, counter_size/2], counters are directly next to each other (of no empty space is specified
         in layout).
-
-        Args:
-            layout_file: Path to the layout file.
         """
         current_y: float = 0.5
         counters: list[Counter] = []
-- 
GitLab