mirror of
https://github.com/illiumst/marl-factory-grid.git
synced 2025-06-19 10:52:54 +02:00

# Conflicts: # marl_factory_grid/environment/actions.py # marl_factory_grid/environment/entity/entity.py # marl_factory_grid/environment/factory.py # marl_factory_grid/modules/batteries/rules.py # marl_factory_grid/modules/clean_up/groups.py # marl_factory_grid/modules/destinations/entitites.py # marl_factory_grid/modules/destinations/groups.py # marl_factory_grid/modules/destinations/rules.py # marl_factory_grid/modules/items/rules.py # marl_factory_grid/modules/maintenance/entities.py # marl_factory_grid/utils/config_parser.py # marl_factory_grid/utils/level_parser.py # marl_factory_grid/utils/states.py
32 lines
980 B
Python
32 lines
980 B
Python
import random
|
|
from typing import List, Union
|
|
|
|
from marl_factory_grid.environment.rules import Rule
|
|
from marl_factory_grid.environment import constants as c
|
|
from marl_factory_grid.utils.results import TickResult
|
|
|
|
|
|
class AgentSingleZonePlacementBeta(Rule):
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def on_init(self, state, lvl_map):
|
|
zones = state[c.ZONES]
|
|
n_zones = state[c.ZONES]
|
|
agents = state[c.AGENT]
|
|
if len(self.coordinates) == len(agents):
|
|
coordinates = self.coordinates
|
|
elif len(self.coordinates) > len(agents):
|
|
coordinates = random.choices(self.coordinates, k=len(agents))
|
|
else:
|
|
raise ValueError
|
|
tiles = [state[c.FLOORS].by_pos(pos) for pos in coordinates]
|
|
for agent, tile in zip(agents, tiles):
|
|
agent.move(tile, state)
|
|
|
|
def tick_step(self, state):
|
|
return []
|
|
|
|
def tick_post_step(self, state) -> List[TickResult]:
|
|
return [] |