added changes from code submission branch and coin entity

This commit is contained in:
Chanumask
2024-09-06 11:01:42 +02:00
parent 33e40deecf
commit 5476f617c6
42 changed files with 1429 additions and 68 deletions

View File

@@ -1,4 +1,5 @@
import ast
import random
from marl_factory_grid.environment import constants as c
from marl_factory_grid.environment.groups.collection import Collection
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])
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.
@@ -67,6 +68,8 @@ class DirtPiles(Collection):
self.max_local_amount = max_local_amount
self.coords_or_quantity = coords_or_quantity
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]:
if ignore_blocking:
@@ -85,7 +88,17 @@ class DirtPiles(Collection):
else:
n_new = [pos for pos in coords_or_quantity]
amounts = [amount if amount else (self.initial_amount ) # removed rng amount
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
for _ in range(len(n_new))]
spawn_counter = 0