Menu

Starcraft 2 – Artificial Intelligence Bot Army

8th January 2026 - AI, Uncategorised
Starcraft 2 – Artificial Intelligence Bot Army

Around 9 years ago, before all the recent chicanery and LLM love in, deepmind was messing around in video games, and I had a nVidia 960gtx, and was still playing Warcraft 3 and Starcraft 2.

Deepmind released the first version of pySC2 (python Starcraft 2) https://github.com/google-deepmind/pysc2. It doesn’t seem to be actively worked on at the minute, probably because it’s quite mature. The bot making scene on top of Starcraft 2 is still going strength to strength.

Starcraft 2 is now free, and the tournament scene isn’t as massive as it was, but as mentioned the bot scene is quite interesting, with bots averaging 1200-25,000 apm (actions per minute) that’s at least10 times the speed of the best human Starcraft 2 players. They’re fascinating to watch.

Setting up pySC2

The basic setup of pySC2 is a bridge application, which hooks into the network code of Starcraft2, and the agent bots, that use a python script to determine how to behave.

  1. Clone the pySC2 git repository https://github.com/google-deepmind/pysc2

If you have any issues with pyGame, then it’s because it relies on packages which were deprecated in python in version 3.10, then removed by 3.13. Create a virtual environment which uses python 3.10

If you still have problems, welcome to OSS development (snark). Try the following;

At which point pip install --upgrade pysc2/ should work without any wheel issues.. Note that I cloned the pysc2 library so I could edit it if I wanted.

2) Download Starcraft 2 via battle.net and complete the first few levels to activate the multiplayer mode.

Once installed, take a note of the Starcraft 2 installation directory, mine is D:\bn\StarCraft II

Smash a few zerg, then enable multiplayer and quit.

3) Now download all the maps you need and export into the maps folder of your starcraft install. The zip password is ‘iagreetotheeula‘ and they can be found at https://github.com/Blizzard/s2client-proto?tab=readme-ov-file#downloads

I downloaded the following maps and copied them to my Starcraft II/Maps folder

4) Now lets test that everything is set up correctly

As ever, if it fails, it usually means a package needs downgrading

After which, check whether it can see the maps.

All my maps were shown, so we’re good.

5) Now, the moment of truth, try and run a simple game

To run a zerg versus a human, run the following.

But oh no! I installed starcraft in a non-normal location.. I need to update SC2PATH in my virtual environment activation script .venv/scripts/activate.bat or activate.ps1 Either way, change, deactivate venv and activate it again then run.

Note: There may be a Fixed extra_ports bug in .venv\lib\site-packages\pysc2\lib\sc_process.py: This parameter wasn’t valid for subprocess.Popen() Added kwargs.pop(‘extra_ports’, None) before passing to subprocess.Popen()

A simpler start command is

Helper Script

Creating a launcher means you can now concentrate on creating a bot and running the script rather than a monster command line.

Creating a Terran agent ai bot

A bot template must have a defined interface based on the BaseAgent class (pysc2/agents/base_agent.py)

This extremely simple code would create a passive agent that just sits and picks its nose while Zerg picks over its bones.

For more information, see some of the examples online.

https://a01701804.medium.com/build-a-reinforcement-learning-terran-agent-with-pysc2-2-0-framework-c6be51b13d48

Training models

To create a learning model and more complex agents, you may need to install the dev version of pySC2 and create an environment for reinforcement learning, as well as have access to a Machine learning library and for ease of use, CUDA.

https://medium.com/data-science/create-a-customized-gym-environment-for-star-craft-2-8558d301131f

  1. Reward System Structure: PySC2 returns TimeStep(step_type, reward, discount, observation) with scalar rewards (0 on first step)
  2. Built-in Reward Types: Game score (score_index >= 0), win/loss (score_index = -1), or custom map-specific rewards via score_index
  3. Automatic Reward Tracking: BaseAgent automatically accumulates rewards in self.reward, accessible via obs.reward at each timestep
  4. RL Framework Integration: PySC2 works with standard libraries – Stable Baselines3 (PPO/DQN), TensorFlow (tf-agents/dopamine), and Ray/RLlib
  5. Custom Gym Environment: Create OpenAI Gym wrapper using gym.envs.registration.register() to integrate with any RL framework
  6. Environment Configuration: Control training with step_mul (8-22 normal speed), feature_dimensions (64×64 recommended), and game_steps_per_episode (0 = until win/loss)
  7. Custom Reward Functions: Override rewards by calculating based on game state – minerals collected, army size, buildings constructed, combat results, penalties for attacks
  8. Training Loop Structure: Reset environment → execute actions → get observations → train model → repeat until episode ends (win/loss/time limit)
  9. Popular RL Algorithms: PPO (best balance), DQN (discrete actions), A3C (faster learning), SAC (continuous actions) – PPO recommended for StarCraft II
  10. Monitoring & Visualization: Use TensorBoard for logging training progress, track metrics like win rate, APM, resource management, and combat effectiveness

LLM agents as Starcraft agent

There’s an interesting arxiv paper which details the thinking behind a LLM agent for StarCraft. LLM agents are very slow compared to trained models, so they’re not comparable to other trained models.
https://arxiv.org/html/2411.05348v2

I may come back and craft some silly agents, but I hope this helps others get started with a more colourful introduction to machine learning.

Leave a Reply