• Stars
    star
    582
  • Rank 74,163 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A StarCraft II bot api client library for Python 3

This repository is no longer maintained and may not work with the latest version of the StarCraft 2 client. You can use this fork instead which aims to stay updated for both the latest windows StarCraft 2 client and latest linux client, while also being available on pypi.org.

A StarCraft II API Client for Python 3

An easy-to-use library for writing AI Bots for StarCraft II in Python 3. The ultimate goal is simplicity and ease of use, while still preserving all functionality. A really simple worker rush bot should be no more than twenty lines of code, not two hundred. However, this library intends to provide both high and low level abstractions.

This library (currently) covers only the raw scripted interface. At this time I don't intend to add support for graphics-based interfaces.

Documentation is in the Wiki.

For automatically running multiple matches, check out Dentosal/sc2-bot-match-runner.

Installation

By installing this library you agree to be bound by the terms of the AI and Machine Learning License.

You'll need Python 3.6 or newer.

pip3 install --user --upgrade sc2

Please note that not all commits are released to PyPI. Releases are tagged with version number. You can see latest released versions from tags page.

You'll also need an StarCraft II executable. If you are running Windows or macOS, just install the normal SC2 from blizzard app. The free starter edition works too.. Linux users get the best experience by installing the Windows version of StarCraft II with Wine. Linux user can also use the Linux binary, but it's headless so you cannot actually see the game.

You probably want some maps too. Official map downloads are available from Blizzard/s2client-proto. Notice: the map files are to be extracted into subdirectories of the install-dir/Maps directory.

Running

After installing the library, a StarCraft II executable, and some maps, you're ready to get started. Simply run a bot file to fire up an instance of StarCraft II with the bot running. For example:

python3 examples/protoss/cannon_rush.py

If you installed StarCraft II on Linux with Wine, set the SC2PF environment variable to WineLinux:

SC2PF=WineLinux python3 examples/protoss/cannon_rush.py

Example

As promised, worker rush in less than twenty lines:

import sc2
from sc2 import run_game, maps, Race, Difficulty
from sc2.player import Bot, Computer

class WorkerRushBot(sc2.BotAI):
    async def on_step(self, iteration):
        if iteration == 0:
            for worker in self.workers:
                await self.do(worker.attack(self.enemy_start_locations[0]))

run_game(maps.get("Abyssal Reef LE"), [
    Bot(Race.Zerg, WorkerRushBot()),
    Computer(Race.Protoss, Difficulty.Medium)
], realtime=True)

This is probably the simplest bot that has any realistic chances of winning the game. I have ran it against the medium AI a few times, and once in a while it wins.

You can find more examples in the examples/ folder.

Help and support

You have questions but don't want to create an issue? Join the Starcraft 2 AI Discord. Questions about this repository can be asked in channel #python-sc2.

Bug reports, feature requests and ideas

If you have any issues, ideas or feedback, please create a new issue. Pull requests are also welcome!

Contributing & style guidelines

Git commit messages use imperative-style messages, start with capital letter and do not have trailing commas.

More Repositories

1

rust_os

My hobby operating system microkernel written in Rust
Rust
39
star
2

portpicker-rs

Pick a free unused port
Rust
38
star
3

autogui-rs

GUI automation toolkit for Rust
Rust
20
star
4

sc2-bot-match-runner

Automatically run matches between StarCraft 2 bots
Python
17
star
5

sc2-techtree

SC2 tech tree as JSON data + a Rust library
Python
12
star
6

isolated-rs

Linux process isolation using namespaces and pivot_root jail
Rust
8
star
7

python-sc2-bot-template

A template for developing competitive bots using python-sc2 library
Python
6
star
8

wsl-rs

Detect if the program is running under Windows Subsystem for Linux
Rust
5
star
9

pinecone

Minimalistic serde format supporting no_std + alloc
Rust
5
star
10

allogator

A collection of allocators for Rust, usable for operating system development
Rust
4
star
11

SieniRTS

Sienestystรค tuubassa...
C++
2
star
12

vpass

Opinionated password manager
Rust
2
star
13

cargo-recursive

A cargo subcommand for running a command in all subdirectories recursively
Rust
2
star
14

hepta-lang

Hepta programming language
Rust
2
star
15

IFEngine

Engine for interactive fiction written in Python 2
Python
1
star
16

minilisp

Lisp distilled, more than enough
Rust
1
star
17

pico-upload

Minimal file upload service
Rust
1
star
18

linux-job-runner

A simple job runner server for Linux hosts
Rust
1
star
19

sc2-proxy

StarCraft II bot API management layer
Rust
1
star
20

reregex

Minimal regex engine
Rust
1
star
21

tcpstate

Abstract TCP socket implementation in Rust
Rust
1
star
22

compiler-bootstrap

Bootstrapping a compiler from scratch
Assembly
1
star
23

rts-game

Yet another RTS game
Rust
1
star
24

brain-opt

Optimizing BrainFuck compiler
Rust
1
star
25

ImbaPython

Extending Python 3 by patching built in types
Python
1
star
26

StackVM

Simple stack-based virtual machine
Python
1
star
27

fatimg-rs

Command line tool for reading and writing FAT filesystem images
Rust
1
star
28

raytracer-rs

SImple raytracer written in Rust
Rust
1
star
29

constcodegen

Share constants between languages
Rust
1
star
30

pygressbar

A simple python library for displaying text-based progress bars
Python
1
star
31

SimpleChat

A simple in-browser chat using Python, Flask, Redis, Javascript and jQuery
Python
1
star
32

c4ai

Connect4 AI using (pure) Monte Carlo tree search
Rust
1
star
33

cpuio-rs

Raw CPU port IO
Rust
1
star
34

python-htmlhl

Python syntax analyzer that produces highlighted code in html format
HTML
1
star