diff --git a/overcooked_simulator/game_content/environment_config.yaml b/overcooked_simulator/game_content/environment_config.yaml index 158a22290759fa0415806ee59ce968972e07029c..48d23d2e04986bd323947612637602ae3d1e824f 100644 --- a/overcooked_simulator/game_content/environment_config.yaml +++ b/overcooked_simulator/game_content/environment_config.yaml @@ -1,4 +1,7 @@ plates: clean_plates: 3 dirty_plates: 2 - plate_delay: [ 5, 10 ] \ No newline at end of file + plate_delay: [ 5, 10 ] + +game: + time_limit_seconds: 10.0 diff --git a/overcooked_simulator/gui_2d_vis/overcooked_gui.py b/overcooked_simulator/gui_2d_vis/overcooked_gui.py index 999eccfce5ca9f4e004b9e52165620d98851aac2..33990634078c106cd9d2a89bf94b25a84706fdc5 100644 --- a/overcooked_simulator/gui_2d_vis/overcooked_gui.py +++ b/overcooked_simulator/gui_2d_vis/overcooked_gui.py @@ -163,7 +163,7 @@ class PyGameGUI: game_height + (2 * self.screen_margin), ) - return window_width, window_height, game_width, game_height, grid_size + return int(window_width), int(window_height), game_width, game_height, grid_size def create_player_colors(self) -> list[Color]: number_player = len(self.simulator.env.players) @@ -735,6 +735,9 @@ class PyGameGUI: self.handle_keys() state = self.simulator.get_state() + if state["ended"]: + self.finished_button_press() + self.manage_button_visibility() self.draw(state) game_screen_rect = self.game_screen.get_rect() diff --git a/overcooked_simulator/gui_2d_vis/visualization.yaml b/overcooked_simulator/gui_2d_vis/visualization.yaml index b4bfdc008c673b2d8042572dac05d5469a52af6a..a1381661f63f54340c1958142277e50401197309 100644 --- a/overcooked_simulator/gui_2d_vis/visualization.yaml +++ b/overcooked_simulator/gui_2d_vis/visualization.yaml @@ -1,8 +1,8 @@ # colors: https://www.webucator.com/article/python-color-constants-module/ GameWindow: - WhatIsFixed: window_height # entweder grid oder window_width - size: 500 + WhatIsFixed: grid # grid or window_width or window_height + size: 40 screen_margin: 100 start_width: 600 start_height: 600 diff --git a/overcooked_simulator/overcooked_environment.py b/overcooked_simulator/overcooked_environment.py index 8f5adf962fed07d207ac034821c4978edb3a3d47..64ad2252ea6d532e3df8c47b48234b569cf40c1c 100644 --- a/overcooked_simulator/overcooked_environment.py +++ b/overcooked_simulator/overcooked_environment.py @@ -134,6 +134,14 @@ class Environment: self.score: int = 0 self.env_time = create_init_env_time() + self.env_time_end = self.env_time + timedelta( + seconds=environment_config["game"]["time_limit_seconds"] + ) + log.debug(f"End time: {self.env_time_end}") + + @property + def game_ended(self) -> bool: + return self.env_time >= self.env_time_end def load_item_info(self) -> dict[str, ItemInfo]: with open(self.item_info_path, "r") as file: @@ -437,6 +445,7 @@ class Environment: and time limits. """ self.env_time += passed_time + with self.lock: for counter in self.counters: if isinstance(counter, (CuttingBoard, Stove, Sink, PlateDispenser)): @@ -448,7 +457,12 @@ class Environment: Returns: Dict of lists of the current relevant game objects. """ - return {"players": self.players, "counters": self.counters, "score": self.score} + return { + "players": self.players, + "counters": self.counters, + "score": self.score, + "ended": self.game_ended, + } def get_state_json(self): """Get the current state of the game environment as a json-like nested dictionary. diff --git a/overcooked_simulator/simulation_runner.py b/overcooked_simulator/simulation_runner.py index 8ad41e28ae7bb2834297cadeaa2d06f915e1c87a..f0a6e9c8667ffd5f68338f407f8546cf1419195d 100644 --- a/overcooked_simulator/simulation_runner.py +++ b/overcooked_simulator/simulation_runner.py @@ -98,9 +98,11 @@ class Simulator(Thread): overslept_in_ns = 0 self.env.reset_env_time() + last_step_start = time.time_ns() while not self.finished: step_start = time.time_ns() - self.step(timedelta(seconds=overslept_in_ns / 1_000_000_000)) + self.step(timedelta(seconds=(step_start - last_step_start) / 1_000_000_000)) + last_step_start = step_start step_duration = time.time_ns() - step_start time_to_sleep_ns = self.preferred_sleep_time_ns - (