mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-06-21 11:21:35 +02:00
Machines
This commit is contained in:
@ -0,0 +1,6 @@
|
||||
from .actions import CleanUp
|
||||
from .entitites import DirtPile
|
||||
from .groups import DirtPiles
|
||||
from .rule_respawn import DirtRespawnRule
|
||||
from .rule_smear_on_move import DirtSmearOnMove
|
||||
from .rule_done_on_all_clean import DirtAllCleanDone
|
||||
|
@ -7,6 +7,22 @@ from marl_factory_grid.modules.clean_up import constants as d
|
||||
|
||||
class DirtPile(Entity):
|
||||
|
||||
@property
|
||||
def var_can_collide(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_can_move(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_is_blocking_light(self):
|
||||
return False
|
||||
|
||||
@property
|
||||
def var_has_position(self):
|
||||
return True
|
||||
|
||||
@property
|
||||
def amount(self):
|
||||
return self._amount
|
||||
|
@ -31,7 +31,7 @@ class DirtPiles(PositionMixin, EnvObjects):
|
||||
self.max_global_amount = max_global_amount
|
||||
self.max_local_amount = max_local_amount
|
||||
|
||||
def spawn_dirt(self, then_dirty_tiles, amount) -> bool:
|
||||
def spawn(self, then_dirty_tiles, amount) -> bool:
|
||||
if isinstance(then_dirty_tiles, Floor):
|
||||
then_dirty_tiles = [then_dirty_tiles]
|
||||
for tile in then_dirty_tiles:
|
||||
@ -57,7 +57,7 @@ class DirtPiles(PositionMixin, EnvObjects):
|
||||
var = self.dirt_spawn_r_var
|
||||
new_spawn = abs(self.initial_dirt_ratio + (state.rng.uniform(-var, var) if initial_spawn else 0))
|
||||
n_dirt_tiles = max(0, int(new_spawn * len(free_for_dirt)))
|
||||
return self.spawn_dirt(free_for_dirt[:n_dirt_tiles], self.initial_amount)
|
||||
return self.spawn(free_for_dirt[:n_dirt_tiles], self.initial_amount)
|
||||
|
||||
def __repr__(self):
|
||||
s = super(DirtPiles, self).__repr__()
|
||||
|
@ -11,7 +11,7 @@ class DirtRespawnRule(Rule):
|
||||
self.spawn_freq = spawn_freq
|
||||
self._next_dirt_spawn = spawn_freq
|
||||
|
||||
def on_init(self, state) -> str:
|
||||
def on_init(self, state, lvl_map) -> str:
|
||||
state[d.DIRT].trigger_dirt_spawn(state, initial_spawn=True)
|
||||
return f'Initial Dirt was spawned on: {[x.pos for x in state[d.DIRT]]}'
|
||||
|
||||
|
@ -18,7 +18,7 @@ class DirtSmearOnMove(Rule):
|
||||
if is_move(entity.state.identifier) and entity.state.validity == c.VALID:
|
||||
if old_pos_dirt := state[d.DIRT].by_pos(entity.last_pos):
|
||||
if smeared_dirt := round(old_pos_dirt.amount * self.smear_amount, 2):
|
||||
if state[d.DIRT].spawn_dirt(entity.tile, amount=smeared_dirt):
|
||||
if state[d.DIRT].spawn(entity.tile, amount=smeared_dirt):
|
||||
results.append(TickResult(identifier=self.name, entity=entity,
|
||||
reward=0, validity=c.VALID))
|
||||
return results
|
||||
|
Reference in New Issue
Block a user