From 54f94688b6d2e6cb57fb5e126c947995e2cdabb7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20Schr=C3=B6der?=
 <fschroeder@techfak.uni-bielefeld.de>
Date: Wed, 10 Apr 2024 13:24:11 +0200
Subject: [PATCH] Add recipe graph and info to cooperative cuisine

Recipe graphs now include the names of 'interactive_counter' and 'equipment' in Cooperative Cuisine. Updated the random agent to also receive recipe graphs information. These changes were implemented to enhance functionality and efficiently retrieve required information.
---
 CHANGELOG.md                                  |  5 +++++
 .../configs/agents/random_agent.py            |  2 ++
 cooperative_cuisine/pygame_2d_vis/gui.py      |  1 +
 cooperative_cuisine/validation.py             | 22 +++++++++++++++++++
 4 files changed, 30 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e4588eee..74397a36 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,9 @@
 
 ### Added
 
+- Recipe graphs contain the names of the interactive counters and equipment
+- Random agent also gets the recipe graph information.
+
 ### Changed
 
 - `CooperativeCuisine` occurrences to `Cooperative Cuisine`
@@ -23,6 +26,8 @@
 
 ### Fixed
 
+- Random Order generation does not depend on other sampling of random numbers.
+
 ### Security
 
 ## [1.1.1] (2024-04-03)
diff --git a/cooperative_cuisine/configs/agents/random_agent.py b/cooperative_cuisine/configs/agents/random_agent.py
index 6d8830d9..506f2a63 100644
--- a/cooperative_cuisine/configs/agents/random_agent.py
+++ b/cooperative_cuisine/configs/agents/random_agent.py
@@ -50,10 +50,12 @@ async def agent():
     parser.add_argument("--player_id", type=str)
     parser.add_argument("--player_hash", type=str)
     parser.add_argument("--step_time", type=float, default=0.1)
+    parser.add_argument("--recipe_graph", type=str, default="")
 
     args = parser.parse_args()
 
     async with (connect(args.uri) as websocket):
+        recipe_graph = json.loads(args.recipe_graph)
         await websocket.send(
             json.dumps({"type": "ready", "player_hash": args.player_hash})
         )
diff --git a/cooperative_cuisine/pygame_2d_vis/gui.py b/cooperative_cuisine/pygame_2d_vis/gui.py
index 20ff8d1a..65619e26 100644
--- a/cooperative_cuisine/pygame_2d_vis/gui.py
+++ b/cooperative_cuisine/pygame_2d_vis/gui.py
@@ -1756,6 +1756,7 @@ class PyGameGUI:
                         f'--uri {player_info["websocket_url"]}',
                         f"--player_hash {player_hash}",
                         f"--player_id {player_id}",
+                        f"--recipe_graph '{json.dumps(self.level_info['recipe_graphs'])}'",
                     ]
                 ),
                 shell=True,
diff --git a/cooperative_cuisine/validation.py b/cooperative_cuisine/validation.py
index 111edaf7..c87d208a 100644
--- a/cooperative_cuisine/validation.py
+++ b/cooperative_cuisine/validation.py
@@ -34,6 +34,9 @@ class MealGraphDict(TypedDict):
     """A dictionary mapping cooking step names to their layout coordinates."""
     score: float
     """The max possible score of the meal."""
+    info: dict[str, list[str]]
+    """The names of the `interactive_counter` and `equipment` (not the ids of the individual). Is not reduced to the 
+    meal."""
 
 
 class Validation:
@@ -70,6 +73,21 @@ class Validation:
         self.recipe_graph_dicts: dict | None = None
         """A dictionary containing recipe graphs for each meal. For visualisation of the recipes."""
 
+        self.interactive_counter = [
+            c
+            for c in self.item_info
+            if self.item_info[c].type == ItemType.Equipment
+            and not self.item_info[c].equipment
+        ]
+        """The list of names of stationary mentioned equipments like stove, cutting board but not pot etc."""
+        self.equipments = [
+            eq
+            for eq in self.item_info
+            if self.item_info[eq].type == ItemType.Equipment
+            and self.item_info[eq].equipment
+        ]
+        """The list of names of the equipments in the environment."""
+
     @staticmethod
     def infer_recipe_graph(item_info) -> DiGraph:
         """Generate a graph from ingredients and meals and their dependencies.
@@ -210,6 +228,10 @@ class Validation:
                 "edges": list(graph.edges),
                 "layout": layout,
                 "score": score,
+                "info": {
+                    "interactive_counter": self.interactive_counter,
+                    "equipment": self.equipments,
+                },
             }
             with open(generated_graph_layouts_path, "w") as f:
                 self.recipe_graph_dicts[graph_hash] = graph_dict
-- 
GitLab