How to create a custom gym environment with multiple agents

Mathieu Cesbron
Analytics Vidhya
Published in
6 min readDec 20, 2019

--

You want to create a custom environments with multiple agents ? You have seen the Open AI video where agents collaborate to hide & seek and want to do something similar ?

OpenAI’s gym is by far the best packages to create a custom reinforcement learning environment. It comes with some pre-built environnments, but it also allow us to create complex custom environments. An environment contains all the necessary functionality to run agents and allow them to learn.

In this tutoarial we will create a custom environment with multiple agents. We wills stick to a really simple environment to focus on the agents. May be we will see interesting things happening like collaboration of agents.

All of the code for this article is available on my GitHub.

The custom environment

Our environment will be a Maze. We will create 2 agents that try to find the exit of the maze (let’s keep it simple at first). Each Agent will take turns to move.

0: An empty area, The agents can go there

1: Agent 1 who will try to find the exit

2: Agent 2 who will also try to find the exit

3: Traps, if an agent go there, he loose the game

--

--