PySC2 OpenAI Gym Environments
OpenAI Gym Environments for the StarCraft II PySC2 environment.
After cloning the repository, you can use the environments in
one of two ways:
PYTHON_PATH
pip install -e .
If you use the first option, you need to manually make sure the
dependencies are installed.
The second option will install the package into your pip
environment
as a link to the directory, so it will reflect the changes when
you git pull
or make any changes to the code.
You need the following minimum code to run any environment:
Import gym and this package:
import gym
import sc2gym.envs
Import and initialize absl.flags: (this is due to pysc2
dependency)
import sys
from absl import flags
FLAGS = flags.FLAGS
FLAGS(sys.argv)
Create and initialize the specific environment as indicated in the
next section.
The full StarCraft II game environment. Initialize as follows:
env = gym.make('SC2Game-v0')
env.settings['map_name'] = '<desired map name>'
Versions:
SC2Game-v0
: The full game with complete access to action andThe action space for this environment doesn’t require the call tofunctionCall
like pysc2
does. You just need to call it with an
array of action and arguments. For example:
_SELECT_ARMY = actions.FUNCTIONS.select_army.id
_SELECT_ALL = [0]
env.step([_SELECT_ARMY, _SELECT_ALL])
It will check the first element in the array (the action) and make
sure it’s available before trying to pass it along to the
pysc2
environment.
observation_space
andaction_space
members like traditional gym
environments. Instead,observation_spec
and action_spec
objectspysc2
environment.The MoveToBeacon mini game. Initialize as follows:
env = gym.make('SC2MoveToBeacon-v0')
Versions:
[1, 64, 64]
numpyobs.observation['screen'][_PLAYER_RELATIVE]
pysc2
observation. The action is a number[1, 64, 64]
numpyobs.observation['screen'][_PLAYER_RELATIVE]
pysc2
observation. The action is an array ofThe CollectMineralShards mini game. Initialize as follows:
env = gym.make('SC2CollectMineralShards-v0')
Versions:
[1, 64, 64]
numpyobs.observation['screen'][_PLAYER_RELATIVE]
pysc2
observation. The action is a number[1, 64, 64]
numpyobs.observation['screen'][_PLAYER_RELATIVE]
pysc2
observation. The action is an array of[2, 64, 64]
numpyobs.observation['screen'][_PLAYER_RELATIVE]
obs.observation['screen'][_SELECTED]
planes from the pysc2
step()
and reset()
, the environments define asave_replay()
method, that takes a single parameter, replay_dir
,StarCraft II/Replays/
folder.action_spec
and observation_spec
properties,action_space
and observation_space
properties definedepisode
: The current episode numbernum_step
: The total number of steps takenepisode_reward
: The total reward received this episodetotal_reward
: The total reward received for all episodes
Copyright 2017 Islam Elnabarawy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.