Skip to content
Snippets Groups Projects
Commit cab15964 authored by Dominik Battefeld's avatar Dominik Battefeld
Browse files

Merge branch 'main' into 51-add-recipe-yaml-check-visualize-recipes

# Conflicts:
#	setup.py
parents d4e8825a 056e5646
No related branches found
No related tags found
1 merge request!19Resolve "Add recipe yaml check + visualize recipes"
Showing
with 817 additions and 67 deletions
counter_side_length: 40
world_width: 800
world_height: 600
plates:
clean_plates: 3
dirty_plates: 2
......
_________________
_#QU#TNLB#_______
_#_______M_______
_#_______#_______
_W_______________
_#__A__A_________
_C_______________
_C_______#_______
_#_______X_______
_#P#S+#S+#_______
_________________
#QU#TNLB#
#_______M
#_______#
W________
#__A__A__
C________
C_______#
#_______X
#P#S+#S+#
\ No newline at end of file
_____
_____
____P
\ No newline at end of file
____P
radius: 0.4
move_dist: 5
move_dist: 0.12
interaction_range: 1.6
\ No newline at end of file
{
"defaults": {
"colours": {
"normal_bg": "#45494e",
"hovered_bg": "#35393e",
"disabled_bg": "#25292e",
"selected_bg": "#193754",
"dark_bg": "#15191e",
"normal_text": "#c5cbd8",
"hovered_text": "#FFFFFF",
"selected_text": "#FFFFFF",
"disabled_text": "#6d736f",
"link_text": "#0000EE",
"link_hover": "#2020FF",
"link_selected": "#551A8B",
"text_shadow": "#777777",
"normal_border": "#DDDDDD",
"hovered_border": "#B0B0B0",
"disabled_border": "#808080",
"selected_border": "#8080B0",
"active_border": "#8080B0",
"filled_bar": "#f4251b",
"unfilled_bar": "#CCCCCC"
}
},
"button": {
"colours": {
"normal_bg": "#45494e",
"hovered_bg": "#35393e",
"disabled_bg": "#25292e",
"selected_bg": "#193754",
"active_bg": "#193754",
"dark_bg": "#15191e",
"normal_text": "#c5cbd8",
"hovered_text": "#FFFFFF",
"selected_text": "#FFFFFF",
"disabled_text": "#6d736f",
"active_text": "#FFFFFF",
"normal_border": "#DDDDDD",
"hovered_border": "#B0B0B0",
"disabled_border": "#808080",
"selected_border": "#8080B0",
"active_border": "#8080B0"
},
"misc": {
"tool_tip_delay": "1.5"
}
}
}
\ No newline at end of file
# colors: https://www.webucator.com/article/python-color-constants-module/
GameWindow:
WhatIsFixed: window_width # entweder grid oder window_width
size: 500
screen_margin: 100
Kitchen:
ground_tiles_color: sgigray76
background_lines: gray79
......@@ -172,11 +177,11 @@ ChoppedLettuce:
- type: circle
radius: 0.3
color: black
center_offset: [ -5, 0 ]
center_offset: [ -0.125, 0 ]
- type: circle
radius: 0.25
color: emeraldgreen
center_offset: [ -5, 0 ]
center_offset: [ -0.125, 0 ]
- type: circle
radius: 0.3
color: black
......@@ -186,11 +191,11 @@ ChoppedLettuce:
- type: circle
radius: 0.3
color: black
center_offset: [ 5, 0 ]
center_offset: [ 0.125, 0 ]
- type: circle
radius: 0.25
color: emeraldgreen
center_offset: [ 5, 0 ]
center_offset: [ 0.125, 0 ]
ChoppedTomato:
parts:
......@@ -203,11 +208,11 @@ ChoppedOnion:
- type: circle
radius: 0.3
color: black
center_offset: [ -5, 0 ]
center_offset: [ -0.125, 0 ]
- type: circle
radius: 0.25
color: deeppink4
center_offset: [ -5, 0 ]
center_offset: [ -0.125, 0 ]
- type: circle
radius: 0.3
color: black
......@@ -217,22 +222,22 @@ ChoppedOnion:
- type: circle
radius: 0.3
color: black
center_offset: [ 5, 0 ]
center_offset: [ 0.125, 0 ]
- type: circle
radius: 0.25
color: deeppink4
center_offset: [ 5, 0 ]
center_offset: [ 0.125, 0 ]
ChoppedMeat:
parts:
- type: circle
radius: 0.3
color: black
center_offset: [ -5, 0 ]
center_offset: [ -0.125, 0 ]
- type: circle
radius: 0.25
color: indianred1
center_offset: [ -5, 0 ]
center_offset: [ -0.125, 0 ]
- type: circle
radius: 0.3
color: black
......
......@@ -7,7 +7,7 @@ from datetime import datetime
import pygame
from overcooked_simulator import ROOT_DIR
from overcooked_simulator.pygame_gui.pygame_gui import PyGameGUI
from overcooked_simulator.gui_2d_vis.overcooked_gui import PyGameGUI
from overcooked_simulator.simulation_runner import Simulator
log = logging.getLogger(__name__)
......@@ -51,12 +51,9 @@ def main():
pygame.K_i,
]
keys2 = [pygame.K_a, pygame.K_d, pygame.K_w, pygame.K_s, pygame.K_f, pygame.K_e]
gui = PyGameGUI(simulator, [f"p{i}" for i in range(number_player)], [keys1, keys2])
simulator.start()
gui = PyGameGUI(simulator, [f"p{i}" for i in range(number_player)], [keys1, keys2])
gui.start_pygame()
simulator.stop()
sys.exit()
......
......@@ -82,7 +82,7 @@ class Environment:
with open(env_config_path, "r") as file:
environment_config = yaml.safe_load(file)
self.layout_path: Path = layout_path
self.counter_side_length = environment_config["counter_side_length"]
# self.counter_side_length = 1 # -> this changed! is 1 now
self.item_info_path: Path = item_info_path
self.item_info = self.load_item_info()
......@@ -118,6 +118,9 @@ class Environment:
"+": SinkAddon,
}
self.kitchen_height: int = 0
self.kitchen_width: int = 0
(
self.counters,
self.designated_player_positions,
......@@ -128,9 +131,6 @@ class Environment:
self.score: int = 0
self.world_width: int = environment_config["world_width"]
self.world_height: int = environment_config["world_height"]
def load_item_info(self) -> dict[str, ItemInfo]:
with open(self.item_info_path, "r") as file:
item_lookup = yaml.safe_load(file)
......@@ -156,16 +156,20 @@ class Environment:
Args:
layout_file: Path to the layout file.
"""
current_y: float = self.counter_side_length / 2
current_y: float = 1.5
counters: list[Counter] = []
designated_player_positions: list[npt.NDArray] = []
free_positions: list[npt.NDArray] = []
self.kitchen_width = 0
with open(layout_file, "r") as layout_file:
lines = layout_file.readlines()
self.kitchen_height = len(lines)
for line in lines:
line = line.replace("\n", "").replace(" ", "") # remove newline char
current_x = self.counter_side_length / 2
current_x = 1.5
for character in line:
character = character.capitalize()
pos = np.array([current_x, current_y])
......@@ -180,8 +184,13 @@ class Environment:
)
elif counter_class == "Free":
free_positions.append(np.array([current_x, current_y]))
current_x += self.counter_side_length
current_y += self.counter_side_length
current_x += 1
if current_x > self.kitchen_width:
self.kitchen_width = current_x
current_y += 1
self.kitchen_height = int(self.kitchen_height + 2.5)
self.kitchen_width = int(self.kitchen_width + 0.5)
return counters, designated_player_positions, free_positions
......@@ -331,9 +340,7 @@ class Environment:
other_players = filter(lambda p: p.name != player.name, self.players.values())
def collide(p):
return np.linalg.norm(player.pos - p.pos) <= (
player.radius * self.counter_side_length
) + (p.radius * self.counter_side_length)
return np.linalg.norm(player.pos - p.pos) <= (player.radius) + (p.radius)
return list(filter(collide, other_players))
......@@ -351,10 +358,7 @@ class Environment:
other_players = filter(lambda p: p.name != player.name, self.players.values())
def collide(p):
return np.linalg.norm(player.pos - p.pos) <= (
(player.radius * self.counter_side_length)
+ (p.radius * self.counter_side_length)
)
return np.linalg.norm(player.pos - p.pos) <= ((player.radius) + (p.radius))
return any(map(collide, other_players))
......@@ -388,16 +392,15 @@ class Environment:
Returns: True if player and counter overlap, False if not.
"""
size = self.counter_side_length
cx, cy = player.pos
dx = max(np.abs(cx - counter.pos[0]) - size / 2, 0)
dy = max(np.abs(cy - counter.pos[1]) - size / 2, 0)
dx = max(np.abs(cx - counter.pos[0]) - 1 / 2, 0)
dy = max(np.abs(cy - counter.pos[1]) - 1 / 2, 0)
distance = np.linalg.norm([dx, dy])
return distance < (player.radius * self.counter_side_length)
return distance < (player.radius)
def add_player(self, player_name: str, pos: npt.NDArray = None):
log.debug(f"Add player {player_name} to the game")
player = Player(player_name, self.counter_side_length, pos)
player = Player(player_name, pos)
self.players[player.name] = player
if player.pos is None:
if len(self.designated_player_positions) > 0:
......@@ -420,12 +423,9 @@ class Environment:
Returns: True if the player touches the world bounds, False if not.
"""
collisions_lower = any(
(player.pos - (player.radius * self.counter_side_length)) < 0
)
collisions_lower = any((player.pos - (player.radius)) < 0)
collisions_upper = any(
(player.pos + (player.radius * self.counter_side_length))
> [self.world_width, self.world_height]
(player.pos + (player.radius)) > [self.kitchen_width, self.kitchen_height]
)
return collisions_lower or collisions_upper
......@@ -467,9 +467,7 @@ class Environment:
case Sink(pos=pos):
assert len(sink_addons) > 0, "No SinkAddon but normal Sink"
closest_addon = self.get_closest(pos, sink_addons)
assert self.counter_side_length - (
self.counter_side_length * 0.05
) <= np.linalg.norm(
assert 1 - (1 * 0.05) <= np.linalg.norm(
closest_addon.pos - pos
), f"No SinkAddon connected to Sink at pos {pos}"
counter.set_addon(closest_addon)
......
......@@ -24,7 +24,6 @@ class Player:
def __init__(
self,
name: str,
grid_size: int,
pos: Optional[npt.NDArray[float]] = None,
):
self.name: str = name
......@@ -42,7 +41,6 @@ class Player:
self.player_config = yaml.safe_load(file)
self.radius: float = self.player_config["radius"]
self.grid_size: int = grid_size
self.move_dist: int = self.player_config["move_dist"]
self.interaction_range: int = self.player_config["interaction_range"]
self.facing_direction: npt.NDArray[float] = np.array([0, 1])
......@@ -85,9 +83,7 @@ class Player:
self.update_facing_point()
def update_facing_point(self):
self.facing_point = self.pos + (
self.facing_direction * self.radius * self.grid_size * 0.5
)
self.facing_point = self.pos + (self.facing_direction * self.radius * 0.5)
def can_reach(self, counter: Counter):
"""Checks whether the player can reach the counter in question. Simple check if the distance is not larger
......@@ -99,9 +95,7 @@ class Player:
Returns: True if the counter is in range of the player, False if not.
"""
return np.linalg.norm(counter.pos - self.facing_point) <= (
self.interaction_range * self.grid_size
)
return np.linalg.norm(counter.pos - self.facing_point) <= self.interaction_range
def pick_action(self, counter: Counter):
"""Performs the pickup-action with the counter. Handles the logic of what the player is currently holding,
......
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