crafting done ?

This commit is contained in:
2023-01-13 20:07:21 +01:00
parent 7539863ace
commit 4f1044b87e
7 changed files with 554 additions and 52 deletions
+9 -2
View File
@@ -38,7 +38,7 @@ class BaseAgent:
if idx is None:
idx = 0
if multi_action_mode is None:
multi_action_mode = False
@@ -64,6 +64,7 @@ class BaseAgent:
self._registered_inventory = False
self._registered_endogenous = False
self._registered_components = False
self._setup = False # agent setup not completed
self._noop_action_dict = dict()
# Special flag to allow logic for multi-action-mode agents
@@ -78,7 +79,13 @@ class BaseAgent:
def idx(self):
"""Index used to identify this agent. Must be unique within the environment."""
return self._idx
@property
def is_setup(self):
return self._setup
def set_setup(self, set):
self._setup=set
def register_inventory(self, resources):
"""Used during environment construction to populate inventory/escrow fields."""
if self._registered_inventory:
+14 -8
View File
@@ -342,16 +342,11 @@ class BaseEnvironment(ABC):
self._components_dict[component_object.name] = component_object
self._shorthand_lookup[component_object.shorthand] = component_object
# Register the components with the agents
# to finish setting up their state/action spaces.
for agent in self.world.agents:
agent.register_inventory(self.resources)
agent.register_endogenous(self.endogenous)
agent.register_components(self._components)
self.world.planner.register_inventory(self.resources)
self.world.planner.register_components(self._components)
self._agent_lookup = {str(agent.idx): agent for agent in self.all_agents}
self.apply_scenario_config_to_agents()
self._completions = 0
@@ -370,6 +365,16 @@ class BaseEnvironment(ABC):
# To collate all the agents ('0', '1', ...) data during reset and step
# into a single agent with index 'a'
self.collate_agent_step_and_reset_data = collate_agent_step_and_reset_data
def apply_scenario_config_to_agents(self):
# Register the components with the agents
# to finish setting up their state/action spaces.
for agent in self.world.agents:
agent.register_inventory(self.resources)
agent.register_endogenous(self.endogenous)
agent.register_components(self._components)
self._agent_lookup = {str(agent.idx): agent for agent in self.all_agents}
self.world.apply_agent_db_to_world()
def _register_entities(self, entities):
for entity in entities:
@@ -920,6 +925,7 @@ class BaseEnvironment(ABC):
# Reset actions to that default.
for agent in self.all_agents:
agent.reset_actions()
agent.set_setup(True)
# Produce observations
obs = self._generate_observations(
+2 -2
View File
@@ -382,7 +382,7 @@ class World:
self._agent_class_idx_map={}
#create agents
self.create_agents(agent_composition)
self.maps = Maps(world_size, self.n_agents, world_resources, world_landmarks)
planner_class = agent_registry.get("BasicPlanner")
@@ -410,7 +410,7 @@ class World:
self._agent_class_idx_map[k].append(str(self.n_agents))
self.n_agents+=1
def apply_agent_db(self):
def apply_agent_db_to_world(self):
"""Applys current agent db into lookup maps inside world and map itself. Enables insertion of new agents into existing env."""
self.n_agents=len(self._agents)
self._agent_class_idx_map={}