mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-07-05 09:01:36 +02:00
Merge branch 'main' into unit_testing
# Conflicts: # marl_factory_grid/modules/doors/groups.py # marl_factory_grid/utils/states.py
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
from typing import Union
|
||||
|
||||
from marl_factory_grid.environment.entity.entity import Entity
|
||||
from marl_factory_grid.utils import Result
|
||||
from marl_factory_grid.utils.utility_classes import RenderEntity
|
||||
@ -16,6 +18,9 @@ class DoorIndicator(Entity):
|
||||
return []
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""
|
||||
Is added around a door for agents to see.
|
||||
"""
|
||||
super().__init__(*args, **kwargs)
|
||||
self.__delattr__('move')
|
||||
|
||||
@ -39,23 +44,38 @@ class Door(Entity):
|
||||
return d.VALUE_CLOSED_DOOR if self.is_closed else d.VALUE_OPEN_DOOR
|
||||
|
||||
@property
|
||||
def str_state(self):
|
||||
def str_state(self) -> str:
|
||||
"""
|
||||
Internal Usage
|
||||
"""
|
||||
return 'open' if self.is_open else 'closed'
|
||||
|
||||
@property
|
||||
def is_closed(self):
|
||||
def is_closed(self) -> bool:
|
||||
return self._state == d.STATE_CLOSED
|
||||
|
||||
@property
|
||||
def is_open(self):
|
||||
def is_open(self) -> bool:
|
||||
return self._state == d.STATE_OPEN
|
||||
|
||||
|
||||
@property
|
||||
def time_to_close(self):
|
||||
"""
|
||||
:returns: The time it takes for the door to close.
|
||||
:rtype: float
|
||||
"""
|
||||
return self._time_to_close
|
||||
|
||||
def __init__(self, *args, closed_on_init=True, auto_close_interval=10, **kwargs):
|
||||
"""
|
||||
A door entity that can be opened or closed by agents or rules.
|
||||
|
||||
:param closed_on_init: Whether the door spawns as open or closed.
|
||||
:type closed_on_init: bool
|
||||
|
||||
:param auto_close_interval: after how many steps should the door automatically close itself,
|
||||
:type auto_close_interval: int
|
||||
"""
|
||||
self._state = d.STATE_CLOSED
|
||||
super(Door, self).__init__(*args, **kwargs)
|
||||
self._auto_close_interval = auto_close_interval
|
||||
@ -74,14 +94,17 @@ class Door(Entity):
|
||||
name, state = 'door_open' if self.is_open else 'door_closed', 'blank'
|
||||
return RenderEntity(name, self.pos, 1, 'none', state, self.u_int + 1)
|
||||
|
||||
def use(self):
|
||||
def use(self) -> bool:
|
||||
"""
|
||||
Internal usage
|
||||
"""
|
||||
if self._state == d.STATE_OPEN:
|
||||
self._close()
|
||||
else:
|
||||
self._open()
|
||||
return c.VALID
|
||||
|
||||
def tick(self, state):
|
||||
def tick(self, state) -> Union[Result, None]:
|
||||
# Check if no entity is standing in the door
|
||||
if not any(e for e in state.entities.by_pos(self.pos) if e.var_can_collide or e.var_is_blocking_pos):
|
||||
# if len(state.entities.pos_dict[self.pos]) <= 2: #can collide can block
|
||||
@ -99,23 +122,38 @@ class Door(Entity):
|
||||
self._reset_timer()
|
||||
return Result(f"{d.DOOR}_reset", c.VALID, entity=self)
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> bool:
|
||||
"""
|
||||
Internal Usage
|
||||
"""
|
||||
self._state = d.STATE_OPEN
|
||||
self._reset_timer()
|
||||
return True
|
||||
|
||||
def _close(self):
|
||||
def _close(self) -> bool:
|
||||
"""
|
||||
Internal Usage
|
||||
"""
|
||||
self._state = d.STATE_CLOSED
|
||||
return True
|
||||
|
||||
def _decrement_timer(self):
|
||||
def _decrement_timer(self) -> bool:
|
||||
"""
|
||||
Internal Usage
|
||||
"""
|
||||
self._time_to_close -= 1
|
||||
return True
|
||||
|
||||
def _reset_timer(self):
|
||||
def _reset_timer(self) -> bool:
|
||||
"""
|
||||
Internal Usage
|
||||
"""
|
||||
self._time_to_close = self._auto_close_interval
|
||||
return True
|
||||
|
||||
def reset(self):
|
||||
"""
|
||||
Internal Usage
|
||||
"""
|
||||
self._close()
|
||||
self._reset_timer()
|
||||
|
Reference in New Issue
Block a user