Door Area Indicators

This commit is contained in:
Steffen Illium
2022-01-18 11:39:19 +01:00
parent 3ce6302e8a
commit a16d7e709e
7 changed files with 34 additions and 9 deletions

View File

@ -68,6 +68,7 @@ class BaseFactory(gym.Env):
@property
def params(self) -> dict:
d = {key: val for key, val in self.__dict__.items() if not key.startswith('_') and not key.startswith('__')}
d['class_name'] = self.__class__.__name__
return d
def __enter__(self):
@ -83,7 +84,10 @@ class BaseFactory(gym.Env):
rewards_base: RewardsBase = RewardsBase(),
parse_doors=False, done_at_collision=False, inject_agents: Union[None, List] = None,
verbose=False, doors_have_area=True, env_seed=time.time_ns(), individual_rewards=False,
**kwargs):
class_name='', **kwargs):
if class_name:
print(f'You loaded parameters for {class_name}', f'this is: {self.__class__.__name__}')
if isinstance(mv_prop, dict):
mv_prop = MovementProperties(**mv_prop)
@ -167,7 +171,7 @@ class BaseFactory(gym.Env):
parsed_doors = np.pad(parsed_doors, self.obs_prop.pomdp_r, 'constant', constant_values=0)
if np.any(parsed_doors):
door_tiles = [floor.by_pos(tuple(pos)) for pos in np.argwhere(parsed_doors == c.OCCUPIED_CELL)]
doors = Doors.from_tiles(door_tiles, self._level_shape,
doors = Doors.from_tiles(door_tiles, self._level_shape, have_area=self.doors_have_area,
entity_kwargs=dict(context=floor)
)
self._entities.register_additional_items({c.DOORS: doors})

View File

@ -311,7 +311,7 @@ class Door(Entity):
@property
def encoding(self):
# This is important as it shadow is checked by occupation value
return c.OCCUPIED_CELL if self.is_closed else 0.5
return c.CLOSED_DOOR_CELL if self.is_closed else c.OPEN_DOOR_CELL
@property
def str_state(self):

View File

@ -460,7 +460,9 @@ class Agents(MovingEntityObjectRegister):
class Doors(EntityRegister):
def __init__(self, *args, **kwargs):
def __init__(self, *args, have_area: bool = False, **kwargs):
self.have_area = have_area
self._area_marked = False
super(Doors, self).__init__(*args, is_blocking_light=True, can_collide=True, **kwargs)
_accepted_objects = Door
@ -475,6 +477,18 @@ class Doors(EntityRegister):
for door in self:
door.tick()
def as_array(self):
if self.have_area and not self._area_marked:
for door in self:
for pos in door.access_area:
if self._individual_slices:
pass
else:
pos = (0, *pos)
self._lazy_eval_transforms.append((pos, c.ACCESS_DOOR_CELL))
self._area_marked = True
return super(Doors, self).as_array()
class Actions(ObjectRegister):
_accepted_objects = Action