diff --git a/cooperative_cuisine/configs/study/study_config.yaml b/cooperative_cuisine/configs/study/study_config.yaml index cf67cf26c87bdc5fe2716b1bff18b350ed3ee3c2..8edfd117202980b691cd22f2f9fd4d0ce0c15559 100644 --- a/cooperative_cuisine/configs/study/study_config.yaml +++ b/cooperative_cuisine/configs/study/study_config.yaml @@ -7,7 +7,7 @@ levels: seed: 12345 config_overwrite: player_config: - speed_units_per_seconds: 5 + speed_units_per_seconds: 8 game: time_limit_seconds: 300 validate_recipes: false @@ -25,13 +25,13 @@ levels: order_gen_kwargs: order_duration_random_func: kwargs: - a: 60 - b: 70 + a: 5 + b: 6 sample_on_dur_random_func: func: uniform kwargs: - a: 20 - b: 30 + a: 3 + b: 4 hook_callbacks: orders: @@ -40,12 +40,16 @@ levels: callback_class_kwargs: time_dependence_func: !!python/name:cooperative_cuisine.scores.stepped_score '' time_dependence_kwargs: - score_ratios: [ 0.4, 0.8, 1 ] - steps: [ 0, 0.33, 0.66 ] + score_ratios: [ 0.5, 1, 1 ] + steps: [ 0, 0.25, 0.66 ] round_decimals: 0 - static_score: 100 + static_score: 10 score_on_specific_kwarg: meal_name - score_map: [ ] + score_map: + Burger: 40 + Salad: 30 + OnionSoup: 20 + TomatoSoup: 10 - config_path: CONFIGS_DIR/environment_config.yaml layout_path: LAYOUTS_DIR/study_layouts/1-4-bottleneck.layout diff --git a/cooperative_cuisine/pygame_2d_vis/drawing.py b/cooperative_cuisine/pygame_2d_vis/drawing.py index c416278e8fcc0259bdef231b5db85ab01f42614b..924841d549fad898988193fe277a4a97a0e4f8ad 100644 --- a/cooperative_cuisine/pygame_2d_vis/drawing.py +++ b/cooperative_cuisine/pygame_2d_vis/drawing.py @@ -97,6 +97,7 @@ class Visualizer: if "Gui" in config and "show_counter_centers" in config["Gui"] else False ) + self.font = pygame.font.SysFont("Arial", 26) def create_player_colors(self, n) -> None: """Create different colors for the players. The color hues are sampled uniformly in HSV-Space, @@ -822,11 +823,7 @@ class Visualizer: config: Visualization configuration (loaded from yaml file) given as a dict. """ - orders_width = width - 100 orders_height = height - # order_screen = pygame.Surface( - # (orders_width, orders_height), - # ) bg_color = colors[config["GameWindow"]["background_color"]] pygame.draw.rect(screen, bg_color, screen.get_rect()) @@ -879,6 +876,11 @@ class Visualizer: attention=percentage < 0.25, ) + self.font.set_bold(True) + + text_surface = self.font.render(str(order["score"]), True, (0, 0, 0)) + screen.blit(text_surface, center) + def save_state_image( self, grid_size: int, state: dict, filename: str | Path ) -> None: diff --git a/cooperative_cuisine/pygame_2d_vis/gui.py b/cooperative_cuisine/pygame_2d_vis/gui.py index a245e5fe375920e17e1ac4df1798441961568662..735505e3713df64a5fef5957e280973a74ef355f 100644 --- a/cooperative_cuisine/pygame_2d_vis/gui.py +++ b/cooperative_cuisine/pygame_2d_vis/gui.py @@ -1441,7 +1441,7 @@ class PyGameGUI: if self.switch_score_color: self.count_frames_score_label += 1 - duration_color_change = 90 + duration_color_change = 60 if score > self.last_score: self.score_label.update_theming( '{"colours": {"normal_text": "#03b706"}, "font": { "size": 20, "bold": 1}}' @@ -1554,15 +1554,16 @@ class PyGameGUI: "translations.level_name", text_kwargs={"level": self.level_info["name"]} ) - graph_width = self.window_width * 0.6 rows = 0 for rg in self.level_info["recipe_graphs"]: rows += len(np.unique(np.array(list(rg["layout"].values()))[:, 1])) row_height = self.window_height / 14 - container_width = self.window_width * 0.9 + container_width = self.window_width * 0.98 container_height = rows * row_height icon_size = row_height * 0.9 + graph_width = container_width * 0.55 + main_container = pygame_gui.elements.UIPanel( relative_rect=pygame.Rect( (0, 0), @@ -1584,9 +1585,6 @@ class PyGameGUI: positions = np.array(list(rg["layout"].values())) - unique_x_vals = np.unique(positions[:, 0]) - - height = row_height * len(np.unique(positions[:, 1])) graph_height = height * 0.9 @@ -1622,7 +1620,7 @@ class PyGameGUI: rect = pygame.Rect( (0, 0), - (self.window_width / 5, height), + (self.window_width / 6, height), ) label = pygame_gui.elements.UILabel( text=f"translations.{meal}", @@ -1634,17 +1632,33 @@ class PyGameGUI: ) rect = graph_surface.get_rect() - rect.right = 0 graph_image = pygame_gui.elements.UIImage( relative_rect=rect, image_surface=graph_surface, manager=self.manager, object_id="#recipe_graph", container=container, - anchors={"centery": "centery", "right": "right"}, + anchors={"center": "center"}, ) last_recipes_labels.append(container) + rect = pygame.Rect( + (0, 0), + (self.window_width / 6, height), + ) + rect.right = 0 + recipe_score_label = pygame_gui.elements.UILabel( + text="", + relative_rect=rect, + manager=self.manager, + container=container, + object_id="#recipe_name", + anchors={"centery": "centery", "right": "right"}, + ) + recipe_score_label.set_text( + "translations.recipe_score", text_kwargs={"score": str(rg["score"])} + ) + self.scroll_space_recipes.set_scrollable_area_dimensions( (self.window_width * 0.95, container_height) ) diff --git a/cooperative_cuisine/pygame_2d_vis/gui_theme.json b/cooperative_cuisine/pygame_2d_vis/gui_theme.json index 5ceaf4397e562c1e82e53566b5f09e91598e41f9..153f1ad88332218811b1f0e164c0564512429593 100644 --- a/cooperative_cuisine/pygame_2d_vis/gui_theme.json +++ b/cooperative_cuisine/pygame_2d_vis/gui_theme.json @@ -64,7 +64,7 @@ "normal_text": "#000000" }, "font": { - "size": 20, + "size": 24, "bold": 1 } }, diff --git a/cooperative_cuisine/pygame_2d_vis/locales/translations.de.json b/cooperative_cuisine/pygame_2d_vis/locales/translations.de.json index 47579ce8519b642e48e78611225d37e7e037fdfd..4b417c16b808c02e81bcdf6ee3f9fa9b6180080f 100644 --- a/cooperative_cuisine/pygame_2d_vis/locales/translations.de.json +++ b/cooperative_cuisine/pygame_2d_vis/locales/translations.de.json @@ -32,9 +32,10 @@ "Burger": "Burger:", "Pizza": "Pizza:", "Fish And Chips": "Fish and Chips:", - "Chips": "Pommes", + "Chips": "Pommes:", "Salad": "Salat:", "Fried Fish": "Backfisch:", - "Burger With Chips": "Burger mit Pommes:" + "Burger With Chips": "Burger mit Pommes:", + "recipe_score": "Punkte: %{score}" } } \ No newline at end of file diff --git a/cooperative_cuisine/pygame_2d_vis/locales/translations.en.json b/cooperative_cuisine/pygame_2d_vis/locales/translations.en.json index 9f9c558bf762d3db59f73aacd127e71d19491853..d2290d1fd2747ccd98ef973045f2255d72d2dc6c 100644 --- a/cooperative_cuisine/pygame_2d_vis/locales/translations.en.json +++ b/cooperative_cuisine/pygame_2d_vis/locales/translations.en.json @@ -35,6 +35,7 @@ "Chips": "Chips", "Salad": "Salad:", "Fried Fish": "Fried Fish:", - "Burger With Chips": "Burger with Chips:" + "Burger With Chips": "Burger with Chips:", + "recipe_score": "Points: %{score}" } } \ No newline at end of file diff --git a/cooperative_cuisine/validation.py b/cooperative_cuisine/validation.py index cea549750ef51f2cbfc6b323cd8a3c6d14fb3eca..5bc7aaa02b3ebd2bc3ec18583a7ff76e9c34f334 100644 --- a/cooperative_cuisine/validation.py +++ b/cooperative_cuisine/validation.py @@ -4,6 +4,7 @@ import json import os import uuid import warnings +from datetime import datetime, timedelta from typing import TypedDict, Tuple, Iterator, Set import networkx as nx @@ -17,8 +18,9 @@ from cooperative_cuisine.counters import ( PlateDispenser, Counter, ) +from cooperative_cuisine.hooks import COMPLETED_ORDER from cooperative_cuisine.items import ItemInfo, ItemType, Item -from cooperative_cuisine.orders import OrderManager +from cooperative_cuisine.orders import OrderManager, Order class MealGraphDict(TypedDict): @@ -30,6 +32,8 @@ class MealGraphDict(TypedDict): """A list of tuples representing the edges between cooking steps.""" layout: dict[str, Tuple[float, float]] """A dictionary mapping cooking step names to their layout coordinates.""" + score: float + """The max possible score of the meal.""" class Validation: @@ -161,6 +165,23 @@ class Validation: current, ) + dummy_order = Order(meal, datetime.now(), timedelta(seconds=1)) + score = sum( + [ + sc.get_score( + COMPLETED_ORDER, + **{ + "meal": dummy_order.meal, + "order": dummy_order, + "relative_order_time": timedelta(seconds=0), + "remaining_time_ratio": 1.0, + "meal_name": dummy_order.meal.name, + }, + )[0] + for sc in self.order_manager.score_callbacks + ] + ) + before_hash = "".join(sorted(str(sorted([sorted(i) for i in graph.edges])))) h = hashlib.new("sha1") h.update(before_hash.encode()) @@ -186,6 +207,7 @@ class Validation: "meal": meal.name, "edges": list(graph.edges), "layout": layout, + "score": score, } with open(generated_graph_layouts_path, "w") as f: self.recipe_graph_dicts[graph_hash] = graph_dict