0 votes
1 view
in Machine Learning by (17.4k points)

I have an assignment to make an AI Agent that will learn play a video game using ML. I want to create a new environment using OpenAI Gym because I don't want to use an existing environment. How can I create a new, custom, Environment?

Also, is there any other way that I can start to develop making AI Agent play a specific video game without the help of OpenAI Gym?

1 Answer

0 votes
by (33.2k points)

See my gym for an extremely small environment.

To create new environments

Create a new repository with a PIP-package structure

It should look like this

gym-foo/

  README.md

  setup.py

  gym_foo/

    __init__.py

    envs/

      __init__.py

      foo_env.py

      Foo_extrahard_env.py

Looking at examples and at gym.openai.com/docs/ helps. Here is an example:

class FooEnv(gym.Env):

    metadata = {'render.modes': ['human']}

    def __init__(self):

        pass

    def _step(self, action):

        self._take_action(action)

        self.status = self.env.step()

        reward = self._get_reward()

        ob = self.env.getState()

        episode_over = self.status != hfo_py.IN_GAME

        return ob, reward, episode_over, {}

    def _reset(self):

        pass

    def _render(self, mode='human', close=False):

        pass

    def _take_action(self, action):

        pass

    def _get_reward(self):

        """ Reward is given for XY. """

        if self.status == FOOBAR:

            return 1

        elif self.status == ABC:

            return self.somestate ** 2

        else:

            return 0

Use your environment

import gym

import gym_foo

env = gym.make('MyEnv-v0')

The above code will create a gym environment in OpenAI.

Hope this answer helps.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...