New Szenario "Two_Rooms_One_Door"

This commit is contained in:
Steffen Illium
2023-07-12 15:59:21 +02:00
parent 836495a884
commit 9135a69da6
25 changed files with 223 additions and 45 deletions

View File

@ -13,7 +13,9 @@ class DestAction(Action):
super().__init__(d.DESTINATION)
def do(self, entity, state) -> Union[None, ActionResult]:
if destination := state[d.DESTINATION].by_pos(entity.pos):
dest_entities = d.DESTINATION if d.DESTINATION in state else d.BOUNDDESTINATION
assert dest_entities
if destination := state[dest_entities].by_pos(entity.pos):
valid = destination.do_wait_action(entity)
state.print(f'{entity.name} just waited at {entity.pos}')
else:

View File

@ -1,6 +1,7 @@
# Destination Env
DESTINATION = 'Destinations'
BOUNDDESTINATION = 'BoundDestinations'
DEST_SYMBOL = 1
DEST_REACHED_REWARD = 0.5
DEST_REACHED = 'ReachedDestinations'

View File

@ -3,12 +3,19 @@ from collections import defaultdict
from marl_factory_grid.environment.entity.agent import Agent
from marl_factory_grid.environment.entity.entity import Entity
from marl_factory_grid.environment import constants as c
from marl_factory_grid.environment.entity.mixin import BoundEntityMixin
from marl_factory_grid.utils.render import RenderEntity
from marl_factory_grid.modules.destinations import constants as d
class Destination(Entity):
var_can_move = False
var_can_collide = False
var_has_position = True
var_is_blocking_pos = False
var_is_blocking_light = False
@property
def any_agent_has_dwelled(self):
return bool(len(self._per_agent_times))
@ -49,3 +56,21 @@ class Destination(Entity):
def render(self):
return RenderEntity(d.DESTINATION, self.pos)
class BoundDestination(BoundEntityMixin, Destination):
@property
def encoding(self):
return d.DEST_SYMBOL
def __init__(self, entity, *args, **kwargs):
self.bind_to(entity)
super().__init__(*args, **kwargs)
@property
def is_considered_reached(self):
agent_at_position = any(self.bound_entity == x for x in self.tile.guests_that_can_collide)
return (agent_at_position and not self.dwell_time) \
or any(x == 0 for x in self._per_agent_times[self.bound_entity.name])

View File

@ -1,6 +1,6 @@
from marl_factory_grid.environment.groups.env_objects import EnvObjects
from marl_factory_grid.environment.groups.mixins import PositionMixin
from marl_factory_grid.modules.destinations.entitites import Destination
from marl_factory_grid.environment.groups.mixins import PositionMixin, HasBoundMixin
from marl_factory_grid.modules.destinations.entitites import Destination, BoundDestination
class Destinations(PositionMixin, EnvObjects):
@ -16,6 +16,14 @@ class Destinations(PositionMixin, EnvObjects):
return super(Destinations, self).__repr__()
class BoundDestinations(HasBoundMixin, Destinations):
_entity = BoundDestination
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class ReachedDestinations(Destinations):
_entity = Destination
is_blocking_light = False