Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cor3bit committed Jan 21, 2021
1 parent a66007c commit 6062f3a
Show file tree
Hide file tree
Showing 12 changed files with 712 additions and 0 deletions.
55 changes: 55 additions & 0 deletions ma_gym/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import logging

from gym import envs
from gym.envs.registration import register

logger = logging.getLogger(__name__)

# Register openai's environments as multi agent
# This should be done before registering new environments
env_specs = [env_spec for env_spec in envs.registry.all() if 'gym.envs' in env_spec.entry_point]
for spec in env_specs:
register(
id='ma_' + spec.id,
entry_point='ma_gym.envs.openai:MultiAgentWrapper',
kwargs={'name': spec.id, **spec._kwargs}
)

for game_info in [[(5, 5), 2, 1], [(7, 7), 4, 2]]: # [(grid_shape, predator_n, prey_n),..]
grid_shape, n_agents, n_preys = game_info
_game_name = 'PredatorPrey{}x{}'.format(grid_shape[0], grid_shape[1])
register(
id='{}-v0'.format(_game_name),
entry_point='ma_gym.envs.predator_prey:PredatorPrey',
kwargs={
'grid_shape': grid_shape, 'n_agents': n_agents, 'n_preys': n_preys
}
)
# fully -observable ( each agent sees observation of other agents)
register(
id='{}-v1'.format(_game_name),
entry_point='ma_gym.envs.predator_prey:PredatorPrey',
kwargs={
'grid_shape': grid_shape, 'n_agents': n_agents, 'n_preys': n_preys, 'full_observable': True
}
)

# prey is initialized at random location and thereafter doesn't move
register(
id='{}-v2'.format(_game_name),
entry_point='ma_gym.envs.predator_prey:PredatorPrey',
kwargs={
'grid_shape': grid_shape, 'n_agents': n_agents, 'n_preys': n_preys,
'prey_move_probs': [0, 0, 0, 0, 1]
}
)

# full observability + prey is initialized at random location and thereafter doesn't move
register(
id='{}-v3'.format(_game_name),
entry_point='ma_gym.envs.predator_prey:PredatorPrey',
kwargs={
'grid_shape': grid_shape, 'n_agents': n_agents, 'n_preys': n_preys, 'full_observable': True,
'prey_move_probs': [0, 0, 0, 0, 1]
}
)
Empty file added ma_gym/envs/__init__.py
Empty file.
1 change: 1 addition & 0 deletions ma_gym/envs/predator_prey/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .predator_prey import PredatorPrey
Loading

0 comments on commit 6062f3a

Please sign in to comment.