Gym Minecraft
This project is outdated, please use MalmoEnv instead.
Gym Minecraft is an environment bundle for OpenAI Gym. It is based on Microsoft's Malmö, which is a platform for Artificial Intelligence experimentation and research built on top of Minecraft.
Basically these are original Malmö missions with only <PrioritiseOffscreenRendering>
added to speed up training.
Installation
-
Install the dependencies for your OS: Windows, Linux, MacOSX. You can skip Torch, Mono and ALE parts.
-
Install OpenAI Gym and its dependencies.
pip install gym
- Download and install minecraft_py.
git clone https://github.com/tambetm/minecraft-py.git
cd minecraft-py
# NB! `minecraft_py` should be installed to writable user directory, either in virtualenv or with `--user` option.
python setup.py install
- Download and install
gym-minecraft
:
git clone https://github.com/tambetm/gym-minecraft.git
cd gym-minecraft
python setup.py install
gym-minecraft
needs pygame
to render Minecraft screen. It is best to have pygame installed via your system commands, i.e. sudo apt-get install python-pygame
or conda install pygame
. Otherwise setup will automatically download and compile pygame
. This might need some additional dependencies though, see instructions for Ubuntu, OSX or Windows.
- Run once following snippet:
import logging
logging.basicConfig(level=logging.DEBUG)
import minecraft_py
proc, port = minecraft_py.start()
minecraft_py.stop(proc)
Basically Minecraft downloads and compiles everything on first start, this snippet just starts minecraft_py
in debug mode, so you can see when Minecraft gets stuck.
Running
import gym
import gym_minecraft
env = gym.make('MinecraftBasic-v0')
env.init(start_minecraft=True)
env.reset()
done = False
while not done:
env.render()
action = env.action_space.sample()
obs, reward, done, info = env.step(action)
env.close()
NB! Running Minecraft for the first time might take a while as it downloads and compiles itself. Next time the startup time should be shorter, but still around 30 seconds. In active development phase you might want to start one permanent Minecraft process in background and remove start_minecraft=True
, see wiki.
Overriding default settings
The default settings for environments might not be optimal for you. Luckily you can easily override them using init()
.
For example to use discrete actions instead of continuous actions:
env = gym.make('MinecraftBasic-v0')
env.init(allowDiscreteMovement=["move", "turn"])
To use continuous actions instead of discrete actions:
env = gym.make('MinecraftBasic-v0')
env.init(allowContinuousMovement=["move", "turn"])
To use different video resolution:
env = gym.make('MinecraftBasic-v0')
env.init(videoResolution=[40, 30])
More documentation about configuration options is in wiki.