object and objects are now private

This commit is contained in:
Chanumask
2023-10-23 16:44:03 +02:00
parent e87bd3aaa0
commit c4ffdb4e44
11 changed files with 30 additions and 30 deletions

View File

@@ -3,13 +3,13 @@ from collections import defaultdict
import numpy as np import numpy as np
from .object import Object from .object import _Object
from .. import constants as c from .. import constants as c
from ...utils.results import ActionResult from ...utils.results import ActionResult
from ...utils.utility_classes import RenderEntity from ...utils.utility_classes import RenderEntity
class Entity(Object, abc.ABC): class Entity(_Object, abc.ABC):
"""Full Env Entity that lives on the environment Grid. Doors, Items, DirtPile etc...""" """Full Env Entity that lives on the environment Grid. Doors, Items, DirtPile etc..."""
_u_idx = defaultdict(lambda: 0) _u_idx = defaultdict(lambda: 0)

View File

@@ -4,7 +4,7 @@ from typing import Union
from marl_factory_grid.environment import constants as c from marl_factory_grid.environment import constants as c
class Object: class _Object:
"""Generell Objects for Organisation and Maintanance such as Actions etc...""" """Generell Objects for Organisation and Maintanance such as Actions etc..."""
_u_idx = defaultdict(lambda: 0) _u_idx = defaultdict(lambda: 0)
@@ -66,8 +66,8 @@ class Object:
return hash(self.identifier) return hash(self.identifier)
def _identify_and_count_up(self): def _identify_and_count_up(self):
idx = Object._u_idx[self.__class__.__name__] idx = _Object._u_idx[self.__class__.__name__]
Object._u_idx[self.__class__.__name__] += 1 _Object._u_idx[self.__class__.__name__] += 1
return idx return idx
def set_collection(self, collection): def set_collection(self, collection):
@@ -92,7 +92,7 @@ class Object:
return self._bound_entity == entity return self._bound_entity == entity
class EnvObject(Object): class EnvObject(_Object):
"""Objects that hold Information that are observable, but have no position on the environment grid. Inventories etc...""" """Objects that hold Information that are observable, but have no position on the environment grid. Inventories etc..."""
_u_idx = defaultdict(lambda: 0) _u_idx = defaultdict(lambda: 0)

View File

