mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-07-05 17:11:35 +02:00
Merge branch 'main' into refactor_rename
# Conflicts: # marl_factory_grid/modules/clean_up/groups.py # marl_factory_grid/modules/clean_up/rules.py # marl_factory_grid/modules/destinations/rules.py
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
from marl_factory_grid.environment import constants as c
|
||||
from marl_factory_grid.utils.results import Result
|
||||
from marl_factory_grid.environment.groups.collection import Collection
|
||||
from marl_factory_grid.modules.clean_up.entitites import DirtPile
|
||||
|
||||
@ -27,42 +28,44 @@ class DirtPiles(Collection):
|
||||
return sum([dirt.amount for dirt in self])
|
||||
|
||||
def __init__(self, *args,
|
||||
initial_amount=2,
|
||||
initial_dirt_ratio=0.05,
|
||||
dirt_spawn_r_var=0.1,
|
||||
max_local_amount=5,
|
||||
clean_amount=1,
|
||||
max_global_amount: int = 20, **kwargs):
|
||||
super(DirtPiles, self).__init__(*args, **kwargs)
|
||||
self.clean_amount = clean_amount
|
||||
self.initial_amount = initial_amount
|
||||
self.initial_dirt_ratio = initial_dirt_ratio
|
||||
self.dirt_spawn_r_var = dirt_spawn_r_var
|
||||
self.max_global_amount = max_global_amount
|
||||
self.max_local_amount = max_local_amount
|
||||
|
||||
def spawn(self, then_dirty_positions, amount) -> bool:
|
||||
for pos in then_dirty_positions:
|
||||
def spawn(self, then_dirty_positions, amount_s) -> Result:
|
||||
spawn_counter = 0
|
||||
for idx, pos in enumerate(then_dirty_positions):
|
||||
if not self.amount > self.max_global_amount:
|
||||
amount = amount_s[idx] if isinstance(amount_s, list) else amount_s
|
||||
if dirt := self.by_pos(pos):
|
||||
new_value = dirt.amount + amount
|
||||
dirt.set_new_amount(new_value)
|
||||
else:
|
||||
dirt = DirtPile(pos, initial_amount=amount, spawn_variation=self.dirt_spawn_r_var)
|
||||
dirt = DirtPile(pos, amount=amount)
|
||||
self.add_item(dirt)
|
||||
spawn_counter += 1
|
||||
else:
|
||||
return c.NOT_VALID
|
||||
return c.VALID
|
||||
return Result(identifier=f'{self.name}_spawn', validity=c.NOT_VALID, reward=0,
|
||||
value=spawn_counter)
|
||||
return Result(identifier=f'{self.name}_spawn', validity=c.VALID, reward=0, value=spawn_counter)
|
||||
|
||||
def trigger_dirt_spawn(self, state, initial_spawn=False) -> bool:
|
||||
def trigger_dirt_spawn(self, n, amount, state, n_var=0.2, amount_var=0.2) -> Result:
|
||||
free_for_dirt = [x for x in state.entities.floorlist if len(state.entities.pos_dict[x]) == 1 or (
|
||||
len(state.entities.pos_dict[x]) == 2 and isinstance(next(y for y in x), DirtPile))]
|
||||
len(state.entities.pos_dict[x]) == 2 and isinstance(next(y for y in x), DirtPile))]
|
||||
# free_for_dirt = [x for x in state[c.FLOOR]
|
||||
# if len(x.guests) == 0 or (
|
||||
# len(x.guests) == 1 and
|
||||
# isinstance(next(y for y in x.guests), DirtPile))]
|
||||
state.rng.shuffle(free_for_dirt)
|
||||
|
||||
var = self.dirt_spawn_r_var
|
||||
new_spawn = abs(self.initial_dirt_ratio + (state.rng.uniform(-var, var) if initial_spawn else 0))
|
||||
n_dirty_positions = max(0, int(new_spawn * len(free_for_dirt)))
|
||||
return self.spawn(free_for_dirt[:n_dirty_positions], self.initial_amount)
|
||||
new_spawn = int(abs(n + (state.rng.uniform(-n_var, n_var))))
|
||||
new_amount_s = [abs(amount + (amount*state.rng.uniform(-amount_var, amount_var))) for _ in range(new_spawn)]
|
||||
n_dirty_positions = free_for_dirt[:new_spawn]
|
||||
return self.spawn(n_dirty_positions, new_amount_s)
|
||||
|
||||
def __repr__(self):
|
||||
s = super(DirtPiles, self).__repr__()
|
||||
|
Reference in New Issue
Block a user