Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"logfile" : "app.log",
"layouts" : ["cramped_room", "cramped_room_tomato", "asymmetric_advantages", "coordination_ring", "forced_coordination", "counter_circuit", "cramped_corridor", "marshmallow_experiment", "long_cook_time", "forced_coordination_tomato", "asymmetric_advantages_tomato", "marshmallow_experiment_coordination", "pipeline", "you_shall_not_pass", "tutorial_3"],
"layouts" : ["cramped_room", "cramped_room_tomato", "asymmetric_advantages", "coordination_ring", "forced_coordination", "counter_circuit", "cramped_corridor", "marshmallow_experiment", "long_cook_time", "forced_coordination_tomato", "asymmetric_advantages_tomato", "marshmallow_experiment_coordination", "pipeline", "you_shall_not_pass", "tutorial_3", "complicated_random_room", "simple_random_room"],
"MAX_GAMES" : 10,
"MAX_GAME_LENGTH" : 120,
"AGENT_DIR" : "./static/assets/agents",
Expand Down
23 changes: 17 additions & 6 deletions server/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
from overcooked_ai_py.mdp.overcooked_env import OvercookedEnv
from overcooked_ai_py.mdp.actions import Action, Direction
from overcooked_ai_py.planning.planners import MotionPlanner, NO_COUNTERS_PARAMS
from overcooked_ai_py.utils import load_from_json
from overcooked_ai_py.mdp.layout_generator import LayoutGenerator
from human_aware_rl.rllib.rllib import load_agent
import numpy as np
import random, os, pickle, json
import ray

# Relative path to where all static pre-trained agents are stored on server
AGENT_DIR = None

LAYOUT_GEN_PARAMS_DIR = os.path.join("static", "layout_generation_params")
# Maximum allowable game time (in seconds)
MAX_GAME_TIME = None

Expand Down Expand Up @@ -406,20 +409,21 @@ def __init__(self, layouts=["cramped_room"], mdp_params={}, num_players=2, gameT
self.curr_tick = 0
self.human_players = set()
self.npc_players = set()
self.featurize_fn = lambda state: self.mdp.lossless_state_encoding(state, 100000)

if randomized:
random.shuffle(self.layouts)

if playerZero != 'human':
player_zero_id = playerZero + '_0'
self.add_player(player_zero_id, idx=0, buff_size=1, is_human=False)
self.npc_policies[player_zero_id] = self.get_policy(playerZero, idx=0)
self.npc_policies[player_zero_id] = self.get_policy(playerZero, idx=0, featurize_fn=self.featurize_fn)
self.npc_state_queues[player_zero_id] = LifoQueue()

if playerOne != 'human':
player_one_id = playerOne + '_1'
self.add_player(player_one_id, idx=1, buff_size=1, is_human=False)
self.npc_policies[player_one_id] = self.get_policy(playerOne, idx=1)
self.npc_policies[player_one_id] = self.get_policy(playerOne, idx=1, featurize_fn=self.featurize_fn)
self.npc_state_queues[player_one_id] = LifoQueue()


Expand Down Expand Up @@ -533,7 +537,14 @@ def activate(self):
raise ValueError("Inconsistent State")

self.curr_layout = self.layouts.pop()
self.mdp = OvercookedGridworld.from_layout_name(self.curr_layout, **self.mdp_params)

try:
mdp_gen_params = load_from_json(os.path.join(LAYOUT_GEN_PARAMS_DIR, self.curr_layout))
np.random.seed(int(time()*100) % 100000)
self.mdp = LayoutGenerator.mdp_gen_fn_from_dict(mdp_gen_params, outer_shape=mdp_gen_params["inner_shape"])()
except FileNotFoundError:
self.mdp = OvercookedGridworld.from_layout_name(self.curr_layout, **self.mdp_params)

if self.show_potential:
self.mp = MotionPlanner.from_pickle_or_compute(self.mdp, counter_goals=NO_COUNTERS_PARAMS)
self.state = self.mdp.get_standard_start_state()
Expand Down Expand Up @@ -578,12 +589,12 @@ def to_json(self):
obj_dict['state'] = self.get_state() if self._is_active else None
return obj_dict

def get_policy(self, npc_id, idx=0):
def get_policy(self, npc_id, idx=0, featurize_fn=None):
if npc_id.lower().startswith("rllib"):
try:
# Loading rllib agents requires additional helpers
fpath = os.path.join(AGENT_DIR, npc_id, 'agent', 'agent')
agent = load_agent(fpath, agent_index=idx)
agent = load_agent(fpath, agent_index=idx, featurize_fn=featurize_fn)
return agent
except Exception as e:
raise IOError("Error loading Rllib Agent\n{}".format(e.__repr__()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"inner_shape": [7, 5],
"prop_empty": 0.75,
"prop_feats": 0.35,
"start_all_orders": [{
"ingredients": ["onion", "onion", "onion"]
}],
"recipe_values": [20],
"recipe_times": [20],
"display": false
}
11 changes: 11 additions & 0 deletions server/static/layout_generation_params/simple_random_room.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"inner_shape": [5, 4],
"prop_empty": 0.95,
"prop_feats": 0.1,
"start_all_orders" : [
{ "ingredients" : ["onion", "onion", "onion"]}
],
"recipe_values" : [20],
"recipe_times" : [20],
"display": false
}