mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-12-11 18:10:38 +01:00
no more tiles no more floor
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import abc
|
||||
|
||||
import numpy as np
|
||||
|
||||
from .. import constants as c
|
||||
from .object import EnvObject
|
||||
from ...utils.render import RenderEntity
|
||||
from ...utils.utility_classes import RenderEntity
|
||||
from ...utils.results import ActionResult
|
||||
|
||||
|
||||
@@ -30,33 +32,32 @@ class Entity(EnvObject, abc.ABC):
|
||||
return self._pos
|
||||
|
||||
@property
|
||||
def tile(self):
|
||||
return self._tile # wall_n_floors funktionalität
|
||||
|
||||
# @property
|
||||
# def last_tile(self):
|
||||
# try:
|
||||
# return self._last_tile
|
||||
# except AttributeError:
|
||||
# # noinspection PyAttributeOutsideInit
|
||||
# self._last_tile = None
|
||||
# return self._last_tile
|
||||
def last_pos(self):
|
||||
try:
|
||||
return self._last_pos
|
||||
except AttributeError:
|
||||
# noinspection PyAttributeOutsideInit
|
||||
self._last_pos = c.VALUE_NO_POS
|
||||
return self._last_pos
|
||||
|
||||
@property
|
||||
def direction_of_view(self):
|
||||
last_x, last_y = self._last_pos
|
||||
curr_x, curr_y = self.pos
|
||||
return last_x - curr_x, last_y - curr_y
|
||||
if self._last_pos != c.VALUE_NO_POS:
|
||||
return 0, 0
|
||||
else:
|
||||
return np.subtract(self._last_pos, self.pos)
|
||||
|
||||
def move(self, next_pos, state):
|
||||
next_pos = next_pos
|
||||
curr_pos = self._pos
|
||||
if not_same_pos := curr_pos != next_pos:
|
||||
if valid := state.check_move_validity(self, next_pos):
|
||||
self._pos = next_pos
|
||||
self._last_pos = curr_pos
|
||||
for observer in self.observers:
|
||||
observer.notify_change_pos(self)
|
||||
observer.notify_del_entity(self)
|
||||
self._view_directory = curr_pos[0]-next_pos[0], curr_pos[1]-next_pos[1]
|
||||
self._pos = next_pos
|
||||
for observer in self.observers:
|
||||
observer.notify_add_entity(self)
|
||||
return valid
|
||||
return not_same_pos
|
||||
|
||||
@@ -64,6 +65,7 @@ class Entity(EnvObject, abc.ABC):
|
||||
super().__init__(**kwargs)
|
||||
self._status = None
|
||||
self._pos = pos
|
||||
self._last_pos = pos
|
||||
if bind_to:
|
||||
try:
|
||||
self.bind_to(bind_to)
|
||||
|
||||
Reference in New Issue
Block a user