mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-12-13 18:50:38 +01:00
Added option for random dirt positioning
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import ast
|
import ast
|
||||||
|
import random
|
||||||
from marl_factory_grid.environment import constants as c
|
from marl_factory_grid.environment import constants as c
|
||||||
from marl_factory_grid.environment.groups.collection import Collection
|
from marl_factory_grid.environment.groups.collection import Collection
|
||||||
from marl_factory_grid.modules.clean_up.entitites import DirtPile
|
from marl_factory_grid.modules.clean_up.entitites import DirtPile
|
||||||
@@ -33,7 +34,7 @@ class DirtPiles(Collection):
|
|||||||
return sum([dirt.amount for dirt in self])
|
return sum([dirt.amount for dirt in self])
|
||||||
|
|
||||||
def __init__(self, *args, max_local_amount=5, clean_amount=1, max_global_amount: int = 20, coords_or_quantity=10,
|
def __init__(self, *args, max_local_amount=5, clean_amount=1, max_global_amount: int = 20, coords_or_quantity=10,
|
||||||
initial_amount=2, amount_var=0.2, n_var=0.2, **kwargs):
|
initial_amount=2, amount_var=0.2, n_var=0.2, randomize=False, randomization_seed=0, **kwargs):
|
||||||
"""
|
"""
|
||||||
A Collection of dirt piles that triggers their spawn.
|
A Collection of dirt piles that triggers their spawn.
|
||||||
|
|
||||||
@@ -67,6 +68,8 @@ class DirtPiles(Collection):
|
|||||||
self.max_local_amount = max_local_amount
|
self.max_local_amount = max_local_amount
|
||||||
self.coords_or_quantity = coords_or_quantity
|
self.coords_or_quantity = coords_or_quantity
|
||||||
self.initial_amount = initial_amount
|
self.initial_amount = initial_amount
|
||||||
|
self.randomize = randomize
|
||||||
|
self.randomized_selection = None
|
||||||
|
|
||||||
def trigger_spawn(self, state, coords_or_quantity=0, amount=0, ignore_blocking=False) -> [Result]:
|
def trigger_spawn(self, state, coords_or_quantity=0, amount=0, ignore_blocking=False) -> [Result]:
|
||||||
if ignore_blocking:
|
if ignore_blocking:
|
||||||
@@ -85,6 +88,16 @@ class DirtPiles(Collection):
|
|||||||
else:
|
else:
|
||||||
n_new = [pos for pos in coords_or_quantity]
|
n_new = [pos for pos in coords_or_quantity]
|
||||||
|
|
||||||
|
if self.randomize:
|
||||||
|
if not self.randomized_selection:
|
||||||
|
n_new_prime = []
|
||||||
|
for n in n_new:
|
||||||
|
if random.random() < 0.5:
|
||||||
|
n_new_prime.append(n)
|
||||||
|
n_new = n_new_prime
|
||||||
|
self.randomized_selection = n_new
|
||||||
|
else:
|
||||||
|
n_new = self.randomized_selection
|
||||||
amounts = [amount if amount else (self.initial_amount ) # removed rng amount
|
amounts = [amount if amount else (self.initial_amount ) # removed rng amount
|
||||||
for _ in range(len(n_new))]
|
for _ in range(len(n_new))]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user