mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-11-27 11:30:38 +01:00
Movement printing and Results, state, state reset.
This commit is contained in:
@@ -43,9 +43,6 @@ class Agent(Entity):
|
||||
def var_is_blocking_pos(self):
|
||||
return self._is_blocking_pos
|
||||
|
||||
@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)
|
||||
@@ -53,21 +50,16 @@ class Agent(Entity):
|
||||
self.step_result = dict()
|
||||
self._actions = actions
|
||||
self._observations = observations
|
||||
self._state: Union[Result, None] = None
|
||||
self._status: Union[Result, None] = None
|
||||
self._is_blocking_pos = is_blocking_pos
|
||||
|
||||
# noinspection PyAttributeOutsideInit
|
||||
def clear_temp_state(self):
|
||||
self._state = None
|
||||
return self
|
||||
|
||||
def summarize_state(self):
|
||||
state_dict = super().summarize_state()
|
||||
state_dict.update(valid=bool(self.state.validity), action=str(self.state.identifier))
|
||||
return state_dict
|
||||
|
||||
def set_state(self, action_result):
|
||||
self._state = action_result
|
||||
self._status = action_result
|
||||
|
||||
def paralyze(self, reason):
|
||||
self._paralyzed.add(reason)
|
||||
|
||||
@@ -90,7 +90,14 @@ class Entity(Object, abc.ABC):
|
||||
self.set_pos(next_pos)
|
||||
for observer in self.observers:
|
||||
observer.notify_add_entity(self)
|
||||
# Aftermath Collision Check
|
||||
if len([x for x in state.entities.by_pos(next_pos) if x.var_can_collide]):
|
||||
# The entity did move, but there was something to collide with...
|
||||
# Is then reported as a non-valid move, which did work.
|
||||
valid = False
|
||||
|
||||
return valid
|
||||
# Bad naming... Was the same was the same pos, not moving....
|
||||
return not_same_pos
|
||||
|
||||
def __init__(self, pos, bind_to=None, **kwargs):
|
||||
|
||||
@@ -40,6 +40,7 @@ class Object:
|
||||
return True
|
||||
|
||||
def __init__(self, str_ident: Union[str, None] = None, **kwargs):
|
||||
self._status = None
|
||||
self._bound_entity = None
|
||||
self._observers = set()
|
||||
self._str_ident = str_ident
|
||||
@@ -84,6 +85,10 @@ class Object:
|
||||
def summarize_state(self):
|
||||
return dict()
|
||||
|
||||
def clear_temp_state(self):
|
||||
self._status = None
|
||||
return self
|
||||
|
||||
def bind_to(self, entity):
|
||||
# noinspection PyAttributeOutsideInit
|
||||
self._bound_entity = entity
|
||||
|
||||
Reference in New Issue
Block a user