Starcraft II environment and library for training agents.
Project description
Fork Notice
This project is a fork of the original PySC2. The original PySC2 project seems to be no longer actively maintained. The goal of this project is to modernize PySC2 as PySC2_Evolved and to add new features and improvements over the original project. Please note that the changes may be heavily opinionated, but nonetheless, the aim is to support the original interfaces as closely as possible.
PySC2_Evolved - StarCraft II Learning Environment
It exposes Blizzard Entertainment's StarCraft II Machine Learning API as a Python RL Environment. This is a collaboration between DeepMind and Blizzard to develop StarCraft II into a rich environment for RL research. PySC2 provides an interface for RL agents to interact with StarCraft 2, getting observations and sending actions.
We have published an accompanying blogpost and paper, which outlines our motivation for using StarCraft II for DeepRL research, and some initial research results using the environment.
Quick Start Guide
Get PySC2_Evolved
PyPI
The easiest way to get PySC2_Evolved is to use pip:
$ pip install pysc2_evolved
That will install the pysc2_evolved package along with all the required dependencies.
virtualenv can help manage your
dependencies. You may also need to upgrade pip: pip install --upgrade pip
for the pysc2_evolved install to work. If you're running on an older system you may
need to install libsdl libraries for the pygame dependency.
Pip will install a few of the binaries to your bin directory. pysc2_play can
be used as a shortcut to python -m pysc2_evolved.bin.play.
From Source
Alternatively you can install latest PySC2_Evolved codebase from git master branch:
$ pip install --upgrade https://github.com/Kaszanas/pysc2_evolved/archive/master.zip
or from a local clone of the git repo:
$ git clone https://github.com/Kaszanas/pysc2_evolved.git
$ pip install --upgrade pysc2_evolved/
Get StarCraft II
PySC2_Evolved depends on the full StarCraft II game and only works with versions that include the API, which is 3.16.1 and above.
Linux
Follow Blizzard's documentation to
get the linux version. By default, PySC2_Evolved expects the game to live in
~/StarCraftII/. You can override this path by setting the SC2PATH
environment variable or creating your own run_config.
Windows/MacOS
Install of the game as normal from Battle.net. Even the
Starter Edition will work.
If you used the default install location PySC2_Evolved should find the latest binary.
If you changed the install location, you might need to set the SC2PATH
environment variable with the correct location.
PySC2_Evolved should work on MacOS and Windows systems running Python 3.8+, but has only been thoroughly tested on Linux. We welcome suggestions and patches for better compatibility with other systems.
Get the maps
PySC2_Evolved has many maps pre-configured, but they need to be downloaded into the SC2
Maps directory before they can be played.
Download the ladder maps
and the mini games
and extract them to your StarCraftII/Maps/ directory.
Run an agent
You can run an agent to test the environment. The UI shows you the actions of the agent and is helpful for debugging and visualization purposes.
$ python -m pysc2_evolved.bin.agent --map_name Simple64
It runs a random agent by default, but you can specify others if you'd like, including your own.
$ python -m pysc2_evolved.bin.agent --map_name CollectMineralShards --agent pysc2_evolved.agents.scripted_agent.CollectMineralShards
You can also run two agents against each other.
$ python -m pysc2_evolved.bin.agent --map_name Simple64 --agent2 pysc2_evolved.agents.random_agent.RandomAgent
To specify the agent's race, the opponent's difficulty, and more, you can pass
additional flags. Run with --help to see what you can change.
Play the game as a human
There is a human agent interface which is mainly used for debugging, but it can also be used to play the game. The UI is fairly simple and incomplete, but it's enough to understand the basics of the game. Also, it runs on Linux.
$ python -m pysc2_evolved.bin.play --map_name Simple64
In the UI, hit ? for a list of the hotkeys. The most basic ones are: F4 to
quit, F5 to restart, F8 to save a replay, and Pgup/Pgdn to control the
speed of the game. Otherwise use the mouse for selection and keyboard for
commands listed on the left.
The left side is a basic rendering. The right side is the feature layers that the agent receives, with some coloring to make it more useful to us. You can enable or disable RGB or feature layer rendering and their resolutions with command-line flags.
Watch a replay
Running an agent and playing as a human save a replay by default. You can watch that replay by running:
$ python -m pysc2_evolved.bin.play --replay <path-to-replay>
This works for any replay as long as the map can be found by the game.
The same controls work as for playing the game, so F4 to exit, pgup/pgdn
to control the speed, etc.
You can save a video of the replay with the --video flag.
List the maps
Maps need to be configured before they're known to the environment. You can see the list of known maps by running:
$ python -m pysc2_evolved.bin.map_list
Run the tests
If you want to submit a pull request, please make sure the tests pass.
Python tests
Requires a StarCraft II installation (set SC2PATH if non-default):
$ python -m pysc2_evolved.bin.run_tests
Individual test files can be run directly with pytest:
$ python -m pytest src/pysc2_evolved/lib/point_test.py
C++ converter tests
The C++ converter (env/converter/) is built and tested via Bazel.
Bazelisk is required — it reads
.bazelversion and downloads the correct Bazel binary automatically.
Docker-based (no local Bazelisk required):
Build the dev image once, then run tests or the build inside the container:
$ make docker_build_dev
$ make bazel_test_converter # runs C++ tests inside the container
$ make bazel_build_converter # builds converter.so inside the container
Install Bazelisk (one-time, for local builds):
$ curl -Lo /usr/local/bin/bazelisk \
https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64
$ chmod +x /usr/local/bin/bazelisk
Run all C++ unit tests:
$ make bazel_test_converter_local
# or directly:
$ bazelisk test //src/pysc2_evolved/env/converter/cc:all --test_output=errors
Build the converter .so extension only:
$ make bazel_build_converter_local
# or directly:
$ bazelisk build //src/pysc2_evolved/env/converter/cc/python:converter
The compiled extension is written to
bazel-bin/src/pysc2_evolved/env/converter/cc/python/converter.so.
# Environment Details
For a full description of the specifics of how the environment is configured,
the observations and action spaces work read the
[environment documentation](docs/environment.md).
Note that an alternative to this environment is now available which provides
an enriched action and observation format using the C++ wrappers developed
for AlphaStar. See [the converter documentation](docs/converters.md) for more
information.
# Mini-game maps
The mini-game map files referenced in the paper are stored under `pysc2_evolved/maps/`
but must be installed in `$SC2PATH/Maps`. Make sure to follow the download
instructions above.
Maps are configured in the Python files in `pysc2_evolved/maps/`. The configs can set
player and time limits, whether to use the game outcome or curriculum score, and
a handful of other things. For more information about the maps, and how to
configure your own, read the [maps documentation](docs/maps.md).
# Replays
A replay lets you review what happened during a game. You can see the actions
and observations that each player made as they played.
Blizzard is releasing a large number of anonymized 1v1 replays played on the
ladder. You can find instructions for how to get the
[replay files](https://github.com/Blizzard/s2client-proto#downloads) on their
site. You can also review your own replays.
Replays can be played back to get the observations and actions made during that
game. The observations are rendered at the resolution you request, so may differ
from what the human actually saw. Similarly the actions specify a point, which
could reflect a different pixel on the human's screen, so may not have an exact
match in our observations, though they should be fairly similar.
Replays are version dependent, so a 3.16 replay will fail in a 3.16.1 or 3.17
binary.
You can visualize the replays with the full game, or with `pysc2_evolved.bin.play`.
Alternatively you can run `pysc2_evolved.bin.replay_actions` to process many replays
in parallel.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pysc2_evolved-1.1.1.tar.gz.
File metadata
- Download URL: pysc2_evolved-1.1.1.tar.gz
- Upload date:
- Size: 1.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
181aafdd2ffcf72e245cf317c48f4c57eb4b3b0ad80e8d1310d9244b9ec3579a
|
|
| MD5 |
ffdd0ac827200c25c7089f4b2e82c14d
|
|
| BLAKE2b-256 |
aed93a54955555c3719c47c4158025417cac37e953de6b1e5320e079253b98db
|
Provenance
The following attestation bundles were made for pysc2_evolved-1.1.1.tar.gz:
Publisher:
release.yml on Kaszanas/pysc2_evolved
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysc2_evolved-1.1.1.tar.gz -
Subject digest:
181aafdd2ffcf72e245cf317c48f4c57eb4b3b0ad80e8d1310d9244b9ec3579a - Sigstore transparency entry: 1332207323
- Sigstore integration time:
-
Permalink:
Kaszanas/pysc2_evolved@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Branch / Tag:
refs/tags/1.1.1 - Owner: https://github.com/Kaszanas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pysc2_evolved-1.1.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: pysc2_evolved-1.1.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 4.2 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca8adc010980052d6df5de31f668ed68b480b50e038a05de83316deab630503b
|
|
| MD5 |
5acd6e013ec571a0f8a4919e58ba0289
|
|
| BLAKE2b-256 |
596c636d5d11226701e896939a3f5f5cc87963d0974ea7fbaf4d34318e870a16
|
Provenance
The following attestation bundles were made for pysc2_evolved-1.1.1-cp313-cp313-win_amd64.whl:
Publisher:
release.yml on Kaszanas/pysc2_evolved
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysc2_evolved-1.1.1-cp313-cp313-win_amd64.whl -
Subject digest:
ca8adc010980052d6df5de31f668ed68b480b50e038a05de83316deab630503b - Sigstore transparency entry: 1332208073
- Sigstore integration time:
-
Permalink:
Kaszanas/pysc2_evolved@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Branch / Tag:
refs/tags/1.1.1 - Owner: https://github.com/Kaszanas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pysc2_evolved-1.1.1-cp313-cp313-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: pysc2_evolved-1.1.1-cp313-cp313-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.13, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
912c709577a5797ba9781238a3deb0f7cc55aaa567b3362fea7944a893485263
|
|
| MD5 |
bd060dde9dea4ccef972d0655af84550
|
|
| BLAKE2b-256 |
053ee5d095e0a6e6efbc924f250c40186e862f0b5082e5fbc3af9d611ca04a35
|
Provenance
The following attestation bundles were made for pysc2_evolved-1.1.1-cp313-cp313-manylinux_2_39_x86_64.whl:
Publisher:
release.yml on Kaszanas/pysc2_evolved
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysc2_evolved-1.1.1-cp313-cp313-manylinux_2_39_x86_64.whl -
Subject digest:
912c709577a5797ba9781238a3deb0f7cc55aaa567b3362fea7944a893485263 - Sigstore transparency entry: 1332208196
- Sigstore integration time:
-
Permalink:
Kaszanas/pysc2_evolved@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Branch / Tag:
refs/tags/1.1.1 - Owner: https://github.com/Kaszanas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pysc2_evolved-1.1.1-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: pysc2_evolved-1.1.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 4.2 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14a310a7cfcad646b9078e5bb4a8b839ac951fca73794cbb65095cf9dd234e5e
|
|
| MD5 |
920e1afe0e6d2a74b48bbb8e1a7df2be
|
|
| BLAKE2b-256 |
d248afced9c270bd54f39d8778d6d052514a1f3029f03d036a7a99720e8fd6e4
|
Provenance
The following attestation bundles were made for pysc2_evolved-1.1.1-cp312-cp312-win_amd64.whl:
Publisher:
release.yml on Kaszanas/pysc2_evolved
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysc2_evolved-1.1.1-cp312-cp312-win_amd64.whl -
Subject digest:
14a310a7cfcad646b9078e5bb4a8b839ac951fca73794cbb65095cf9dd234e5e - Sigstore transparency entry: 1332207914
- Sigstore integration time:
-
Permalink:
Kaszanas/pysc2_evolved@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Branch / Tag:
refs/tags/1.1.1 - Owner: https://github.com/Kaszanas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pysc2_evolved-1.1.1-cp312-cp312-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: pysc2_evolved-1.1.1-cp312-cp312-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.12, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3052fc513e6fcc9ef30599f03af6711110c518856ec27288697c1d67dcf457c6
|
|
| MD5 |
e00504aa1d01d54de10031a70de07728
|
|
| BLAKE2b-256 |
131090019b0f0d00b6152ac9d729c12f79c32d741e9e0d5bd527f70b1c3c91b1
|
Provenance
The following attestation bundles were made for pysc2_evolved-1.1.1-cp312-cp312-manylinux_2_39_x86_64.whl:
Publisher:
release.yml on Kaszanas/pysc2_evolved
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysc2_evolved-1.1.1-cp312-cp312-manylinux_2_39_x86_64.whl -
Subject digest:
3052fc513e6fcc9ef30599f03af6711110c518856ec27288697c1d67dcf457c6 - Sigstore transparency entry: 1332207639
- Sigstore integration time:
-
Permalink:
Kaszanas/pysc2_evolved@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Branch / Tag:
refs/tags/1.1.1 - Owner: https://github.com/Kaszanas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pysc2_evolved-1.1.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: pysc2_evolved-1.1.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 4.2 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c70e76aef476f51aabec34c4403755eb1082122d46477adf88adc717983f336
|
|
| MD5 |
b41c1579785a37c36f5fba60abe5ae06
|
|
| BLAKE2b-256 |
446c4cb7e505c6937a877174e9a90193ef7a22cc6a086655d2778025337d3560
|
Provenance
The following attestation bundles were made for pysc2_evolved-1.1.1-cp311-cp311-win_amd64.whl:
Publisher:
release.yml on Kaszanas/pysc2_evolved
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysc2_evolved-1.1.1-cp311-cp311-win_amd64.whl -
Subject digest:
9c70e76aef476f51aabec34c4403755eb1082122d46477adf88adc717983f336 - Sigstore transparency entry: 1332207743
- Sigstore integration time:
-
Permalink:
Kaszanas/pysc2_evolved@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Branch / Tag:
refs/tags/1.1.1 - Owner: https://github.com/Kaszanas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pysc2_evolved-1.1.1-cp311-cp311-manylinux_2_39_x86_64.whl.
File metadata
- Download URL: pysc2_evolved-1.1.1-cp311-cp311-manylinux_2_39_x86_64.whl
- Upload date:
- Size: 6.5 MB
- Tags: CPython 3.11, manylinux: glibc 2.39+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3089097d88b03425d97ad539e276a24558f39b3b5b6f4d63d285c739df9f481e
|
|
| MD5 |
14a5134ad218b401c03aedf9e0fda33f
|
|
| BLAKE2b-256 |
3bc428187ff544e3ef697382b06ff33617c64a1a4af9a8500b428f321b5ac490
|
Provenance
The following attestation bundles were made for pysc2_evolved-1.1.1-cp311-cp311-manylinux_2_39_x86_64.whl:
Publisher:
release.yml on Kaszanas/pysc2_evolved
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pysc2_evolved-1.1.1-cp311-cp311-manylinux_2_39_x86_64.whl -
Subject digest:
3089097d88b03425d97ad539e276a24558f39b3b5b6f4d63d285c739df9f481e - Sigstore transparency entry: 1332207484
- Sigstore integration time:
-
Permalink:
Kaszanas/pysc2_evolved@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Branch / Tag:
refs/tags/1.1.1 - Owner: https://github.com/Kaszanas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6a3042ddd2e85f5af25e764a43f4a62580acb0b8 -
Trigger Event:
release
-
Statement type: