StarCraft II : Computer Vs AI-Bot

Devashi Choudhary
6 min readJul 27, 2020

Real-Time Strategy(RTS) games are a kind of video game which are emerging as a strong domain in Artificial Intelligence (AI). When we analyze these games, strong human minds can defeat artificial agents. The structure of most of the RTS games like Age of Empires, Warcraft, Starcraft, and many more are very complex and consist of many modules like Build Orders, Collecting Resources, Managing Army, etc for unit control and strategy selection. These modules implement different AI mechanisms and interact with each other. Thus, the article aims to build AI Bot for starcraft game, where our AI bot plays against other players, or computers.

Table of Content

  1. Basic Terminologies and Flow of Game.
  2. Collecting Resources (minerals)
  3. Building Workers
  4. Building Pylons
  5. Expanding Resource Area
  6. Collecting Resources (Gas)
  7. Building AI Army
  8. Commanding AI Army
  9. Take Away
  10. What’s Next

Basic Terminologies and Flow of Game

Before moving to the flow of game, let’s understand some basic terminologies of game which we are going to use.

  1. RACE : In StarCraft II, there are 3 “races:” Terran, Protoss, and Zerg. The Protoss are more technology/robotics-based, so we have used that.
  2. NEXUS : It is the “command center” for the Protoss race.
  3. PROBES : The Protoss Race that we are using have “workers” and they are called Probes.
  4. PYLONS : Units which are allowed to produce(units, as in workers, fighters, ships…etc).
  5. PSIONIC MATRIX : It is a term that refers to the circular matrix that extends outwards from a Protoss Pylon which allows to produce units and research upgrades.
  6. VESPENE GEYSERS : If is a building which is used for harvesting the gas.
  7. ASSIMILATOR : The Protoss race, the building we need to harvest the gas i.e. for collecting the gas Assimilator is used.
  8. GATEWAY : It is a unit production structure for the Protoss, responsible for warping in ground units. Gateways can be warped in by a Probe only within range of the Psionic Matrix, and only if the player controls a Nexus. Like most Protoss structures, the Gateway can only function if it remains within the Matrix, otherwise it becomes unpowered.
  9. CYBERNETICS CORE : It sometimes referred to as Cyber Core or just Core which is a structure on the Protoss Technology Tree, which requires a Gateway before it can be warped in. The Cybernetics Core unlocks new units and the Shield Battery building, and enables research of several upgrades.
  10. STALKER or VOID-RAY : It is army unit. The stalker is a ground unit, but it can engage ground and air forces. The Void Ray is an air unit that can engage both ground and air. The Void Ray is slightly more complex to build, and takes longer.

Flow of Game

Collecting Resources, Build Building and Build Army

Collecting Resources (minerals)

In the strategic game, we want to amass an army and annihilate our enemies. For that, we need resources and in starcraft, that’s are gas and minerals. For collecting minerals, we need to mine them with probes. We will start with some probes and at every mineral patch we allow 3 probes to collect minerals. We have inbuilt function distribute_workers in sc2.BotAI to perform jobs.

The async keyword is used to make these asynchronous methods, so we don’t need to wait on each one to complete to be doing other things and we are using AbyssalReefLE map.

Collecting Resources (minerals)

Building Workers

Now, we’d like to get more workers so we can get supplies faster. If we want more workers for collecting resources then we have to build them. We need to use the NEXUS building (Command Center).

Building Pylons

Now, for increasing supply we need to build more pylons, near NEXUS building which is basically how many units we’re allowed to have produced (units, as in workers, fighters, ships…etc). If our remaining supply is ’n’ or less, then we want to build more pylons. The Protoss class requires you to build your buildings within the “Psionic Matrix” zone. Pylons extend this matrix and increase your supply.

Building Workers and Building Pylons

Expanding Resource Area

Collecting resources from one area will slow down the process of collecting minerals so, we need to expand out. Expanding the new resource area means you’re spreading your defenses thinner. In the above case, we’re limiting our expansions to just 2 locations.

Collecting Resources (Gas)

Now, we need to collect the gas, which is harvested from the Vespene Geysers located around the map. We are having a nexus per major resource area and geysers are available near nexus. Once we find the geyser that is close to Nexus then, the building is built on the top of the geyser. The assimilator is for collecting gas. Next, we also need to select one of our workers who are close to this so, we don’t waste much time.

Expanding Resource Area and Collecting Resources (Gas)

Building AI Army

Now, We have 2 command center areas and a fast-growing resource collection. Next, we need to focus on what’s required to build our army. The path to the Stalker is Nexus > Gateway > Cybernetics Core > Stalker. You will still produce your fighting units from the Gateway. You only need one Cybernetics Core (and hope it doesn’t get destroyed), but you will probably want multiple gateways to create units much faster. If we want to produce fighting units from the Gateway then we need one Cybernetics Core and we want multiple gateways then, we will build new buildings near pylons which we will pick randomly. Now, we have supply and can afford it, we build units for our army.

Building AI Army

Commanding AI Army

For attacking the opponent, we will find the target of opponent If we have more units, we will find any target of opponent Otherwise, we will try to defend our enemies. Now, if we have more than 15 units, we will find any target. Otherwise, if we have more than 3 units, and we know where some enemy units are, we will go get them. In order for us to know where enemies are, we have to be able to see them.

Commanding AI Army

Our AI bot is good enough to defeat both the Easy and Medium AI consistently.

Take Away

  1. Applying searching algorithms in RTS games like starcraft includes uncertainty because no future prediction is possible until the actual move is executed.
  2. Operating system constraints also exist:- SC2 GUI is formed in windows/MAC OS only.

What’s Next?

In this article, we build AI Bot which can defeat Easy and Medium AI consistently. We can use Deep Learning for training our AI Bot.

Acknowledgment: The project was done as a part of Artificial Intelligence subject for understanding the working of AI Bots and it is inspired by the StarCraft II AI python sc2 Tutorial.

The code is available at github.com/Devashi-Choudhary/StarCraft-Computer-Vs-AI-Bot. For any questions or doubts, feel free to contact me directly at github.com/Devashi-Choudhary.

--

--

Devashi Choudhary

Data Scientist at NetApp | IIIT-DELHI | IET-DAVV | Machine Learner, Researcher and Part Time Photographer💯