Skip to main content

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 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 CollectMineralShards --agent pysc2_evolved.agents.scripted_agent.CollectMineralShards

You can also run two agents against each other.

$ python -m pysc2_evolved.bin.agent --map 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 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysc2_evolved-1.0.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pysc2_evolved-1.0.0-cp313-cp313-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.13Windows x86-64

pysc2_evolved-1.0.0-cp313-cp313-manylinux_2_39_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

pysc2_evolved-1.0.0-cp312-cp312-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.12Windows x86-64

pysc2_evolved-1.0.0-cp312-cp312-manylinux_2_39_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

pysc2_evolved-1.0.0-cp311-cp311-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.11Windows x86-64

pysc2_evolved-1.0.0-cp311-cp311-manylinux_2_39_x86_64.whl (6.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.39+ x86-64

File details

Details for the file pysc2_evolved-1.0.0.tar.gz.

File metadata

  • Download URL: pysc2_evolved-1.0.0.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

Hashes for pysc2_evolved-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cbbea35256db8816901914e09a27f3bc6d6a36e3547f28db35e81916fd05d057
MD5 08c4901c89cdd91eb6446bc5a1980ffb
BLAKE2b-256 dd20cb13dd81a3fac90363d00a9f1d2deb86dabb847795e465186604b98f17f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysc2_evolved-1.0.0.tar.gz:

Publisher: release.yml on Kaszanas/pysc2_evolved

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pysc2_evolved-1.0.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pysc2_evolved-1.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3a8234dc134a01f6bc6a7f6d73134795f45ea8d73b8baac1263271ea8078a258
MD5 b5f66f4583b9c1ec8148a65c5d22088c
BLAKE2b-256 8a83a753af59d3f23402916d9afec7a5b5ae456745ffc16a2c1183e2079c637d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysc2_evolved-1.0.0-cp313-cp313-win_amd64.whl:

Publisher: release.yml on Kaszanas/pysc2_evolved

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pysc2_evolved-1.0.0-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for pysc2_evolved-1.0.0-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 7ca7720af31444218df2145ea924f683de6154b8b28fc90d8cf4918b68babf56
MD5 d76ecaf89b8a01f4309f8c9eb71ff763
BLAKE2b-256 aebf465b5ec765b8d69899e377fc588c944ee920f539bc292272d02e4258685e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysc2_evolved-1.0.0-cp313-cp313-manylinux_2_39_x86_64.whl:

Publisher: release.yml on Kaszanas/pysc2_evolved

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pysc2_evolved-1.0.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pysc2_evolved-1.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 bacd07cd65f5158eb2d7ad42706dd89d5a39371925e1ab6c9cec4a8d7a70671d
MD5 bbb755d5ef37e67946bf01eae341780b
BLAKE2b-256 fcf9ebfbd384bcd8e6d315b2b74471fc15c09fb7c6e378dd64021776bbdf7792

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysc2_evolved-1.0.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on Kaszanas/pysc2_evolved

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pysc2_evolved-1.0.0-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for pysc2_evolved-1.0.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 1d7b1b45b2e35d74a8922567ba8d2399555ba9007371a0ab7157cb5a6164c90a
MD5 9e5574c0f707077c0f03db1173a81410
BLAKE2b-256 a31a9c70c7e26b923dabb4e7f0c83b3472ce9e9463c35bee4b20fce63c255622

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysc2_evolved-1.0.0-cp312-cp312-manylinux_2_39_x86_64.whl:

Publisher: release.yml on Kaszanas/pysc2_evolved

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pysc2_evolved-1.0.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pysc2_evolved-1.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 31984cfa8e573c29a29a8c7c5253cf3642b06bf4109619c58f69bacf1f4bd80c
MD5 6a8bf45e0538f3b37a2f171886238f2d
BLAKE2b-256 60834bdc9b09d138cb675fafc00fca78f65b46775e8879a74a395661e2489904

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysc2_evolved-1.0.0-cp311-cp311-win_amd64.whl:

Publisher: release.yml on Kaszanas/pysc2_evolved

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pysc2_evolved-1.0.0-cp311-cp311-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for pysc2_evolved-1.0.0-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 949a17915910c5f38a1dad66b80af7b2bab746dc14e272cb91e571d7a7df44d5
MD5 9588af2f337c07cc94d342e14267377b
BLAKE2b-256 920b87ab6a577e8ad3c3fda41c7b2d2dbbfc3662376e4ff139089bda4ab2002c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysc2_evolved-1.0.0-cp311-cp311-manylinux_2_39_x86_64.whl:

Publisher: release.yml on Kaszanas/pysc2_evolved

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page