diff --git a/overcooked_simulator/counters.py b/overcooked_simulator/counters.py index 28265ccdb1030c8e6608f7e059cb37c1391aa626..d83dc162d871abe60efb3a3578d13dffa42b733f 100644 --- a/overcooked_simulator/counters.py +++ b/overcooked_simulator/counters.py @@ -1,3 +1,9 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from overcooked_simulator.overcooked_environment import GameScore from typing import Optional import numpy as np @@ -99,8 +105,13 @@ class CuttingBoard(Counter): class ServingWindow(Counter): + def __init__(self, pos, gamescore: GameScore): + self.game_score = gamescore + super().__init__(pos) + def drop_off(self, item): - return 5 + reward = 5 + self.game_score.increment_score(reward) def can_score(self, item): if isinstance(item, Plate) and isinstance(item.holds, ProgressibleItem): @@ -151,7 +162,7 @@ class PlateReturn(Counter): """ # possibility to drop off empty plate on empty plate return return ( - isinstance(self.occupied_by, Plate) and isinstance(item, Plate) + isinstance(self.occupied_by, Plate) and isinstance(item, Plate) ) or self.occupied_by.can_combine(item) def __repr__(self): diff --git a/overcooked_simulator/overcooked_environment.py b/overcooked_simulator/overcooked_environment.py index 8245fafabcba77786f4b940edea04bfe8bc55224..08a40bdeb6cf0a965e1afde47eb4f36e0057cb1d 100644 --- a/overcooked_simulator/overcooked_environment.py +++ b/overcooked_simulator/overcooked_environment.py @@ -11,20 +11,22 @@ from overcooked_simulator.counters import ( Counter, CuttingBoard, Trash, - ServingWindow, TomatoDispenser, + ServingWindow, PlateReturn, ) -SYMBOL_TO_CHARACTER_MAP = { - "C": Counter, - "B": CuttingBoard, - "X": Trash, - "W": ServingWindow, - "T": TomatoDispenser, - "P": PlateReturn, - "E": None, -} + +class GameScore: + def __init__(self): + self.score = 0 + + def increment_score(self, score: int): + self.score += score + print(self.score) + + def read_score(self): + return self.score class Action: @@ -55,6 +57,18 @@ class Environment: self.players: dict[str, Player] = {} self.counter_side_length: float = 40 self.layout_path: Path = layout_path + + self.game_score = GameScore() + self.SYMBOL_TO_CHARACTER_MAP = { + "C": Counter, + "B": CuttingBoard, + "X": Trash, + "W": lambda pos: ServingWindow(pos, self.game_score), + "T": TomatoDispenser, + "P": PlateReturn, + "E": None, + } + self.counters: list[Counter] = self.create_counters(self.layout_path) self.score: int = 0 self.world_width: int = 800 @@ -80,7 +94,7 @@ class Environment: for character in line: character = character.capitalize() pos = np.array([current_x, current_y]) - counter_class = SYMBOL_TO_CHARACTER_MAP[character] + counter_class = self.SYMBOL_TO_CHARACTER_MAP[character] if counter_class is not None: counter = counter_class(pos) counters.append(counter)