本文介绍了如何在OpenAI中创建新的健身环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我分配了一个AI代理,该代理将学习使用ML玩视频游戏.我想使用OpenAI Gym创建新环境,因为我不想使用现有环境.如何创建新的自定义环境?

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?

而且,在没有OpenAI Gym的帮助下,我还有其他方法可以使AI Agent玩特定的视频游戏吗?

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

推荐答案

请参阅我的 banana-gym 在非常小的环境中.

See my banana-gym for an extremely small environment.

请参见存储库的主页:

https://github.com/openai/gym/blob/master/docs/creating-environments.md

步骤是:

  1. 使用PIP打包结构创建新的存储库

它应该看起来像这样

gym-foo/
  README.md
  setup.py
  gym_foo/
    __init__.py
    envs/
      __init__.py
      foo_env.py
      foo_extrahard_env.py

有关其内容,请单击上面的链接.这里没有提到的细节尤其是foo_env.py中的某些功能的外观.查看示例,并在 gym.openai.com/docs/中提供帮助.这是一个示例:

For the contents of it, follow the link above. Details which are not mentioned there are especially how some functions in foo_env.py should look like. 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):
        """

        Parameters
        ----------
        action :

        Returns
        -------
        ob, reward, episode_over, info : tuple
            ob (object) :
                an environment-specific object representing your observation of
                the environment.
            reward (float) :
                amount of reward achieved by the previous action. The scale
                varies between environments, but the goal is always to increase
                your total reward.
            episode_over (bool) :
                whether it's time to reset the environment again. Most (but not
                all) tasks are divided up into well-defined episodes, and done
                being True indicates the episode has terminated. (For example,
                perhaps the pole tipped too far, or you lost your last life.)
            info (dict) :
                 diagnostic information useful for debugging. It can sometimes
                 be useful for learning (for example, it might contain the raw
                 probabilities behind the environment's last state change).
                 However, official evaluations of your agent are not allowed to
                 use this for learning.
        """
        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

使用您的环境

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

示例

  1. https://github.com/openai/gym-soccer
  2. https://github.com/openai/gym-wikinav
  3. https://github.com/alibaba/gym-starcraft
  4. https://github.com/endgameinc/gym-malware
  5. https://github.com/hackthemarket/gym-trading
  6. https://github.com/tambetm/gym-minecraft
  7. https://github.com/ppaquette/gym-doom
  8. https://github.com/ppaquette/gym-super-mario
  9. https://github.com/tuzzer/gym-maze
  1. https://github.com/openai/gym-soccer
  2. https://github.com/openai/gym-wikinav
  3. https://github.com/alibaba/gym-starcraft
  4. https://github.com/endgameinc/gym-malware
  5. https://github.com/hackthemarket/gym-trading
  6. https://github.com/tambetm/gym-minecraft
  7. https://github.com/ppaquette/gym-doom
  8. https://github.com/ppaquette/gym-super-mario
  9. https://github.com/tuzzer/gym-maze

这篇关于如何在OpenAI中创建新的健身环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-07 18:26