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
from .object import Object
from .object import _Object
from .. import constants as c
from ...utils.results import ActionResult
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..."""
_u_idx = defaultdict(lambda: 0)

View File

@ -4,7 +4,7 @@ from typing import Union
from marl_factory_grid.environment import constants as c
class Object:
class _Object:
"""Generell Objects for Organisation and Maintanance such as Actions etc..."""
_u_idx = defaultdict(lambda: 0)
@ -66,8 +66,8 @@ class Object:
return hash(self.identifier)
def _identify_and_count_up(self):
idx = Object._u_idx[self.__class__.__name__]
Object._u_idx[self.__class__.__name__] += 1
idx = _Object._u_idx[self.__class__.__name__]
_Object._u_idx[self.__class__.__name__] += 1
return idx
def set_collection(self, collection):
@ -92,7 +92,7 @@ class Object:
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..."""
_u_idx = defaultdict(lambda: 0)

View File

@ -3,7 +3,7 @@ import math
import numpy as np
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):
super().__init__(*args, **kwargs)
@ -30,7 +30,7 @@ class PlaceHolder(Object):
return "PlaceHolder"
class GlobalPosition(Object):
class GlobalPosition(_Object):
@property
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
class Collection(Objects):
class Collection(_Objects):
_entity = EnvObject
@property

View File

@ -3,12 +3,12 @@ from operator import itemgetter
from random import shuffle
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
class Entities(Objects):
_entity = Objects
class Entities(_Objects):
_entity = _Objects
@staticmethod
def neighboring_positions(pos):

View File

@ -3,12 +3,12 @@ from typing import List
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
class Objects:
_entity = Object
class _Objects:
_entity = _Object
@property
def observers(self):
@ -129,8 +129,8 @@ class Objects:
self.add_items([self._entity() for _ in range(n)])
return c.VALID
def despawn(self, items: List[Object]):
items = [items] if isinstance(items, Object) else items
def despawn(self, items: List[_Object]):
items = [items] if isinstance(items, _Object) else items
for item in items:
del self[item]
@ -145,7 +145,7 @@ class Objects:
# except (ValueError, AttributeError):
# pass
def notify_del_entity(self, entity: Object):
def notify_del_entity(self, entity: _Object):
try:
entity.del_observer(self)
except AttributeError:
@ -155,7 +155,7 @@ class Objects:
except (AttributeError, ValueError, IndexError):
pass
def notify_add_entity(self, entity: Object):
def notify_add_entity(self, entity: _Object):
try:
if self not in entity.observers:
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.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.environment.groups.objects import _Objects
from marl_factory_grid.modules.zones import Zone
from marl_factory_grid.utils import helpers as h
from marl_factory_grid.environment import constants as c