PyCommandCenter: Library for making bots for Starcraft II
PyCommandCenter is a slimmed down version of the popular Starcraft AI CommandCenter connected to Python.
Key differences:
- Library made for use with Python, made possible by binding existing C++ code to Python using pybind11
- No decision-making, only perception
- Improved TechTree, by importing data from the JSON files provided by sc2-gamedata
- Everything is built using cmake, allowing for one Visual studio project to build PyCommandCenter together with all its dependencies
Code example for making a bot
from library import *
class DoNothingBot(IDABot):
def __init__(self):
IDABot.__init__(self)
def on_game_start(self):
IDABot.on_game_start(self)
def on_step(self):
IDABot.on_step(self)
def main():
coordinator = Coordinator()
bot1 = DoNothingBot()
participant_1 = create_participants(Race.Terran, bot1)
participant_2 = create_computer(Race.Random, Difficulty.Easy)
coordinator.set_participants([participant_1, participant_2])
coordinator.launch_starcraft()
coordinator.start_game("InterloperTest.SC2Map")
while coordinator.update():
pass
How to build (Windows)
First you need to make sure you got all the build dependencies:
- cmake
- Visual Studio 2017 or later (earlier might work, but untested)
- git
- python 3.6 or later (earlier might work, but untested)
Now, you are ready to build the python library:
- Open up a terminal, download the source code using the command:
git clone --recurse-submodules https://gitlab.ida.liu.se/davbe125/s2-python-api.git
- Next, open the repository in your file viewer and run the batch script
called
create-visual-studio-solution.bat
in order to use cmake to create a Visual studio solution - Open the Visual Studio solution located in the newly created directory
build/
- The project called
library
should be selected as the default StartUp project in the Solution Explorer (on the right side by default) - Change settings to Release and x64
- Click "Local Windows Debugger" and it will start compiling
- Visual Studio will open an error message telling you it cannot open the
resulting library file, which means it successfully created the library
file. The file will be located at
build\python-api-src\Release
and its name will depend on the python version used.
How to build (Linux, untested)
Same dependencies applies as for Windows, although you don't need Visual Studio.
- Open up a terminal, download the source code using the command:
git clone --recurse-submodules https://gitlab.ida.liu.se/davbe125/s2-python-api.git
- Next, enter the directory and run the command
mkdir build
followed bycd build
andcmake ..
in order to create the makefiles needed for building the library. - Run
make
to build the project (usemake -j N
if you want to use N threads)
Credits
CommandCenter is written by David Churchill, Assistant Professor of Computer Science at Memorial University, and organizer of the AIIDE StarCraft AI Competition.
CommandCenter is in turn based on the Blizzard's StarCraft II AI API and the architecture of UAlbertaBot.