@@ -3,7 +3,7 @@ import math
import numpy as np import numpy as np
from marl_factory_grid.environment.entity.mixin import BoundEntityMixin from marl_factory_grid.environment.entity.mixin import BoundEntityMixin
from marl_factory_grid.environment.entity.object import Object, EnvObject from marl_factory_grid.environment.entity.object import _Object, EnvObject
########################################################################## ##########################################################################
@@ -11,7 +11,7 @@ from marl_factory_grid.environment.entity.object import Object, EnvObject
########################################################################## ##########################################################################
class PlaceHolder(Object): class PlaceHolder(_Object):
def __init__(self, *args, fill_value=0, **kwargs): def __init__(self, *args, fill_value=0, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@@ -30,7 +30,7 @@ class PlaceHolder(Object):
return "PlaceHolder" return "PlaceHolder"
class GlobalPosition(Object): class GlobalPosition(_Object):
@property @property
def encoding(self): def encoding(self):

View File

@@ -1,8 +1,8 @@
from marl_factory_grid.environment.groups.objects import Objects from marl_factory_grid.environment.groups.objects import _Objects
from marl_factory_grid.environment.entity.object import EnvObject from marl_factory_grid.environment.entity.object import EnvObject
class Collection(Objects): class Collection(_Objects):
_entity = EnvObject _entity = EnvObject
@property @property

View File

@@ -3,12 +3,12 @@ from operator import itemgetter
from random import shuffle from random import shuffle
from typing import Dict from typing import Dict
from marl_factory_grid.environment.groups.objects import Objects from marl_factory_grid.environment.groups.objects import _Objects
from marl_factory_grid.utils.helpers import POS_MASK from marl_factory_grid.utils.helpers import POS_MASK
class Entities(Objects): class Entities(_Objects):
_entity = Objects _entity = _Objects
@staticmethod @staticmethod
def neighboring_positions(pos): def neighboring_positions(pos):

View File

@@ -3,12 +3,12 @@ from typing import List
import numpy as np import numpy as np
from marl_factory_grid.environment.entity.object import Object from marl_factory_grid.environment.entity.object import _Object
import marl_factory_grid.environment.constants as c import marl_factory_grid.environment.constants as c
class Objects: class _Objects:
_entity = Object _entity = _Object
@property @property
def observers(self): def observers(self):
@@ -129,8 +129,8 @@ class Objects:
self.add_items([self._entity() for _ in range(n)]) self.add_items([self._entity() for _ in range(n)])
return c.VALID return c.VALID
def despawn(self, items: List[Object]): def despawn(self, items: List[_Object]):
items = [items] if isinstance(items, Object) else items items = [items] if isinstance(items, _Object) else items
for item in items: for item in items:
del self[item] del self[item]
@@ -145,7 +145,7 @@ class Objects:
# except (ValueError, AttributeError): # except (ValueError, AttributeError):
# pass # pass
def notify_del_entity(self, entity: Object): def notify_del_entity(self, entity: _Object):
try: try:
entity.del_observer(self) entity.del_observer(self)
except AttributeError: except AttributeError:
@@ -155,7 +155,7 @@ class Objects:
except (AttributeError, ValueError, IndexError): except (AttributeError, ValueError, IndexError):
pass pass
def notify_add_entity(self, entity: Object): def notify_add_entity(self, entity: _Object):
try: try:
if self not in entity.observers: if self not in entity.observers:
entity.add_observer(self) entity.add_observer(self)

View File

@@ -5,7 +5,7 @@ import numpy as np
from marl_factory_grid.environment.entity.util import GlobalPosition from marl_factory_grid.environment.entity.util import GlobalPosition
from marl_factory_grid.environment.groups.collection 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.mixins import PositionMixin, HasBoundMixin
from marl_factory_grid.environment.groups.objects import Objects from marl_factory_grid.environment.groups.objects import _Objects
from marl_factory_grid.modules.zones import Zone from marl_factory_grid.modules.zones import Zone
from marl_factory_grid.utils import helpers as h from marl_factory_grid.utils import helpers as h
from marl_factory_grid.environment import constants as c from marl_factory_grid.environment import constants as c

View File

@@ -1,11 +1,11 @@
from marl_factory_grid.environment import constants as c from marl_factory_grid.environment import constants as c
from marl_factory_grid.environment.entity.entity import Entity from marl_factory_grid.environment.entity.entity import Entity
from marl_factory_grid.environment.entity.object import Object from marl_factory_grid.environment.entity.object import _Object
from marl_factory_grid.modules.batteries import constants as b from marl_factory_grid.modules.batteries import constants as b
from marl_factory_grid.utils.utility_classes import RenderEntity from marl_factory_grid.utils.utility_classes import RenderEntity
class Battery(Object): class Battery(_Object):
@property @property
def var_can_be_bound(self): def var_can_be_bound(self):

View File

@@ -4,7 +4,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 import constants as c
from marl_factory_grid.environment.groups.collection 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.objects import _Objects
from marl_factory_grid.environment.groups.mixins import PositionMixin, IsBoundMixin, HasBoundMixin from marl_factory_grid.environment.groups.mixins import PositionMixin, IsBoundMixin, HasBoundMixin
from marl_factory_grid.environment.entity.agent import Agent from marl_factory_grid.environment.entity.agent import Agent
from marl_factory_grid.modules.items.entitites import Item, DropOffLocation from marl_factory_grid.modules.items.entitites import Item, DropOffLocation
@@ -65,7 +65,7 @@ class Inventory(IsBoundMixin, Collection):
self._collection = collection self._collection = collection
class Inventories(HasBoundMixin, Objects): class Inventories(HasBoundMixin, _Objects):
_entity = Inventory _entity = Inventory
@property @property

View File

@@ -1,10 +1,10 @@
import random import random
from typing import List, Tuple from typing import List, Tuple
from marl_factory_grid.environment.entity.object import Object from marl_factory_grid.environment.entity.object import _Object
class Zone(Object): class Zone(_Object):
@property @property
def positions(self): def positions(self):

View File

@@ -1,8 +1,8 @@
from marl_factory_grid.environment.groups.objects import Objects from marl_factory_grid.environment.groups.objects import _Objects
from marl_factory_grid.modules.zones import Zone from marl_factory_grid.modules.zones import Zone
class Zones(Objects): class Zones(_Objects):
symbol = None symbol = None
_entity = Zone _entity = Zone