mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-06-23 12:01:36 +02:00
new rules, new spawn logic, small fixes, default and narrow corridor debugged
This commit is contained in:
@ -12,14 +12,6 @@ from marl_factory_grid.environment import constants as c
|
||||
|
||||
class Agent(Entity):
|
||||
|
||||
@property
|
||||
def var_is_blocking_light(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_can_move(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def var_is_paralyzed(self):
|
||||
return len(self._paralyzed)
|
||||
@ -28,14 +20,6 @@ class Agent(Entity):
|
||||
def paralyze_reasons(self):
|
||||
return [x for x in self._paralyzed]
|
||||
|
||||
@property
|
||||
def var_is_blocking_pos(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_has_position(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def obs_tag(self):
|
||||
return self.name
|
||||
@ -48,10 +32,6 @@ class Agent(Entity):
|
||||
def observations(self):
|
||||
return self._observations
|
||||
|
||||
@property
|
||||
def var_can_collide(self):
|
||||
return True
|
||||
|
||||
def step_result(self):
|
||||
pass
|
||||
|
||||
@ -60,16 +40,21 @@ class Agent(Entity):
|
||||
return self._collection
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self._state or ActionResult(entity=self, identifier=c.NOOP, validity=c.VALID, reward=0)
|
||||
def var_is_blocking_pos(self):
|
||||
return self._is_blocking_pos
|
||||
|
||||
def __init__(self, actions: List[Action], observations: List[str], *args, **kwargs):
|
||||
@property
|
||||
def state(self):
|
||||
return self._state or ActionResult(entity=self, identifier=c.NOOP, validity=c.VALID)
|
||||
|
||||
def __init__(self, actions: List[Action], observations: List[str], *args, is_blocking_pos=False, **kwargs):
|
||||
super(Agent, self).__init__(*args, **kwargs)
|
||||
self._paralyzed = set()
|
||||
self.step_result = dict()
|
||||
self._actions = actions
|
||||
self._observations = observations
|
||||
self._state: Union[Result, None] = None
|
||||
self._is_blocking_pos = is_blocking_pos
|
||||
|
||||
# noinspection PyAttributeOutsideInit
|
||||
def clear_temp_state(self):
|
||||
|
@ -14,7 +14,7 @@ class Entity(_Object, abc.ABC):
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
return self._status or ActionResult(entity=self, identifier=c.NOOP, validity=c.VALID, reward=0)
|
||||
return self._status or ActionResult(entity=self, identifier=c.NOOP, validity=c.VALID)
|
||||
|
||||
@property
|
||||
def var_has_position(self):
|
||||
@ -60,6 +60,10 @@ class Entity(_Object, abc.ABC):
|
||||
def pos(self):
|
||||
return self._pos
|
||||
|
||||
def set_pos(self, pos):
|
||||
assert isinstance(pos, tuple) and len(pos) == 2
|
||||
self._pos = pos
|
||||
|
||||
@property
|
||||
def last_pos(self):
|
||||
try:
|
||||
@ -84,7 +88,7 @@ class Entity(_Object, abc.ABC):
|
||||
for observer in self.observers:
|
||||
observer.notify_del_entity(self)
|
||||
self._view_directory = curr_pos[0] - next_pos[0], curr_pos[1] - next_pos[1]
|
||||
self._pos = next_pos
|
||||
self.set_pos(next_pos)
|
||||
for observer in self.observers:
|
||||
observer.notify_add_entity(self)
|
||||
return valid
|
||||
@ -93,7 +97,7 @@ class Entity(_Object, abc.ABC):
|
||||
def __init__(self, pos, bind_to=None, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self._status = None
|
||||
self._pos = pos
|
||||
self.set_pos(pos)
|
||||
self._last_pos = pos
|
||||
if bind_to:
|
||||
try:
|
||||
@ -109,8 +113,9 @@ class Entity(_Object, abc.ABC):
|
||||
def render(self):
|
||||
return RenderEntity(self.__class__.__name__.lower(), self.pos)
|
||||
|
||||
def __repr__(self):
|
||||
return super(Entity, self).__repr__() + f'(@{self.pos})'
|
||||
@abc.abstractmethod
|
||||
def render(self):
|
||||
return RenderEntity(self.__class__.__name__.lower(), self.pos)
|
||||
|
||||
@property
|
||||
def obs_tag(self):
|
||||
@ -149,4 +154,4 @@ class Entity(_Object, abc.ABC):
|
||||
except StopIteration:
|
||||
pass
|
||||
except ValueError:
|
||||
print()
|
||||
pass
|
||||
|
@ -1,24 +0,0 @@
|
||||
|
||||
|
||||
# noinspection PyAttributeOutsideInit
|
||||
class BoundEntityMixin:
|
||||
|
||||
@property
|
||||
def bound_entity(self):
|
||||
return self._bound_entity
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
if self.bound_entity:
|
||||
return f'{self.__class__.__name__}({self.bound_entity.name})'
|
||||
else:
|
||||
pass
|
||||
|
||||
def belongs_to_entity(self, entity):
|
||||
return entity == self.bound_entity
|
||||
|
||||
def bind_to(self, entity):
|
||||
self._bound_entity = entity
|
||||
|
||||
def unbind(self):
|
||||
self._bound_entity = None
|
@ -13,10 +13,6 @@ class _Object:
|
||||
def __bool__(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def var_has_position(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_can_be_bound(self):
|
||||
try:
|
||||
@ -30,22 +26,14 @@ class _Object:
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
if self._str_ident is not None:
|
||||
name = f'{self.__class__.__name__}[{self._str_ident}]'
|
||||
else:
|
||||
name = f'{self.__class__.__name__}#{self.u_int}'
|
||||
if self.bound_entity:
|
||||
name = h.add_bound_name(name, self.bound_entity)
|
||||
if self.var_has_position:
|
||||
name = h.add_pos_name(name, self)
|
||||
return name
|
||||
return f'{self.__class__.__name__}[{self.identifier}]'
|
||||
|
||||
@property
|
||||
def identifier(self):
|
||||
if self._str_ident is not None:
|
||||
return self._str_ident
|
||||
else:
|
||||
return self.name
|
||||
return self.u_int
|
||||
|
||||
def reset_uid(self):
|
||||
self._u_idx = defaultdict(lambda: 0)
|
||||
@ -62,7 +50,15 @@ class _Object:
|
||||
print(f'Following kwargs were passed, but ignored: {kwargs}')
|
||||
|
||||
def __repr__(self):
|
||||
return f'{self.name}'
|
||||
name = self.name
|
||||
if self.bound_entity:
|
||||
name = h.add_bound_name(name, self.bound_entity)
|
||||
try:
|
||||
if self.var_has_position:
|
||||
name = h.add_pos_name(name, self)
|
||||
except (AttributeError):
|
||||
pass
|
||||
return name
|
||||
|
||||
def __eq__(self, other) -> bool:
|
||||
return other == self.identifier
|
||||
@ -88,7 +84,7 @@ class _Object:
|
||||
def summarize_state(self):
|
||||
return dict()
|
||||
|
||||
def bind(self, entity):
|
||||
def bind_to(self, entity):
|
||||
# noinspection PyAttributeOutsideInit
|
||||
self._bound_entity = entity
|
||||
return c.VALID
|
||||
@ -100,9 +96,6 @@ class _Object:
|
||||
def bound_entity(self):
|
||||
return self._bound_entity
|
||||
|
||||
def bind_to(self, entity):
|
||||
self._bound_entity = entity
|
||||
|
||||
def unbind(self):
|
||||
self._bound_entity = None
|
||||
|
||||
|
@ -24,7 +24,7 @@ class PlaceHolder(_Object):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return "PlaceHolder"
|
||||
return self.__class__.__name__
|
||||
|
||||
|
||||
class GlobalPosition(_Object):
|
||||
@ -36,7 +36,8 @@ class GlobalPosition(_Object):
|
||||
else:
|
||||
return self.bound_entity.pos
|
||||
|
||||
def __init__(self, level_shape, *args, normalized: bool = True, **kwargs):
|
||||
def __init__(self, agent, level_shape, *args, normalized: bool = True, **kwargs):
|
||||
super(GlobalPosition, self).__init__(*args, **kwargs)
|
||||
self.bind_to(agent)
|
||||
self._normalized = normalized
|
||||
self._shape = level_shape
|
||||
|
@ -5,13 +5,8 @@ from marl_factory_grid.utils.utility_classes import RenderEntity
|
||||
|
||||
class Wall(Entity):
|
||||
|
||||
@property
|
||||
def var_has_position(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def var_can_collide(self):
|
||||
return True
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@property
|
||||
def encoding(self):
|
||||
@ -19,11 +14,3 @@ class Wall(Entity):
|
||||
|
||||
def render(self):
|
||||
return RenderEntity(c.WALL, self.pos)
|
||||
|
||||
@property
|
||||
def var_is_blocking_pos(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def var_is_blocking_light(self):
|
||||
return True
|
||||
|
Reference in New Issue
Block a user