Package: marlenv
MarlenvMarlenv is a multi-agent environment for reinforcement learning, based on the OpenAIgymconvention.The function names such as reset(), step() are consistent but the return format is different. Unlike the single agent environments, the multi-agent environments included in this repo formats all returns in a list format, where each element corresponds to each agent in the environment. A similar rule applies to the input action where the action should be a list of actions with a length of number of agents.Marlenv is an ongoing project and modifications and new environments are expected in the future.Installationclone marlenv repo and use pip to installgitclonehttps://github.com/kc-ml2/marlenv.gitcdmarlenv
pipinstall-e.RulesSnake GameMultiple snakes battle on a fixed size grid map.Each snake is spawned at a random location on the map, with a random pose and direction at reset().The map may be initialized with a different walls upon instantiation of the environment.Snake dies when its head hits a wall or body of another snake. Here, the other snake receives a reward for kill and the dead snake receives a reward for death ('lose').When multiple snakes collide head to head, all dies without receiving the kill score.When there is only one snake remaining, it receives a win reward for every unit time of survival.The snake grows by one pixel when it has eatten a fruit.Observation TypesImage grid : The order is'NHWC'Examples Input ArgumentsSnake GameCreating an environmentimportgymimportmarlenvenv=gym.make('Snake-v1',height=20,# Height of the grid mapwidth=20,# Width of the grid mapnum_snakes=4,# Number of snakes to spawn on gridsnake_length=3,# Initial length of the snake at spawn timevision_range=5,# Vision range (both width height), map returned if Noneframe_stack=1,# Number of observations to stack on return)Single-agent wrapperenv=gym.make('Snake-v1',num_snakes=1)env=marlenv.wrappers.SingleAgent(env)This will unwrap the returned the observation, reward, etc from a listUsing the make_snake() function# Automatically chooses wrappers to handle single agent, multi-agent, vector_env, etc.env,observation_space,action_space,properties=marlenv.wrappers.make_snake(num_envs=1,# Number of environments. Used to decided vector env or notnum_snakes=1,# Number of players. Used to determine single/multi agent**kwargs# Other input parameters to the environment)The returned values areenv : The environment objectobservation_space : The processed observation space (according to env type)action_space : The processed action spaceproperties : The properties is a dict that includeshigh: highest value that observation can havelow: lowest value that the observation can havenum_envs: number of environmentsnum_snakes: number of snakes to be spawneddiscrete: True if action space is discrete, categoricalaction_info{action_high, action_low} if continuous action or {action_n} if discreteCustom reward functionThe user can change the reward function structure of the snake-game upon instantiation.The reward function can be defined using python dictionary as the followingcustom_reward_func={'fruit':1.0,'kill':0.0,'lose':0.0,'time':0.0,'win':0.0}env=gym.make('snake-v1',reward_func=custom_reward_func)Each of the each of the keys representfruit : reward received when the snake eats a fruitkill : reward received when the snake kills another snakelose : reward (or penalty) received when the snake diestime : reward received for each unit of time of survivalwin : reward received during the snake's time of survival as the last one standingEach reward can be both + and - float numberTestingpytestCitation@MISC{marlenv2021,author={ML2},title={Marlenv,Multi-agentReinforcementLearningEnvironment},howpublished={\url{http://github.com/kc-ml2/marlenv}},year={2021}}UpdatesCurrently, there is only one environment of multi-agent snake game.