All Projects → BurnySc2 → Python Sc2

BurnySc2 / Python Sc2

Licence: mit
A StarCraft II bot api client library for Python 3

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Python Sc2

Pengubot
Official PenguBot GitHub Repository
Stars: ✭ 98 (-30.5%)
Mutual labels:  bot, hacktoberfest
Botogram
Just focus on your bots.
Stars: ✭ 106 (-24.82%)
Mutual labels:  bot, hacktoberfest
Ex gram
Telegram Bot API low level API and framework
Stars: ✭ 103 (-26.95%)
Mutual labels:  bot, hacktoberfest
Ex mustang
✨ A simple, clueless bot
Stars: ✭ 67 (-52.48%)
Mutual labels:  bot, hacktoberfest
Madelineproto
Async PHP client/server API for the telegram MTProto protocol
Stars: ✭ 1,776 (+1159.57%)
Mutual labels:  bot, hacktoberfest
Bot
A Discord bot for all your needs. With memes, utilities, moderation & more, Fire is the only bot you'll need.
Stars: ✭ 79 (-43.97%)
Mutual labels:  bot, hacktoberfest
Mygf Instagram
Like posts of my girlfriend's Instagram using web api, don't need any api key and access tokens just login and password
Stars: ✭ 140 (-0.71%)
Mutual labels:  bot, hacktoberfest
Thm Discord Bot
TryHackMe Python Bot
Stars: ✭ 53 (-62.41%)
Mutual labels:  bot, hacktoberfest
Botonomous
A PHP Framework For Creating Autonomous Slack Bots
Stars: ✭ 109 (-22.7%)
Mutual labels:  bot, ai
Dtel
Telephone roleplay bot on Discord
Stars: ✭ 108 (-23.4%)
Mutual labels:  bot, hacktoberfest
Genesis
🤖 Warframe Discord Cephalon
Stars: ✭ 67 (-52.48%)
Mutual labels:  bot, hacktoberfest
Neuro
🔮 Neuro.js is machine learning library for building AI assistants and chat-bots (WIP).
Stars: ✭ 126 (-10.64%)
Mutual labels:  bot, ai
Everydaywechat
微信助手:1.每日定时给好友(女友)发送定制消息。2.机器人自动回复好友。3.群助手功能(例如:查询垃圾分类、天气、日历、电影实时票房、快递物流、PM2.5等)
Stars: ✭ 8,688 (+6061.7%)
Mutual labels:  bot, ai
Slack Machine
A sexy, simple, yet powerful and extendable Slack bot
Stars: ✭ 91 (-35.46%)
Mutual labels:  bot, ai
Dialogflow Angular5
💬 Bot in Angular 5 & DialogFlow
Stars: ✭ 52 (-63.12%)
Mutual labels:  bot, ai
Botacspro Bot Auto checkout Flashsale Shopee Promo
Bot Auto Checkout Flashsale Shopee Promo (Botacs Pro)
Stars: ✭ 107 (-24.11%)
Mutual labels:  bot, ai
Community Bot
The bot used on the TypeScript Community discord server
Stars: ✭ 46 (-67.38%)
Mutual labels:  bot, hacktoberfest
Emotecollector
Collects emotes from other servers for use by people who don't have Nitro
Stars: ✭ 51 (-63.83%)
Mutual labels:  bot, hacktoberfest
Sir Lancebot
A Discord bot started as a community project for Hacktoberfest 2018, later evolved to an introductory project for aspiring new developers starting out with open source development.
Stars: ✭ 105 (-25.53%)
Mutual labels:  bot, hacktoberfest
Discord.js
discord.js is a powerful Node.js module that allows you to easily interact with the Discord API.
Stars: ✭ 16,432 (+11553.9%)
Mutual labels:  bot, hacktoberfest

Actions Status

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.

The documentation can be found here. For bot authors, looking directly at the files in the sc2 folder can also be of benefit: bot_ai.py, unit.py, units.py, client.py, game_info.py and game_state.py. Most functions in those files have docstrings, example usages and type hinting.

I am planning to change this fork more radically than the main repository, for bot performance benefits and to add functions to help new bot authors. This may break older bots in the future, however I try to add deprecationwarnings to give a heads up notification. This means that the video tutorial made by sentdex is outdated and does no longer directly work with this fork.

For a list of ongoing changes and differences to the main repository of Dentosal, check here.

Installation

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

For this fork, you'll need Python 3.7 or newer.

Install the pypi package:

pip install --upgrade burnysc2

or directly from develop branch:

pip install pipenv
pip install --upgrade --force-reinstall https://github.com/BurnySc2/python-sc2/archive/develop.zip

Both commands will use the sc2 library folder, so you will not be able to have Dentosal's and this fork installed at the same time, unless you use virtual environments or pipenv.

StarCraft II

You'll need a 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.

Maps

You probably want some maps too.

Official maps

Official Blizzard map downloads are available from Blizzard/s2client-proto.
Extract these maps into their respective subdirectories in the SC2 maps directory.
e.g. install-dir/Maps/Ladder2017Season1/

Bot ladder maps

Maps that are run on the SC2 AI Ladder and SC2 AI Arena can be downloaded from the sc2ai wiki and the aiarena wiki.
Extract these maps into the root of the SC2 maps directory (otherwise ladder replays won't work).
e.g. install-dir/Maps/AcropolisLE.SC2Map

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

WINE and Lutris

If you installed StarCraft II on Linux with Wine or Lutris, set the following environment variables (either globally or within your development environment, e.g. Pycharm: Run -> Edit Configurations -> Environment Variables):

SC2PF=WineLinux
WINE=usr/bin/wine
# Or a wine binary from lutris:
# WINE=/home/burny/.local/share/lutris/runners/wine/lutris-4.20-x86_64/bin/wine64
# Default Lutris StarCraftII Installation path:
SC2PATH=/home/burny/Games/battlenet/drive_c/Program Files (x86)/StarCraft II/

WSL

WSL version 1 should not require any configuration. You may be asked to allow Python through your firewall.

When running WSL version 2 you need to supply the following environment variables so that your bot can connect:

SC2CLIENTHOST=<your windows IP>
SC2SERVERHOST=0.0.0.0

You can find your Windows IP using ipconfig /all from PowerShell.exe or CMD.exe.

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: int):
        if iteration == 0:
            for worker in self.workers:
                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.

API Configuration Options

The API supports a number of options for configuring how it operates.

unit_command_uses_self_do

Set this to 'True' if your bot is issueing commands using self.do(Unit(Ability, Target)) instead of Unit(Ability, Target).

class MyBot(sc2.BotAI):
    def __init__(self):
        self.unit_command_uses_self_do = True

raw_affects_selection

Setting this to true improves bot performance by a little bit.

class MyBot(sc2.BotAI):
    def __init__(self):
        self.raw_affects_selection = True

distance_calculation_method

The distance calculation method:

  • 0 for raw python
  • 1 for scipy pdist
  • 2 for scipy cdist
class MyBot(sc2.BotAI):
    def __init__(self):
        self.distance_calculation_method: int = 2

game_step

On game start or in any frame actually, you can set the game step. This controls how often your bot's step method is called.
Do not set this in the __init__ function as the client will not have been initialized yet!

class MyBot(sc2.BotAI):
    def __init__(self):
        pass  # don't set it here!

    async def on_start(self):
        self.client.game_step: int = 2

Community - Help and support

You have questions but don't want to create an issue? Join the Starcraft 2 AI Discord server or aiarena.net Discord server. Questions about this repository can be asked in text channel #python. There are discussions and questions about SC2 bot programming and this repository every day.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].