Skip to content
Snippets Groups Projects
Commit 0ca93147 authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Added GameScore class to keep track of game score. Currently just by serving...

Added GameScore class to keep track of game score. Currently just by serving things in the serving window
parent 636263c2
No related branches found
No related tags found
1 merge request!8Resolve "Can put tomatos on returned plate"
Pipeline #41467 passed
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from overcooked_simulator.overcooked_environment import GameScore
from typing import Optional from typing import Optional
import numpy as np import numpy as np
...@@ -99,8 +105,13 @@ class CuttingBoard(Counter): ...@@ -99,8 +105,13 @@ class CuttingBoard(Counter):
class ServingWindow(Counter): class ServingWindow(Counter):
def __init__(self, pos, gamescore: GameScore):
self.game_score = gamescore
super().__init__(pos)
def drop_off(self, item): def drop_off(self, item):
return 5 reward = 5
self.game_score.increment_score(reward)
def can_score(self, item): def can_score(self, item):
if isinstance(item, Plate) and isinstance(item.holds, ProgressibleItem): if isinstance(item, Plate) and isinstance(item.holds, ProgressibleItem):
...@@ -151,7 +162,7 @@ class PlateReturn(Counter): ...@@ -151,7 +162,7 @@ class PlateReturn(Counter):
""" """
# possibility to drop off empty plate on empty plate return # possibility to drop off empty plate on empty plate return
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) ) or self.occupied_by.can_combine(item)
def __repr__(self): def __repr__(self):
......
...@@ -11,20 +11,22 @@ from overcooked_simulator.counters import ( ...@@ -11,20 +11,22 @@ from overcooked_simulator.counters import (
Counter, Counter,
CuttingBoard, CuttingBoard,
Trash, Trash,
ServingWindow,
TomatoDispenser, TomatoDispenser,
ServingWindow,
PlateReturn, PlateReturn,
) )
SYMBOL_TO_CHARACTER_MAP = {
"C": Counter, class GameScore:
"B": CuttingBoard, def __init__(self):
"X": Trash, self.score = 0
"W": ServingWindow,
"T": TomatoDispenser, def increment_score(self, score: int):
"P": PlateReturn, self.score += score
"E": None, print(self.score)
}
def read_score(self):
return self.score
class Action: class Action:
...@@ -55,6 +57,18 @@ class Environment: ...@@ -55,6 +57,18 @@ class Environment:
self.players: dict[str, Player] = {} self.players: dict[str, Player] = {}
self.counter_side_length: float = 40 self.counter_side_length: float = 40
self.layout_path: Path = layout_path 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.counters: list[Counter] = self.create_counters(self.layout_path)
self.score: int = 0 self.score: int = 0
self.world_width: int = 800 self.world_width: int = 800
...@@ -80,7 +94,7 @@ class Environment: ...@@ -80,7 +94,7 @@ class Environment:
for character in line: for character in line:
character = character.capitalize() character = character.capitalize()
pos = np.array([current_x, current_y]) 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: if counter_class is not None:
counter = counter_class(pos) counter = counter_class(pos)
counters.append(counter) counters.append(counter)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment