mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-07-07 10:01:36 +02:00
WIP: collection, entities, objects
This commit is contained in:
@ -16,10 +16,9 @@ class Entity(Object, abc.ABC):
|
||||
def state(self):
|
||||
return self._status or ActionResult(entity=self, identifier=c.NOOP, validity=c.VALID, reward=0)
|
||||
|
||||
# @property
|
||||
# def var_has_position(self):
|
||||
# return self.pos != c.VALUE_NO_POS
|
||||
var_has_position: bool = True
|
||||
@property
|
||||
def var_has_position(self):
|
||||
return self.pos != c.VALUE_NO_POS
|
||||
|
||||
@property
|
||||
def var_is_blocking_light(self):
|
||||
@ -28,7 +27,6 @@ class Entity(Object, abc.ABC):
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
# var_is_blocking_light: bool = True
|
||||
|
||||
@property
|
||||
def var_can_move(self):
|
||||
@ -51,7 +49,6 @@ class Entity(Object, abc.ABC):
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
# var_can_collide: bool = True
|
||||
|
||||
@property
|
||||
def x(self):
|
||||
|
@ -5,13 +5,13 @@ from marl_factory_grid.environment import constants as c
|
||||
|
||||
|
||||
class Object:
|
||||
|
||||
"""Generell Objects for Organisation and Maintanance such as Actions etc..."""
|
||||
|
||||
_u_idx = defaultdict(lambda: 0)
|
||||
|
||||
def __bool__(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def var_has_position(self): # brauchen wir das hier jetzt?
|
||||
try:
|
||||
@ -93,11 +93,10 @@ class Object:
|
||||
|
||||
|
||||
class EnvObject(Object):
|
||||
|
||||
"""Objects that hold Information that are observable, but have no position on the environment grid. Inventories etc..."""
|
||||
|
||||
_u_idx = defaultdict(lambda: 0)
|
||||
|
||||
|
||||
@property
|
||||
def obs_tag(self):
|
||||
try:
|
||||
|
@ -1,5 +1,5 @@
|
||||
from marl_factory_grid.environment.entity.agent import Agent
|
||||
from marl_factory_grid.environment.groups.env_objects import Collection
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@ from typing import List, Union
|
||||
import numpy as np
|
||||
|
||||
from marl_factory_grid.environment.entity.util import GlobalPosition
|
||||
from marl_factory_grid.environment.groups.env_objects import Collection
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin, HasBoundMixin
|
||||
from marl_factory_grid.environment.groups.objects import Objects
|
||||
from marl_factory_grid.modules.zones import Zone
|
||||
|
@ -2,7 +2,7 @@ import random
|
||||
from typing import List, Tuple
|
||||
|
||||
from marl_factory_grid.environment import constants as c
|
||||
from marl_factory_grid.environment.groups.env_objects import Collection
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin
|
||||
from marl_factory_grid.environment.entity.wall_floor import Wall, Floor
|
||||
|
||||
|
@ -9,6 +9,10 @@ from marl_factory_grid.modules.batteries import constants as b
|
||||
|
||||
class Battery(Object):
|
||||
|
||||
@property
|
||||
def var_can_be_bound(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def is_discharged(self):
|
||||
return self.charge_level == 0
|
||||
@ -67,7 +71,8 @@ class Pod(Entity):
|
||||
if battery.charge_level == 1.0:
|
||||
return c.NOT_VALID
|
||||
# if sum(guest for guest in self.tile.guests if 'agent' in guest.name.lower()) > 1:
|
||||
if sum(1 for key, val in self.state.entities.pos_dict[self.pos] for guest in val if 'agent' in guest.name.lower()) > 1:
|
||||
if sum(1 for key, val in self.state.entities.pos_dict[self.pos] for guest in val if
|
||||
'agent' in guest.name.lower()) > 1:
|
||||
return c.NOT_VALID
|
||||
valid = battery.do_charge_action(self.charge_rate)
|
||||
return valid
|
||||
|
@ -1,4 +1,4 @@
|
||||
from marl_factory_grid.environment.groups.env_objects import Collection
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin, HasBoundMixin
|
||||
from marl_factory_grid.modules.batteries.entitites import Pod, Battery
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
from marl_factory_grid.environment.groups.env_objects import Collection
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin
|
||||
from marl_factory_grid.environment.entity.wall_floor import Floor
|
||||
from marl_factory_grid.modules.clean_up.entitites import DirtPile
|
||||
|
@ -8,14 +8,31 @@ from marl_factory_grid.utils.render import RenderEntity
|
||||
from marl_factory_grid.modules.destinations import constants as d
|
||||
|
||||
|
||||
class Destination(BoundEntityMixin, Entity):
|
||||
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
|
||||
var_can_be_bound = True # Introduce this globally!
|
||||
@property
|
||||
def var_can_move(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_can_collide(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_has_position(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def var_is_blocking_pos(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_is_blocking_light(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_can_be_bound(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def was_reached(self):
|
||||
@ -39,7 +56,8 @@ class Destination(BoundEntityMixin, Entity):
|
||||
def has_just_been_reached(self):
|
||||
if self.was_reached:
|
||||
return False
|
||||
agent_at_position = any(c.AGENT.lower() in x.name.lower() for x in state.entities.pos_dict[self.pos] if x.var_can_collide)
|
||||
agent_at_position = any(
|
||||
c.AGENT.lower() in x.name.lower() for x in state.entities.pos_dict[self.pos] if x.var_can_collide)
|
||||
|
||||
if self.bound_entity:
|
||||
return ((agent_at_position and not self.action_counts)
|
||||
|
@ -1,4 +1,4 @@
|
||||
from marl_factory_grid.environment.groups.env_objects import Collection
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin
|
||||
from marl_factory_grid.modules.destinations.entitites import Destination
|
||||
from marl_factory_grid.environment import constants as c
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Union
|
||||
|
||||
from marl_factory_grid.environment.groups.env_objects import Collection
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin
|
||||
from marl_factory_grid.modules.doors import constants as d
|
||||
from marl_factory_grid.modules.doors.entitites import Door
|
||||
|
@ -8,7 +8,9 @@ from marl_factory_grid.modules.items import constants as i
|
||||
|
||||
class Item(Entity):
|
||||
|
||||
var_can_collide = False
|
||||
@property
|
||||
def var_can_collide(self):
|
||||
return False
|
||||
|
||||
def render(self):
|
||||
return RenderEntity(i.ITEM, self.pos) if self.pos != c.VALUE_NO_POS else None
|
||||
@ -71,7 +73,7 @@ class DropOffLocation(Entity):
|
||||
def place_item(self, item: Item):
|
||||
if self.is_full:
|
||||
raise RuntimeWarning("There is currently no way to clear the storage or make it unfull.")
|
||||
return bc.NOT_VALID
|
||||
return bc.NOT_VALID # in Zeile 81 verschieben?
|
||||
else:
|
||||
self.storage.append(item)
|
||||
item.set_auto_despawn(self.auto_item_despawn_interval)
|
||||
|
@ -1,7 +1,7 @@
|
||||
from marl_factory_grid.modules.items import constants as i
|
||||
from marl_factory_grid.environment import constants as c
|
||||
|
||||
from marl_factory_grid.environment.groups.env_objects import Collection
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.objects import Objects
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin, IsBoundMixin, HasBoundMixin
|
||||
from marl_factory_grid.environment.entity.agent import Agent
|
||||
@ -10,8 +10,14 @@ from marl_factory_grid.modules.items.entitites import Item, DropOffLocation
|
||||
|
||||
class Items(PositionMixin, Collection):
|
||||
_entity = Item
|
||||
is_blocking_light: bool = False
|
||||
can_collide: bool = False
|
||||
|
||||
@property
|
||||
def is_blocking_light(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def can_collide(self):
|
||||
return False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@ -21,7 +27,8 @@ class Items(PositionMixin, Collection):
|
||||
if item_to_spawns := max(0, (n_items - len(state[i.ITEM]))):
|
||||
floor_list = state.entities.floorlist[:item_to_spawns]
|
||||
state[i.ITEM].spawn(floor_list)
|
||||
state.print(f'{item_to_spawns} new items have been spawned; next spawn in {spawn_frequency}') # spawn in self._next_item_spawn ?
|
||||
state.print(
|
||||
f'{item_to_spawns} new items have been spawned; next spawn in {spawn_frequency}') # spawn in self._next_item_spawn ?
|
||||
return len(floor_list)
|
||||
else:
|
||||
state.print('No Items are spawning, limit is reached.')
|
||||
@ -57,7 +64,10 @@ class Inventory(IsBoundMixin, Collection):
|
||||
|
||||
class Inventories(HasBoundMixin, Objects):
|
||||
_entity = Inventory
|
||||
var_can_move = False
|
||||
|
||||
@property
|
||||
def var_can_move(self):
|
||||
return False
|
||||
|
||||
def __init__(self, size: int, *args, **kwargs):
|
||||
super(Inventories, self).__init__(*args, **kwargs)
|
||||
@ -92,8 +102,14 @@ class Inventories(HasBoundMixin, Objects):
|
||||
|
||||
class DropOffLocations(PositionMixin, Collection):
|
||||
_entity = DropOffLocation
|
||||
is_blocking_light: bool = False
|
||||
can_collide: bool = False
|
||||
|
||||
@property
|
||||
def is_blocking_light(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def can_collide(self):
|
||||
return False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(DropOffLocations, self).__init__(*args, **kwargs)
|
||||
|
@ -1,4 +1,4 @@
|
||||
from marl_factory_grid.environment.groups.env_objects import Collection
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin
|
||||
|
||||
from .entitites import Machine
|
||||
|
@ -2,7 +2,7 @@ from typing import List
|
||||
|
||||
from .entities import Maintainer
|
||||
from marl_factory_grid.environment.entity.wall_floor import Floor
|
||||
from marl_factory_grid.environment.groups.env_objects import Collection
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.environment.groups.mixins import PositionMixin
|
||||
from ..machines.actions import MachineAction
|
||||
from ...utils.states import Gamestate
|
||||
|
Reference in New Issue
Block a user