mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-06-26 05:01:36 +02:00
WIP: removing tiles
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
from typing import List
|
||||
from typing import List, Tuple
|
||||
|
||||
from marl_factory_grid.environment import constants as c
|
||||
from marl_factory_grid.environment.entity.entity import Entity
|
||||
@ -6,14 +6,13 @@ from marl_factory_grid.environment.entity.wall_floor import Floor
|
||||
|
||||
|
||||
class PositionMixin:
|
||||
|
||||
_entity = Entity
|
||||
var_is_blocking_light: bool = True
|
||||
var_can_collide: bool = True
|
||||
var_has_position: bool = True
|
||||
|
||||
def spawn(self, tiles: List[Floor]):
|
||||
self.add_items([self._entity(tile) for tile in tiles])
|
||||
def spawn(self, coords: List[Tuple[(int, int)]]): # runde klammern?
|
||||
self.add_items([self._entity(pos) for pos in coords])
|
||||
|
||||
def render(self):
|
||||
return [y for y in [x.render() for x in self] if y is not None]
|
||||
@ -33,10 +32,6 @@ class PositionMixin:
|
||||
entity_kwargs=entity_kwargs,
|
||||
**kwargs)
|
||||
|
||||
@property
|
||||
def tiles(self):
|
||||
return [entity.tile for entity in self]
|
||||
|
||||
def __delitem__(self, name):
|
||||
idx, obj = next((i, obj) for i, obj in enumerate(self) if obj.name == name)
|
||||
obj.tile.leave(obj)
|
||||
|
@ -126,12 +126,17 @@ class Objects:
|
||||
del self[item]
|
||||
|
||||
def notify_change_pos(self, entity: object):
|
||||
# print("notifychange")
|
||||
try:
|
||||
# print("lastpos")
|
||||
# print(self.pos_dict[entity.last_pos])
|
||||
self.pos_dict[entity.last_pos].remove(entity)
|
||||
except (ValueError, AttributeError):
|
||||
pass
|
||||
if entity.var_has_position:
|
||||
try:
|
||||
# print("pos")
|
||||
# print(self.pos_dict[entity.pos])
|
||||
self.pos_dict[entity.pos].append(entity)
|
||||
except (ValueError, AttributeError):
|
||||
pass
|
||||
|
@ -51,10 +51,9 @@ class Floors(Walls):
|
||||
|
||||
@property
|
||||
def empty_tiles(self) -> List[Floor]:
|
||||
# def empty_tiles(self) -> List[Tuple[int, int]]:
|
||||
tiles = [tile for tile in self if tile.is_empty()]
|
||||
# positions = [tile.pos for tile in self if tile.is_empty()]
|
||||
random.shuffle(tiles)
|
||||
return tiles
|
||||
|
||||
@classmethod
|
||||
def from_tiles(cls, tiles, *args, **kwargs):
|
||||
raise RuntimeError()
|
||||
|
Reference in New Issue
Block a user