Skip to content
Snippets Groups Projects
Commit 0aaf03dc authored by Florian Schröder's avatar Florian Schröder
Browse files

Refactor and centralize configuration classes

The EnvironmentConfig and OrderConfig classes, previously defined in the utils.py file, were moved to their respective modules overcooked_environment.py and order.py. This change creates a central location for configuration and reduces unnecessary dependencies in the utils.py file.
parent aff6a0e5
No related branches found
No related tags found
1 merge request!37Resolve "Type hint class for environment config"
Pipeline #45335 passed
......@@ -51,7 +51,7 @@ import uuid
from abc import abstractmethod
from collections import deque
from datetime import datetime, timedelta
from typing import Callable, Tuple, Any, Deque, Protocol, TypedDict
from typing import Callable, Tuple, Any, Deque, Protocol, TypedDict, Type
from overcooked_simulator.game_items import Item, Plate, ItemInfo
......@@ -62,6 +62,17 @@ ORDER_CATEGORY = "Order"
"""The string for the `category` value in the json state representation for all orders."""
class OrderConfig(TypedDict):
"""The configuration of the order in the `environment_config`under the `order` key."""
order_gen_class: Type[OrderGeneration]
"""The class that should handle the order generation."""
order_gen_kwargs: dict[str, Any]
"""The additional kwargs for the order gen class."""
serving_not_ordered_meals: Callable[[Item], Tuple[bool, float]]
""""""
@dataclasses.dataclass
class Order:
"""Datawrapper for Orders"""
......
......@@ -9,7 +9,7 @@ import sys
from datetime import timedelta, datetime
from enum import Enum
from pathlib import Path
from typing import Literal
from typing import Literal, TypedDict
import numpy as np
import numpy.typing as npt
......@@ -24,7 +24,10 @@ from overcooked_simulator.game_items import (
ItemInfo,
ItemType,
)
from overcooked_simulator.order import OrderAndScoreManager
from overcooked_simulator.order import (
OrderAndScoreManager,
OrderConfig,
)
from overcooked_simulator.player import Player, PlayerConfig
from overcooked_simulator.state_representation import StateRepresentation
from overcooked_simulator.utils import create_init_env_time, get_closest
......@@ -79,6 +82,15 @@ class Action:
# TODO Abstract base class for different environments
class EnvironmentConfig(TypedDict):
plates: PlateConfig
game: dict[Literal["time_limit_seconds"], int]
meals: dict[Literal["all"] | Literal["list"], bool | list[str]]
orders: OrderConfig
player_config: PlayerConfig
layout_chars: dict[str, str]
class Environment:
"""Environment class which handles the game logic for the overcooked-inspired environment.
......@@ -101,9 +113,13 @@ class Environment:
"""Are the configs just the path to the files."""
if self.as_files:
with open(env_config, "r") as file:
self.environment_config = yaml.load(file, Loader=yaml.Loader)
self.environment_config: EnvironmentConfig = yaml.load(
file, Loader=yaml.Loader
)
else:
self.environment_config = yaml.load(env_config, Loader=yaml.Loader)
self.environment_config: EnvironmentConfig = yaml.load(
env_config, Loader=yaml.Loader
)
self.layout_config = layout_config
"""The layout config for the environment"""
# self.counter_side_length = 1 # -> this changed! is 1 now
......
......@@ -8,31 +8,13 @@ import sys
import uuid
from datetime import datetime
from enum import Enum
from typing import TypedDict, Literal, Type, Any, Callable, Tuple
import numpy as np
import numpy.typing as npt
from scipy.spatial import distance_matrix
from overcooked_simulator import ROOT_DIR
from overcooked_simulator.counters import PlateConfig, Counter
from overcooked_simulator.game_items import Item
from overcooked_simulator.order import OrderGeneration
from overcooked_simulator.player import PlayerConfig
class OrderConfig(TypedDict):
order_gen_class: Type[OrderGeneration]
order_gen_kwargs: dict[str, Any]
serving_not_ordered_meals: Callable[[Item], Tuple[bool, float]]
class EnvironmentConfig(TypedDict):
plates: PlateConfig
game: dict[Literal["time_limit_seconds"], int]
meals: dict[Literal["all"] | Literal["list"], bool | list[str]]
orders: OrderConfig
player_config: PlayerConfig
from overcooked_simulator.counters import Counter
def create_init_env_time():
......
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