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

Merge remote-tracking branch 'origin/main' into 79-info-screens-pop-ups-etc

# Conflicts:
#	overcooked_simulator/gui_2d_vis/overcooked_gui.py
parents ec29d41c 038000bf
No related branches found
No related tags found
1 merge request!53Resolve "Info screens (pop ups etc)"
Pipeline #46130 passed
Showing
with 420 additions and 11 deletions
......@@ -81,10 +81,10 @@ def convert_words_to_chars(layout_chars_config: dict[str, str]) -> dict[str, str
"""
word_refs = {
"hash": "#",
"space": " ",
# "space": " ",
"dot": ".",
"comma": ",",
"semicolon": ";",
# "semicolon": ";",
"colon": ":",
"minus": "-",
"exclamation": "!",
......@@ -98,6 +98,7 @@ def convert_words_to_chars(layout_chars_config: dict[str, str]) -> dict[str, str
"left": "<",
"pipe": "|",
"at": "@",
"wave": "~", # ~ is None / null in yaml
"ocurlybracket": "{",
"ccurlybracket": "}",
"osquarebracket": "[",
......@@ -163,8 +164,11 @@ class CounterFactory:
"""A set of characters that represent counters for agents or free spaces."""
self.counter_classes: dict[str, Type] = dict(
inspect.getmembers(
sys.modules["overcooked_simulator.counters"], inspect.isclass
filter(
lambda k: issubclass(k[1], Counter),
inspect.getmembers(
sys.modules["overcooked_simulator.counters"], inspect.isclass
),
)
)
"""A dictionary of counter classes imported from the 'overcooked_simulator.counters' module."""
......@@ -191,6 +195,8 @@ class CounterFactory:
assert self.can_map(c), f"Can't map counter char {c}"
counter_class = None
if c == "@":
print("-")
if self.layout_chars_config[c] in self.item_info:
item_info = self.item_info[self.layout_chars_config[c]]
if item_info.type == ItemType.Equipment and item_info.equipment:
......@@ -221,7 +227,20 @@ class CounterFactory:
)
if counter_class is None:
counter_class = self.counter_classes[self.layout_chars_config[c]]
if self.layout_chars_config[c] in self.counter_classes:
counter_class = self.counter_classes[self.layout_chars_config[c]]
elif self.layout_chars_config[c] == "Plate":
return Counter(
pos=pos,
hook=self.hook,
occupied_by=Plate(
transitions=self.filter_item_info(
by_item_type=ItemType.Meal, add_effects=True
),
clean=True,
item_info=self.item_info[Plate.__name__],
),
)
kwargs = {
"pos": pos,
"hook": self.hook,
......
......@@ -623,7 +623,7 @@ class Trashcan(Counter):
return None
def can_drop_off(self, item: Item) -> bool:
return True
return item.name != "Extinguisher"
class CookingCounter(Counter):
......
"""
# Usage
- Set `CONNECT_WITH_STUDY_SERVER` in overcooked_gui.py to True.
- Run this script. Copy the manager id that is printed
- Run the game_server.py script with the manager id copied from the terminal
```
python game_server.py --manager_ids COPIED_UUID
```
- Run 2 overcooked_gui.py scripts in different terminals. For more players change `NUMBER_PLAYER_PER_ENV` and start more guis.
The environment starts when all players connected.
"""
import argparse
import asyncio
import logging
from typing import Tuple
import requests
import uvicorn
from fastapi import FastAPI
from overcooked_simulator import ROOT_DIR
from overcooked_simulator.game_server import CreateEnvironmentConfig
from overcooked_simulator.server_results import PlayerInfo
from overcooked_simulator.utils import (
url_and_port_arguments,
add_list_of_manager_ids_arguments,
)
NUMBER_PLAYER_PER_ENV = 2
log = logging.getLogger(__name__)
app = FastAPI()
game_server_url = "localhost:8000"
server_manager_id = None
# @app.get("/")
# async def root(response_class=HTMLResponse):
# return """
# <html>
# <head>
# <title>Overcooked Game</title>
# </head>
# <body>
# <h1>Start Game!</h1>
# <button type="button">Click Me!</button>
# </body>
# </html>
# """
running_envs: dict[str, Tuple[int, dict[str, PlayerInfo], list[str]]] = {}
current_free_envs = []
@app.post("/connect_to_game/{request_id}")
async def want_to_play(request_id: str):
global current_free_envs
# TODO based on study desing / internal state of request id current state (which level to play)
if current_free_envs:
current_free_env = current_free_envs.pop()
running_envs[current_free_env][2].append(request_id)
new_running_env = (
running_envs[current_free_env][0] + 1,
running_envs[current_free_env][1],
running_envs[current_free_env][2],
)
player_info = running_envs[current_free_env][1][str(new_running_env[0])]
running_envs[current_free_env] = new_running_env
if new_running_env[0] < NUMBER_PLAYER_PER_ENV - 1:
current_free_env.append(current_free_env)
return player_info
else:
environment_config_path = ROOT_DIR / "game_content" / "environment_config.yaml"
layout_path = ROOT_DIR / "game_content" / "layouts" / "basic.layout"
item_info_path = ROOT_DIR / "game_content" / "item_info.yaml"
with open(item_info_path, "r") as file:
item_info = file.read()
with open(layout_path, "r") as file:
layout = file.read()
with open(environment_config_path, "r") as file:
environment_config = file.read()
creation_json = CreateEnvironmentConfig(
manager_id=server_manager_id,
number_players=NUMBER_PLAYER_PER_ENV,
environment_settings={"all_player_can_pause_game": False},
item_info_config=item_info,
environment_config=environment_config,
layout_config=layout,
seed=1234567890,
).model_dump(mode="json")
# todo async
env_info = requests.post(
game_server_url + "/manage/create_env/", json=creation_json
)
if env_info.status_code == 403:
raise ValueError(f"Forbidden Request: {env_info.json()['detail']}")
env_info = env_info.json()
print(env_info)
running_envs[env_info["env_id"]] = (0, env_info["player_info"], [request_id])
current_free_envs.append(env_info["env_id"])
return env_info["player_info"]["0"]
def main(host, port, game_server_url_, manager_id):
global game_server_url, server_manager_id
game_server_url = "http://" + game_server_url_
server_manager_id = manager_id[0]
print(f"Use {server_manager_id=} for {game_server_url=}")
loop = asyncio.new_event_loop()
config = uvicorn.Config(app, host=host, port=port, loop=loop)
server = uvicorn.Server(config)
loop.run_until_complete(server.serve())
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="Overcooked Simulator Study Server",
description="Study Server: Match Making, client pre and post managing.",
epilog="For further information, see https://scs.pages.ub.uni-bielefeld.de/cocosy/overcooked-simulator/overcooked_simulator.html",
)
url_and_port_arguments(parser=parser, server_name="Study Server", default_port=8080)
add_list_of_manager_ids_arguments(parser=parser)
args = parser.parse_args()
main(
args.url,
args.port,
game_server_url_="localhost:8000",
manager_id=args.manager_ids,
)
......@@ -18,15 +18,16 @@ meals:
layout_chars:
_: Free
hash: Counter
hash: Counter # #
A: Agent
pipe: Extinguisher
P: PlateDispenser
C: CuttingBoard
X: Trashcan
W: ServingWindow
$: ServingWindow
S: Sink
+: SinkAddon
at: Plate # @ just a clean plate on a counter
U: Pot # with Stove
Q: Pan # with Stove
O: Peel # with Oven
......@@ -41,6 +42,15 @@ layout_chars:
G: Sausage # sausaGe
B: Bun
M: Meat
question: Counter # ? mushroom
: Counter
^: Counter
right: Counter
left: Counter
wave: Free # ~ Water
minus: Free # - Ice
dquote: Counter # " wall/truck
p: Counter # second plate return ??
orders:
......@@ -88,7 +98,8 @@ player_config:
player_speed_units_per_seconds: 6
interaction_range: 1.6
restricted_view: False
view_angle: 95
view_angle: 70
view_range: 5.5 # in grid units, can be "null"
effect_manager:
FireManager:
......
#QU#FO#TNLB#
#__________M
|__________K
W__________I
$__________I
#__A_____A_D
C__________E
C__________G
......
......@@ -4,7 +4,7 @@
#____________________________________#
#____________________________________#
#____________________________________K
W____________________________________I
$____________________________________I
#____________________________________#
#____________________________________#
#__A_____A___________________________D
......
#QU#F###O#T#################N###L###B#
#____________________________________#
#____________________________________M
#____________________________________#
#____________________________________#
#____________________________________K
W____________________________________I
#____________________________________#
#____________________________________#
#__A_____A___________________________D
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
C____________________________________E
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
#____________________________________#
C____________________________________G
#____________________________________#
#P#####S+####X#####S+#################
\ No newline at end of file
###N####U####
#___________|
#___A___A___#
#___________S
##########__+
P___________#
$___________#
$___________X
###C#C###@@##
; seconds=150
; plates={c:0, d:0}
; dirty_plates=true
; link: https://overcooked.fandom.com/wiki/1-1_(Overcooked!)
\ No newline at end of file
_##U#U#__###|X_#
______#____A___$
+_____@__@_____$
S________#_____P
____A____#______
_##C#C#__#T#N##_
; seconds=240
; plates={c:0, d:0}
; dirty_plates=true
; link: https://overcooked.fandom.com/wiki/1-2_(Overcooked!)
; pedestrians: down the middle road
_____________
___U#U##$$P|_
_#____#______
_@__A_#___A__
_@____#______
_@____#______
_X____#______
_#C#C##NT?___
_____________
; seconds=240
; plates={c:0, d:0}
; dirty_plates=false
; link: https://overcooked.fandom.com/wiki/1-3_(Overcooked!)
; moving counters
\ No newline at end of file
##S+####QQQQ#
T____###____|
M_A__###__A_#
B___________#
L____###____$
#____###____$
#____###____P
X____###____@
##C#C###@@@@#
; seconds=240
; plates={c:0, d:0}
; dirty_plates=true
; link: https://overcooked.fandom.com/wiki/1-4_(Overcooked!)
\ No newline at end of file
#####P$$|#####
#?NT#A_A_#S+##
#____________X
#_##########_#
#_##########_#
#_##########_#
#_#######@@@_#
#____________#
#C#C####U#U#U#
; seconds=240
; plates={c:0, d:0}
; dirty_plates=true
; link: https://overcooked.fandom.com/wiki/1-5_(Overcooked!)
\ No newline at end of file
##S+###@Q@Q@#
M___________#
T___________|
L___________$
#___________$
#___________P
X___________#
##C#C##Q#Q#B#
; seconds=240
; plates={c:0, d:0}
; dirty_plates=true
; link: https://overcooked.fandom.com/wiki/1-6_(Overcooked!)
; raising platforms based on earthquakes
\ No newline at end of file
_______________
__#QQQ#@@@#____
__#_______$____
__B_______$____
__#_______P____
_______________
__M__A____X____
__L_______#____
__T__A____C____
__#|###C###____
_______________
; seconds=240
; plates={c:0, d:0}
; dirty_plates=false
; link: https://overcooked.fandom.com/wiki/2-1_(Overcooked!)
; moving trucks: counters and ground are moving
\ No newline at end of file
#####P$$|#####
#####____#####
##S+#____#S+##
X____________X
#____________#
U___@__A_@___#
#___@____@___#
#___#_A__#___#
U___#____#___#
#___#____#___#
#?N##C##C##NT#
; seconds=240
; plates={c:0, d:0}
; dirty_plates=true
; link: https://overcooked.fandom.com/wiki/2-2_(Overcooked!)
; rats: steal ingredients + meals
\ No newline at end of file
>>>>>>>>>>>>>>>↓
^#_____##@____#↓
^+A____|#@_A__#↓
^S_____Q#C____$↓
^M_____###____$↓
^L_____Q#C____P↓
^B_____###____#↓
^T_____X#@____X↓
^<<<<<<<<<<<<<<<
; seconds=240
; plates={c:0, d:0}
; dirty_plates=true
; link: https://overcooked.fandom.com/wiki/2-3_(Overcooked!)
; conveyors
\ No newline at end of file
#@@@##C#C######
#_____________$
#___A_________$
#_____________P
####____###___#
X<<<<<<X>>>>>>X
#___###____####
Q_____________#
#________A____#
Q_____________#
##Q#+S#|##BTLM#
; seconds=240
; plates={c:0, d:0}
; dirty_plates=true
; link: https://overcooked.fandom.com/wiki/2-4_(Overcooked!)
\ No newline at end of file
~~~~~~~~~~~~~~~~
~~~~~~P$$~~~~~~~
~~~---------~~~~
~~~-----------~~
~~--#C#C|##----~
~---S#####IA---~
~---+#####K---~~
~---#FFF##F---~~
~~-A----@@@--~~~
~~-----------~~~
~~~~--------~~~~
~~~~~~~----~~~~~
~~~~~~~~~~~~~~~~
; seconds=240
; plates={c:0, d:0}
; dirty_plates=true
; link: https://overcooked.fandom.com/wiki/3-1_(Overcooked!)
; ice: accelerating
\ No newline at end of file
##$$####$$###
####P##______
______?______
______N______
U_____T_____U
X#####X______
U_____#_____U
______#______
__A___#__A___
@@@C#C#______
; seconds=240
; plates={c:0, d:0}
; dirty_plates=false
; link: https://overcooked.fandom.com/wiki/3-2_(Overcooked!)
; moving counters
\ No newline at end of file
__________""#NIK?TX##
__________""#__A____$
__________""#_______$
__________""#__A____P
__________""_________
C_________""________C
#_________""________#
C_________""________C
#|U#U#U@@####F@F@F|##
; seconds=240
; plates={c:0, d:0}
; dirty_plates=false
; link: https://overcooked.fandom.com/wiki/3-3_(Overcooked!)
; moving trucks: counters and ground are moving
\ No newline at end of file
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