WIP: removing tiles

This commit is contained in:
Chanumask
2023-09-26 10:35:41 +02:00
parent 04af996232
commit 3bf3246aeb
12 changed files with 60 additions and 65 deletions

View File

@@ -71,7 +71,7 @@ class PodRules(Rule):
def on_init(self, state, lvl_map):
pod_collection = state[b.CHARGE_PODS]
empty_tiles = state[c.FLOOR].empty_tiles[:self.n_pods]
pods = pod_collection.from_tiles(empty_tiles, entity_kwargs=dict(
pods = pod_collection.from_coordinates(empty_tiles, entity_kwargs=dict(
multi_charge=self.multi_charge, charge_rate=self.charge_rate)
)
pod_collection.add_items(pods)

View File

@@ -48,4 +48,4 @@ class DirtPile(Entity):
return state_dict
def render(self):
return RenderEntity(d.DIRT, self.tile.pos, min(0.15 + self.amount, 1.5), 'scale')
return RenderEntity(d.DIRT, self.pos, min(0.15 + self.amount, 1.5), 'scale')

View File

@@ -29,7 +29,7 @@ class ItemAction(Action):
elif items := state[i.ITEM].by_pos(entity.pos):
item = items[0]
item.change_parent_collection(inventory)
item.set_tile_to(state.NO_POS_TILE)
item.set_pos_to(c.VALUE_NO_POS)
state.print(f'{entity.name} just picked up an item at {entity.pos}')
return ActionResult(entity=entity, identifier=self._identifier, validity=c.VALID, reward=r.PICK_UP_VALID)

View File

@@ -11,7 +11,7 @@ class Item(Entity):
var_can_collide = False
def render(self):
return RenderEntity(i.ITEM, self.tile.pos) if self.pos != c.VALUE_NO_POS else None
return RenderEntity(i.ITEM, self.pos) if self.pos != c.VALUE_NO_POS else None
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -29,8 +29,8 @@ class Item(Entity):
def set_auto_despawn(self, auto_despawn):
self._auto_despawn = auto_despawn
def set_tile_to(self, no_pos_tile):
self._tile = no_pos_tile
def set_pos_to(self, no_pos):
self._pos = no_pos
def summarize_state(self) -> dict:
super_summarization = super(Item, self).summarize_state()
@@ -57,7 +57,7 @@ class DropOffLocation(Entity):
return True
def render(self):
return RenderEntity(i.DROP_OFF, self.tile.pos)
return RenderEntity(i.DROP_OFF, self.pos)
@property
def encoding(self):

View File

@@ -1,5 +1,5 @@
import random
from typing import List
from typing import List, Tuple
from marl_factory_grid.environment.entity.entity import Entity
from marl_factory_grid.environment.entity.object import Object
@@ -14,12 +14,12 @@ class Zone(Object):
@property
def positions(self):
return [x.pos for x in self.tiles]
return self.coords
def __init__(self, tiles: List[Floor], *args, **kwargs):
def __init__(self, coords: List[Tuple[(int, int)]], *args, **kwargs):
super(Zone, self).__init__(*args, **kwargs)
self.tiles = tiles
self.coords = coords
@property
def random_tile(self):
return random.choice(self.tiles)
return random.choice(self.coords)