on reinforcement learning for full-length game of starcraft

21
On Reinforcement Learning for Full-length Game of StarCraft Zhen-Jia Pang, Ruo-Ze Liu, Zhou-Yu Meng, Yi Zhang, Yang Yu , Tong Lu National Key Laboratory for Novel Software Technology, Nanjing University, Nanjing 210023, China To whom correspondence should be addressed; E-mail: [email protected]. Abstract StarCraft II poses a grand challenge for reinforcement learning. The main difficulties of it include huge state and action space and a long-time horizon. In this paper, we investigate a hierarchical reinforcement learning approach for StarCraft II. The hierarchy involves two levels of abstraction. One is the macro-action automatically extracted from expert’s trajec- tories, which reduces the action space in an order of magnitude yet remains effective. The other is a two-layer hierarchical architecture which is modular and easy to scale, enabling a curriculum transferring from simpler tasks to more complex tasks. The reinforcement train- ing algorithm for this architecture is also investigated. On a 64x64 map and using restrictive units, we achieve a winning rate of more than 99% against the difficulty level-1 built-in AI. Through the curriculum transfer learning algorithm and a mixture of combat model, we can achieve over 93% winning rate of Protoss against the most difficult non-cheating built- in AI (level-7) of Terran, training within two days using a single machine with only 48 CPU cores and 8 K40 GPUs. It also shows strong generalization performance, when tested against never seen opponents including cheating levels built-in AI and all levels of Zerg and Protoss built-in AI. We hope this study could shed some light on the future research of large-scale reinforcement learning. 1 Introduction In recent years, reinforcement learning (13) (RL) has developed rapidly in many different do- mains. Game of Go has been considered to be conquered after AlphaGo (11) and AlphaGo Zero (12) . Most of Atari games are nearly solved using DQN (6) and follow-up methods. Var- ious mechanical control problems, such as robotic arms (4) and self-driving vehicles (10), have 1 arXiv:1809.09095v1 [cs.LG] 23 Sep 2018

Upload: others

Post on 26-Dec-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

On Reinforcement Learning for Full-length Game ofStarCraft

Zhen-Jia Pang, Ruo-Ze Liu, Zhou-Yu Meng, Yi Zhang, Yang Yu†, Tong Lu

National Key Laboratory for Novel Software Technology,Nanjing University, Nanjing 210023, China

†To whom correspondence should be addressed; E-mail: [email protected].

AbstractStarCraft II poses a grand challenge for reinforcement learning. The main difficulties of itinclude huge state and action space and a long-time horizon. In this paper, we investigatea hierarchical reinforcement learning approach for StarCraft II. The hierarchy involves twolevels of abstraction. One is the macro-action automatically extracted from expert’s trajec-tories, which reduces the action space in an order of magnitude yet remains effective. Theother is a two-layer hierarchical architecture which is modular and easy to scale, enabling acurriculum transferring from simpler tasks to more complex tasks. The reinforcement train-ing algorithm for this architecture is also investigated. On a 64x64 map and using restrictiveunits, we achieve a winning rate of more than 99% against the difficulty level-1 built-in AI.Through the curriculum transfer learning algorithm and a mixture of combat model, wecan achieve over 93% winning rate of Protoss against the most difficult non-cheating built-in AI (level-7) of Terran, training within two days using a single machine with only 48CPU cores and 8 K40 GPUs. It also shows strong generalization performance, when testedagainst never seen opponents including cheating levels built-in AI and all levels of Zergand Protoss built-in AI. We hope this study could shed some light on the future research oflarge-scale reinforcement learning.

1 Introduction

In recent years, reinforcement learning (13) (RL) has developed rapidly in many different do-mains. Game of Go has been considered to be conquered after AlphaGo (11) and AlphaGoZero (12) . Most of Atari games are nearly solved using DQN (6) and follow-up methods. Var-ious mechanical control problems, such as robotic arms (4) and self-driving vehicles (10), have

1

arX

iv:1

809.

0909

5v1

[cs

.LG

] 2

3 Se

p 20

18

made great progress. However, reinforcement learning algorithms at present are still difficult tobe used in large-scale reinforcement learning problem. Agents can not learn to solve problemsas smartly and efficiently as human. In order to improve the ability of reinforcement learn-ing, complex strategic games like StarCraft has become the perfect simulation environment formany institutions such as DeepMind (18), FAIR (15), and Alibaba (8).

From the perspective of reinforcement learning, StarCraft is a very difficult problem. Firstof all, it is a imperfect information game. Players can only see a small area of map througha local camera and there is a fog of war in the game. Secondly, the state space and actionspace of StarCraft are huge. The input image features are much larger than Go. There arehundreds of units and buildings and each of them has unique operations, making action spaceextremely large. Third, a full-length game of StarCraft commonly lasts for 30 minutes to morethan one hour and the player needs to make thousands of decisions to win. Finally, StarCraftis a multi-agent game. The combination of these issues makes StarCraft a great challenge forreinforcement learning.

Most previous agents in StarCraft are based on manual rules and scripts. Some works relatedto reinforcement learning are usually about micromanagement (16) or macromanagement (3).These works solved some specific problems like local combat in StarCraft. However, there arerare works about the full-length games. In the paper of SC2LE (18), the benchmark result givenby DeepMind shows that the A3C algorithm (5) in SC2LE did not achieve one victory on theeasiest difficulty level-1, which verifies the difficulty of full-length game in StarCraft II.

In this paper, we investigate a hierarchical reinforcement learning method for full-lengthgame of StarCraft II (SC2). First of all, we have a summary of the difficulties encountered inthe StarCraft II and introduce the simulation platform SC2LE (StarCraft II Learning Environ-ment). Then, we present our hierarchical architecture which uses several levels of abstractionto make intractable large-scale reinforcement learning problems become easy to solve. An ef-fective training algorithm tailed to the architecture is also investigated. Then, we give someexperiments in the full-length game on a 64x64 map of SC2LE. Finally, we discuss about theimpacts of the architecture, reward design and the settings of curriculum learning. Experi-mental results achieved in several difficult levels of full-length games on SC2LE illustrate theeffectiveness of different method. The main contributions of this paper are as follow:

• We investigate a hierarchical architecture which makes large-scale SC2 problem easy tosolve.

• An simple yet effective training algorithm for this architecture is also presented.

• We give detailed study of impact on training settings of our architecture on SC2LE.

• Experiment results on SC2LE show that our method achieves state-of-the-art results.

2

2 Background

In this section, we first introduce the preliminaries of reinforcement learning problems. Then,we give related works of hierarchical reinforcement learning problems. At last, we introducethe environment of StarCraft II and discuss some related works.

2.1 Reinforcement Learning

Consider a finite-horizon Markov Decision Process (MDP), which can be specified as 6-tuple:

M = 〈S,A, P (.), R(.), γ, T 〉, (1)

S is the state space and s ∈ S is a state of the state space. A is the action space and a ∈ A

is an action which agent can choose in state s. P (.) = Pr(s′|s, a) represents the probabilitydistribution of next state s′ over S when agent choose action a in state s. R(.) = R(s, a)

represents the instant reward gained from the environment when agent choose action a in states. γ is discount factor which represents the influence of future reward on the choice at now. Tis the max length of time horizon.

Policy π is a mapping or distribution form S to A. If π(s) is a scalar and agent select anaction a = π(s) when it is in state s, this policy is called a distinct policy. In contrast, if π(s)

is a distribution and agent samples an action a ∼ π(s), this policy is called a stochastic policy.Assuming one agent, using a policy π, starts from state s0, choose an action a0, gains a rewardr0 = R(s0, a0), then transform to next state s1 according to distribution Pr(.|s, a) and repeatthis process. This will generate a sequence τ below:

τ = s0, a0, r0, s1, a1, r1, . . . , (2)

There is a state send at where if agent arrives, exploration of the agent will stop. Processfrom s0 to send is called one episode. The sequence τ in the episode is called a trajectoryof the agent. For finite-horizon problem, when time step exceeds T , the exploration is alsoover. Typical RL algorithms need hundreds of episodes to learn a policy. In one episode, thediscounted cumulative reward get by agent is defined as:

G = r0 + γr1 + γ2r2 + · · · , (3)

G is called return of the episode. Typical RL algorithms aim to find an optimal policy whichmaximize the expected return.

π∗ = argmaxπ

Eπ[T∑t=0

γtR(st, at)] (4)

3

2.2 Hierarchical Reinforcement Learning

When the dimension of the state space in the environment is large, the space that needs to beexplored exhibits exponential growth, which is called the curse of dimensionality problem inreinforcement learning. Hierarchical reinforcement learning solves this problem by decom-posing a complex problem into several sub-problems and solving each sub-question in turn.Option (14) is one of the traditional hierarchical reinforcement learning algorithms. Althoughthese algorithms can better solve curse of dimensionality problems, the options need to be man-ually defined, which is time consuming and laborious. Another advantage of the hierarchicalreinforcement learning algorithm is that the resolution of the time is reduced, so that the prob-lem of credit assignment over a long time scale can be better handled.

In recent years, some novel hierarchical reinforcement learning algorithms have been pro-posed. Option-Critic (1) is a method using theorem of gradient descent to learn the options andpolicy over options simultaneously, thus reducing the effort of manual designing options. How-ever, the automatically learned options do not perform as well as non-hierarchical algorithms oncertain tasks. FeUdalNetwork (17) designed a hierarchical architecture that includes a Managermodule and a Worker module. The Manager assigns sub-goals to the Worker, and the Worker isresponsible for doing specific actions. The paper proposes a gradient transfer strategy to learnthe parameters of the Manager and Worker in an end-to-end manner. However, due to the com-plexity, this architecture is hard-to-tune. MLSH (2) proposes a hierarchical learning approachbased on meta-learning, which enhances the learning ability of transferring to new tasks throughsub-policies learned in multiple tasks. MLSH has achieved better results on some tasks than thePPO (9) algorithm, but because its setting is multi-tasking, it is more difficult to apply to ourenvironment.

2.3 StarCraft II

Games are ideal environments for reinforcement learning research. RL problems on real-timestrategy (RTS) games are far more difficult than problems on Go due to complexity of states,diversity of actions, and long time horizon. Traditionally, research on real-time strategy gamesis based on search and planning approaches (7). In recent years, more studies use RL algorithmsto conduct research on RTS and one of the most famous RTS research environments is StarCraft.Previous works on StarCraft are mostly focused on local battles or part-length and often getfeatures directly from game engine. (16) present a heuristic reinforcement learning algorithmcombining exploration in the space of policy and back propagation. (8) introduce BiCNet basedon multi-agent reinforcement learning combined with actor-critic. Although they have achievedgood results, they are only effective for part-length game. ELF (15) provides a framework forefficient learning and a platform mini-RTS for reinforcement learning research. ELF also give a

4

baseline of A3C (5) algorithm in a full-length game of mini-RTS. However, because the problemis relatively simple, there is still a great distance from the complexity of StarCraft.

SC2LE is a new research learning environment based on StarCraft II which is the follow-up of StarCraft. The location information for each unit is given in the engine of StarCraft.However, the location information of units and buildings need to be perceived from the imagefeatures in SC2LE. Therefore, the spatial complexity of the state of its input is much largerthan StarCraft I. At the same time, in order to simulate real hand movement of humans, actionspace in SC2LE is refined to each mouse click event, which greatly increases the difficulty oflearning and searching. Benchmark result given by DeepMind shows that A3C algorithm (5) didnot achieve one victory on the easiest difficulty level-1, verifying the difficulties of full-lengthgame in StarCraft II. In addition to full-length game, SC2LE also provides several mini-gamesfor research. (20) proposed a relation-based reinforcement learning algorithm, which achievedgood results on these mini-games. But the results on the full-length game are still not reported.

3 Methodology

In this section, we introduce our hierarchical architecture and the generation of macro-actionsfirstly. Then the training algorithm of the architecture is given. At last, we discuss the rewarddesign and the curriculum learning setting used in our method.

DemonstrationsDemonstrations

Policy 1

Policy 2

Policy n

ControllerGlobal

State

Sub-policies

a1, a2, a3, …

a1, a2, a3, …

a1, a2, a3, …

Macro-actionsLocal

States

Figure 1: Overall Architecture.

5

3.1 Hierarchical Architecture

Our hierarchical architecture is illustrated in Fig. 1. There are two types of policies running indifferent timescales. The controller decides to choose a sub-policy based on current observationevery long time interval, and the sub-policy picks a macro-action every short time interval.

For further illustration, we use Π to represent the controller. Sc and Ac is its state and actionspace. Rc is the reward function of controller. Similarly, assuming there is n sub-policies in thepool, we use 〈π1, π2, ..., πn〉 to represent them. The state and action space of ith sub-policy isdefined as Si and Ai. Ri is its reward function. Besides, we have a time interval K. It meansthat the controller chooses a sub-policy in every K time units and the chosen sub-policy makesa decision in every time unit. Now we can deeply go through the whole process.

At time tc, the controller gets its own global observation sctc , and it will choose a sub-policyi based on its state, like below:

actc = Π(sctc), sctc ∈ Sc (5)

Now the controller will wait for K time units and the ith sub-policy begins to make itsmove. We assume its current time is ti and its local observation is siti , so it get the macro-actionaiti = πi(s

iti

). After the ith sub-policy doing the macro-action aiti in the game, it will get thereward riti = Ri(s

iti, aiti) and its next local observation siti+1. The tuple (siti , a

iti, riti , s

iti+1) will be

stored in its local buffer Di for the future training. After K moves, it will return to the controllerand wait for the next chance.

The high level controller gets the return of the chosen sub-policy πi and compute the rewardof its action actc as follows:

rctc = riti + riti+1 + ...+ riti+K−1 (6)

Also, the controller will get its next global state sctc+1 and the tuple (sctc , actc , r

ctc , s

ctc+1) will

be stored in its local buffer Dc. Now the time is tc + 1, and the controller will make a nextchoice based on its current global observation.

From the above, we can see that there is some advantages in our hierarchical architecture.First, each sub-policy and the high-level controller have different state space. We can see thatthe controller only needs the global information to make high-level decision. The global statespace Sc is a small part of all the state space S. Also, a sub-policy responsible for combat aremore focused on the local state space Si related to battle. It can be seen that such a hierarchicalstructure can split the original huge state space into a plurality of subspaces correspondingto different policy networks. Second, the hierarchical structure can also split the tremendousaction space A. The sub-policies with different functions will have their own action space Ai.Third, the hierarchical architecture can effectively reduce the execution step size of the strategy.

6

Since the control network calls a sub-network every fixed time interval K , the total executionstep size of the high-level network becomes T/K step. The execution step size of sub-policieswill also be reduced. Last but not least, the hierarchical architecture makes design of the rewardfunction easier. Different sub-policies may have different targets. Therefore, they can learnmore quickly by their own suitable reward functions.

3.2 Generation of Macro-actions

In StarCraft, the original action space A is tremendous, and human player always need to doa sequence of raw actions to achieve one simple purpose. For example, if we want to build abuilding in the game, we have to select a peasant, order it to build the building in the specificposition, and make it come back after finish. The sequences of the raw actions for some simplepurposes are more likely some fixed sequence stored in mind for our human player. So we in-stead generate a macro-action spaceAη which is obtained through data mining from trajectoriesof experts. The original action spaceA is then replaced by the macro-action spaceAη. This willimprove the learning efficiency and running speed. The generation process of macro-actions isas follow:

• Firstly, we collect some expert trajectories which are sequence of operations a ∈ A fromgame replays.

• Secondly, we use a prefix-span (19) algorithm to mine the relationship of the each oper-ation and combine the related operations to be a sequence of actions aseq of which maxlength isC and constructed a setAseq which is defined asAseq = { aseq = (a0, a1, a2, ...ai) |ai ∈ A and i ≤ C, }

• Thirdly, we sort this set by frequency(aseq).

• Fourthly, we remove duplicated and meaningless ones, remain the top K ones;

• Finally, the reduced set are marked as newly generated macro-action space Aη.

Using the macro-action space Aη, our MDP problem of the controller are now reduced to asimple one, which is defined as:

Mc = 〈Sc, Aηc , Pc(.), Rc(.), γ, Tc〉, (7)

Meanwhile, the MDP problem of each sub-policy is also reduced to new one:

Mi = 〈Si, Aηi , P (.), Ri(.), γ, Ti〉, for i = 1 to n, (8)

7

3.3 Reward Design

As we know, reward has a significant impact on reinforcement learning. There are usually twotypes of reward we can use. One is dense reward that can be got easily during the game, andthe other is sparse reward that only shown at few specific states. Obviously, dense reward givesmore positive or negative feedback to the agent. As a result, dense reward can help agent learnto play the game faster and better than sparse reward.

There are three types of rewards we explore in this paper. Win/Loss reward is a ternary 1(win) / 0 (tie) / -1 (loss) received at the end of a game. Score reward is Blizzard scores get fromthe game engine. Mixture reward is a designed reward function. It’s hard for agent to learn thegame using Win/Loss reward. Blizzard scores can be seen as dense reward. We will show thatusing this score as reward can not help agent get more chances to win in the experiment section.We have designed some reward functions for the sub-policies that combines dense reward likescore and sparse reward like win/lose. These rewards seem to be really effective for training.There results are also shown in the experiment section.

3.4 Training Algorithm

The training process of our architecture is showed in Algorithm 1 and can be summarized asfollows. Firstly we initialize the controller and sub-policies. Then we run the iteration of Ztimes and run the episode of M times in each iteration. At the beginning of each iteration, wewill clear all the replay buffers. In each episode, we collect the trajectories of the controller andsub-policies. At the end of each iteration, we use the replay buffers to update the parameters ofthe controller and sub-policies.

The update algorithm we use is PPO (9). Entropy’s loss was added to the PPO’s loss calcu-lation to encourage exploration. Therefore, our loss formula is as follows:

Lt(θ) = Et[Lclipt (θ) + c1L

vft (θ) + c2S[πθ](st)] (9)

where c1, c2 are the coefficients we need to tune, and S denotes an entropy bonus. Lclipt (θ) is

defined as follows:

Lclipt (θ) = Et[min(rt(θ)At, clip(r(θ), 1− ε, 1 + ε)At] (10)

Lvft (θ) = Et[(r(st, at) + Vt(st)− Vt(st+1))

2] (11)

where rt(θ) = πθ(at|st)πθold (at|st)

, At is computed by a truncated version of generalized advantageestimation.

8

Algorithm 1 RL training algorithmInput: Number of sub-policys N , time interval K, reward function Rc, R1, R2, ..., Rn, maxepisodes M , max iteration steps Z

Initialize replay buffer 〈Dc, D1, D2, ..., Dn〉 , controller policy Πφ, each sub-policy πθifor j = 1 to Z do

clear data buffer 〈Dc, D1, D2, ..., Dn〉for k = 1 to M do

collect τc = {(sc1, ac1, rc1, sc2), ...} in 1/K timescaleDc ← Dc ∪ τcfor i = 1 to N do

collect τi = {(si1, ai1, ri1, si2), ...} in full timescaleDi ← Di ∪ τi

end forend forusing Dc to update φ to maximize expected returnfor i = 1 to N do

using Di to update θi to maximize expected returnend for

end for

3.5 Curriculum Learning

Curriculum learning is an effective method that can be applied to reinforcement learning. Itdesigns a curriculum from easy to difficult. Agents can continue to learn from this curriculumto improve their abilities. We use the idea of curriculum learning here to let our agents cancontinue to challenge more difficult tasks.

SC2 includes 10 difficult levels of built-in AI which are all crafted by rules and scripts. Fromlevel-1 to level-10, the built-in AI’s ability is constantly improving. Training directly in higherdifficulty level gives less positive feedback, so this is very hard for agent to learn. Instead wedesign a suitable learning sequence. In this work, we train our agent in low level of difficultyat first, and then transfer to high level of difficulty using the pre-trained model in a curriculumsetting.

However, when the pre-trained agent transfers to high levels of difficulty, we find that ifcontroller and all sub-policies are updated at the same time, the training is unstable due to themutual influence of different network. In response to this situation, we have devised a strategyto update the controller and sub-policies alternatively. We found that this method can make thetraining process more stable, and the winning rate for high difficulty levels can rise steadily.

9

4 Experiments

In this section, we introduce the experiments results on SC2LE. We first introduce the trainingand experiment settings in the evaluation. Then three sets of experiments results of evaluationare shown. At last, we discuss the results and analyze the possible causes.

4.1 Setting

The setting of our architecture is as follow: controller selects one sub-policy every 8 seconds,and the sub-policy performs macro-actions every 1 second. In the setup, we have two sub-policies in the sub-policy pool. One sub-policy controls the construction of buildings and theproduction of units in the base, called as base network. The other sub-policy responsible forbattle. This sub-policy has two different settings, which are explained later.

The number of iterations of training is generally set to 800. Each iteration run 100 full-length game of SC2. One full-length game of SC2 is defined as an episode. The maximumnumber of frames for each game is set to 18,000. In order to speed up learning, we haveadopted a distributed training method. We used 10 workers. Each worker has 5 threads. Eachworker is assigned several CPU cores and one GPU. Each worker collects data on its own andstores it in its own replay buffer. Suppose we need 100 episodes of data per iteration, theneach worker’s thread needs to collect data for 2 episodes. Each worker collects the data of 10episodes and then calculates the gradients, then passes the gradients to the parameter server.After the parameters are updated on the parameter server, the new parameters are passed backto each worker. Since the algorithm we use is PPO, the last old parameters are maintained oneach worker to calculate the gradients.

We tested it on a machine with 8 K40 GPUs and 48 CPU cores. Two experiments arerunning at the same time, with each experiment assigning 4 GPUs. It takes 8-10 minutes to run100 games of StarCraft. A training often requires about 20,000 to 50,000 episodes to converge.This means that an effective agent may be trained in more than one day even in a distributedversion. Therefore, resource consumption of training for SC2 is also a difficulty in researchingon it. In the future, it may be necessary to explore more efficient training methods.

A full-length game of SC2 in the 1v1 mode is as follow: Firstly, two players spawn ondifferent random points in the map and they should accumulate resources. Secondly, constructsthe buildings. Thirdly, produces the battle units. Fourthly, attacks and destroys all the buildingsof opponents. Fig. 2 shows a screenshot of the running game.

For simplicity, we fix the agent’s race to Protoss and build-in AI’s race to Terran. The mapwe used is the 64x64 map simple64 on SC2LE. We set the maximum length of each game to nomore than 15 minutes. For the sake of simplicity, our agent does not open sub-mine, and onlyuses the basic two military units which are Zealot and Stalker.

10

Minimap

buildingunit

Unobservable opponent location

Figure 2: Screenshot of StarCraft II.

In our setup, the battle policy has three different settings. This is explained below.

4.1.1 Combat rule

Combat rule is the simplest battle policy, in which the enemy’s position is automatically selectedby priori knowledge. The enemy’s position is set to the most distant point of all resource pointsfrom our base.

There are only one action in combat rule: attacking the enemy. The attack action uses thebuilt-in AI to do automatic attack. Thus the result of the attack depends on the constructionof the base and the production of the unit. This kind of setting can facilitate our training onbase construction and unit production. Only when the agent learns to better carry out baseconstruction (for example, master the order of buildings, do not build some redundant buildings,

11

and timely build more Crystals when supply is insufficient), it is possible for agent to win in theattack on the enemy.

4.1.2 Combat network

Though the simple Combat Rule is effective, the combat process is slightly rigid and may failswhen moving to larger and more complex maps. Below we introduce a more intelligent attackapproach which is called combat network. The output of the combat network consists of threeactions and a position vector. The three actions are: all attack a certain position, all retreat to acertain position, do nothing.

The location position is specified by a position vector. The position vector is a one-hotvector that represents the eight coordinate points on the screen. We can imagine that there is asquare in the center of the screen. The side length of the square is half the length of the sideof the screen. These 8 points are evenly distributed on the side of rectangle, referring to theposition of the attack and movement. With this setup, the agent can be smarter to choose thetarget and location of the offense, thus increasing the flexibility of the battle. At the same time,because the combat network does not specify the location of the enemy, it can automaticallylearn and discover the possible existence of the enemy, so that it can maintain performancewhen moving to a larger and more complex map.

Screen Feature Map

Minimap

Feature Map

C1 C2 C3 C4 FC 5,6,7

Predcit

3x3x32 3x3x64 3x3x64 3x3x364x64x10 256,512,256

Figure 3: Architecture of combat network.

This combat network is constructed as a Convolution Neural Network (CNN) which isshown in Fig. 3. The CNN accepts the feature map of the minimap so that it can use theinformation of the full map. Since the combat network needs to specify the position on thescreen, it is necessary to input the feature map information of the screen image and specify theposition of the local camera.

12

0 50 100 150 200 250Iteration

0.0

0.2

0.4

0.6

0.8

1.0

Win

rate

pre-trainfrom scratch

(a) Curriculum learning

0 25 50 75 100 125 150 175Iteration

0.0

0.2

0.4

0.6

0.8

1.0

Win

rate pre-train

from scratch

(b) Module training

0 50 100 150 200 250 300Iteration

0.0

0.2

0.4

0.6

0.8

1.0

Win

rate

simultaneousalternative

(c) Combat rule

0 50 100 150 200 250Iteration

0.0

0.2

0.4

0.6

0.8

1.0W

in ra

tesimultaneousalternative

(d) Combat network

Figure 4: Winning curve in training process.

We use a simple strategy to decide the position of the screen. When the controller choosesthe base sub-policy, the camera is moved to the location of agent’s base. When the controllerchooses the battle sub-policy, the camera is moved to the location of army. The location of armyis chosen in two ways. The first is the center point of all combat units. The second is the centerof the most injured unit. Since the injured unit indicated the occurrence of a recent battle, wefound that the effect of last setting was better in practice.

4.1.3 Mixture model

We can combine combat network with combat rule into a mixture model. When a certain valueis predicted in the position vector of the combat network, the army’s attack position will becomea position calculated by prior knowledge.

13

0 100 200 300 400 500Iteration

0.0

0.2

0.4

0.6

0.8

1.0

Win

rate

singlehierarchy

(a) Hierarchy vs single

0 10 20 30 40 50Iteration

0.0

0.2

0.4

0.6

0.8

1.0

Win

rate

handcraftedwin/loss

(b) Win/Loss vs handcrafted

0 50 100 150 200 250 300 350 400Iteration

6000

7000

8000

9000

10000

11000

12000

Scor

e

0.0

0.2

0.4

0.6

0.8

1.0W

in ra

te

scorewin rate

(c) Score and win rate

0 100 200 300 400 500Iteration

0.0

0.2

0.4

0.6

0.8

1.0W

in ra

te2050100

(d) Impact of update num

Figure 5: Comparison of settings.

4.2 Comparison of Training Method

First we trained our combat rule agent on the difficulty level-2 from scratch. The training iteratesover 800 steps. We found that at the beginning of the training, the agent constructed a lot ofredundant buildings. After training, the agent will more effectively use the building resourcesand control the proportion of the production quantities of each unit.

4.2.1 Effect of curriculum learning

In all of our combat models, we firstly train on low difficulty level and then transfer to highdifficulty level. This process follows the purpose of curriculum learning. We found that whentraining directly on high difficulty level, the performance of our agent is difficult to improve. If

14

we start training from low difficulty level and then use the low-difficulty’s model as the initialparameters to train, we can often get good results.

Fig. 4 (a) shows the comparison between training using pre-trained model and training fromscratch in difficulty level-7.

4.2.2 Effect of module training

Since we are using a hierarchical architecture, we can easily replace sub-policies. While re-placing a sub-policy, the parameters of the control network and other sub-policies are retained,only the parameters of the newly replaced sub-policy are updated. This can accelerate learning.On the contrary, if we are using a single network architecture, when we want to change thecombat strategy, we need to retrain all the parameters in the network, which may lead to poorperformance.

Fig. 4 (b) shows the comparison between training using pre-trained model and training fromscratch when replacing combat rules with a combat network in our experiment.

4.2.3 Alternative vs simultaneous updating

When performing transfer learning, if all the networks in the hierarchical architecture are up-dated at the same time, the learning curve will become very unstable, which makes it difficultto converge. We used an alternate updating strategy to train them in turn. This will often resultin a steady improvement.

Fig. 4 (c) shows the comparison between simultaneously updating and alternately updatingwhen transferred the combat rule model from level-2 to level-7.

Fig. 4 (d) shows the comparison between simultaneously updating and alternately updatingwhen transferred the combat network model from level-2 to level-7.

4.3 Comparison of Combat Model

Table 1: Evaluation of models.Opponent’s Type Non-cheating (Training) Cheating (No-training)Difficulty Level 1 2 3 4 5 6 7 8 9 10Combat Rule 1 0.99 0.94 0.99 0.95 0.88 0.78 0.70 0.73 0.60Combat Network 0.98 0.99 0.45 0.47 0.39 0.73 0.66 0.56 0.52 0.41Mixture Model 1 1 0.99 0.97 1 0.90 0.93 0.74 0.71 0.43

After training on difficulty level-7, we perform evaluation for each setting of combat model.Each evaluation tests from difficulty level-1 to difficulty level-10. We run 100 games in each

15

Table 2: Evaluation the policy against Protoss and Zerg without re-training.Opponent’s Type Non-cheating (No-Training) Cheating (No-training)Difficulty Level 1 2 3 4 5 6 7 8 9 10vs Zerg 1 0.99 1 0.98 0.98 0.99 0.94 0.89 0.82 0.35vs Protoss 1 1 0.92 0.76 0.46 0.40 0.45 0.47 0.41 0.34

difficulty level and report the each winning rate. The result is shown in Table 1. In the difficultylevel-1 to level-7, we found that the training agent has a very good performance.

We also evaluate the policy against even seen opponent, i.e., the built-in AI for difficultylevel-8, level-9 and level-10 uses several different cheat techniques. It can be seen that ourtrained agent still has a good performance on fighting with them. The performance video of ouragent is shown in supplementary material.

In order to test the generalization of the policy against different types of opponents, wetested the winning rate of our Protoss agent against the other two races. Table 2 shows theevaluation results of our agent against all levels built-in AI of Zerg and Protoss.

4.3.1 Combat rule

The combat rule agent achieves good results in difficulty level-1 to difficulty level-5. We findthat since agents can only use the basic two battle units to fight, they are more inclined to use afast attack fashion (called ’Rush’), which can guarantee the winning percentage.

At the same time, in order to ensure the effective use of resources, agents will minimizethe production of unrelated buildings. At the beginning, agents tend to produce more farmersto develop the economy. When the number of farmers is close to saturation, the agent willturn to the production of soldiers and other combat units. When the number of soldiers issufficient, the agent will choose to attack. This layered progressive strategy is automaticallylearned through our reinforcement learning algorithm. We found that our agents can learn ahuman-like development strategy which illustrates the effectiveness of our approach.

4.3.2 Combat network

We test the combat network on all 9 difficulty levels. The result is shown in Table 1. We foundthat although the combat network model achieved a good winning percentage on difficultylevel-7, the winning rate on several other difficulty levels was not high. It is worth noting thatmany results of the other levels of difficulty are tie. This means that the model of the combatnetwork is more difficult to completely destroy the enemy (which means eliminating all enemybuildings).

16

4.3.3 Mixture model

Through experiments, it can be found in Table 1 that the mixture model of combat networkand combat rule has achieved the best results in 1-7 difficulty levels. This can be explained asfollow. Because the agent has the right to choose to attack the enemy in the screen or the enemyon the small map, it has a lot of freedom. That is, the agent can not only choose the attackingarea within the camera, but also can switch to a fierce attack on a certain point. This freedomcan lead to a performance improvement which makes mixture model best in all three combatmodels.

4.4 Comparison of Settings

In this section we give three experiments of importance of hierarchy, design of reward andimpact of hyper parameters.

4.4.1 Hierarchy vs non-hierarchy

Our method uses a hierarchical architecture. A common problem is whether it can handle theSC2 problem if using non-hierarchical architecture. In the paper of SC2LE, the learning effectof the original action and state space and non-hierarchical reinforcement learning algorithm hasbeen given. It can be seen that it is very difficult to solve this problem without hierarchy. Ourarchitecture uses two levels of abstraction. One is a reduction in the action space, which is doneby macro-action. The other is a two-layer architecture that uses the controller to select sub-policies. We tested the effect of keeping the use of macro-actions without using the controllerand sub-policies. This is called the single-policy architecture.

We were surprised to find that on difficulty level-2, the single-policy architecture can be al-most as good as hierarchical architecture learning which means that macro-actions are effectivefor training a good agent. However, when moving to more complex levels of difficulty (such asdifficulty level-7), the initial performance and the final learning performance of the hierarchicalarchitecture are significantly better than the single-policy architecture, as shown in Fig. 5 (a).It can be explained that when the difficulty level is low, the difference between the hierarchicaland non-hierarchical architecture is less obvious. When the difficulty of the problem continuesto increase, the performance of the hierarchical model will be better than the performance ofnon-hierarchical model.

4.4.2 Outcome reward vs handcrafted reward

Win/Loss reward can achieve good results on low difficulty like handcrafted reward. However,when the training is on high difficulty level, we found that the effect of Win/Loss reward on

17

hierarchical model is relatively poor as shown in Fig. 5 (b). In SC2LE, it is mentioned that youcan use Blizzard score as a reward. However, we found that Blizzard score and winning rate arenot in a proportional relationship. While the agent is trying to improve the score, it may ignorethe attack chance on the enemy base and lose the best opportunity to win. When the score islarger, the winning rate may be smaller. This is shown in Fig. 5 (c). The final performance ofthe agent trained in SC2LE by Blizzard score also shows this problem. That is the reason whyBlizzard score is not an ideal reward function.

4.4.3 Influence of hyper-parameters

In this section we explore the effects of hyper-parameters on training. We experimented witha variety of different parameters. We found that update number of each iteration has a greatinfluence on the learning process of the agent. When the update number is small, the learningwill be unstable and hard to converge. At this time, improving update number can significantlymitigate the problem. This effect is shown in Fig. 5 (d). Other parameters do not have muchimpact on training.

4.5 Discussion

Strategies used by built-in AIs are highly optimized by game developers and therefore pose sig-nificant challenges to learning algorithms. Our method is characterized by the abstraction andreduction of StarCraft II from multiple levels. For example, by learning the macro-actions, theaction space in the StarCraft II is greatly reduced. Long-time horizon problem of the StarCraftII is mitigated through a hierarchical approach. This learning algorithm is robust (because ofthe characteristics of learning) and efficient (because of the abstraction of problems). The com-bination of these factors makes this framework suitable for solving large-scale reinforcementlearning problem such as StarCraft II.

5 Conclusion

In this paper, we investigate a hierarchical reinforcement learning approach for full-lengthgames in StarCraft II. This architecture employs two levels of abstraction. After proper train-ing, our architecture has achieved state-of-the-art results on the current challenging platformSC2LE. Though our method has achieved good results in SC2LE, it still has some shortcom-ings. For example, the 64x64 map we are currently testing is small, we only use the two arms ofthe initial level. We will explore learning on larger maps and try to use more arms to organizetactics in the future. We hope that this framework could shed some light on the future researchof reinforcement learning in real world problems. In the future, we will continue to explore

18

more reinforcement learning algorithms that can better solve large-scale reinforcement learningproblem.

References

1. P. Bacon, J. Harb, and D. Precup. The option-critic architecture. In Proceedings of theThirty-First AAAI Conference on Artificial Intelligence, February 4-9, 2017, San Francisco,California, USA., pages 1726–1734, 2017.

2. K. Frans, J. Ho, X. Chen, P. Abbeel, and J. Schulman. Meta learning shared hierarchies.CoRR, abs/1710.09767, 2017.

3. N. Justesen and S. Risi. Learning macromanagement in starcraft from replays using deeplearning. pages 162–169, 2017.

4. S. Levine, C. Finn, T. Darrell, and P. Abbeel. End-to-end training of deep visuomotorpolicies. Journal of Machine Learning Research, 17:39:1–39:40, 2016.

5. V. Mnih, A. P. Badia, M. Mirza, A. Graves, T. P. Lillicrap, T. Harley, D. Silver, andK. Kavukcuoglu. Asynchronous methods for deep reinforcement learning. In Proceed-ings of the 33nd International Conference on Machine Learning, ICML 2016, New YorkCity, NY, USA, June 19-24, 2016, pages 1928–1937, 2016.

6. V. Mnih, K. Kavukcuoglu, D. Silver, A. Graves, I. Antonoglou, D. Wierstra, and M. A.Riedmiller. Playing atari with deep reinforcement learning. CoRR, abs/1312.5602, 2013.

7. S. Ontanon, G. Synnaeve, A. Uriarte, F. Richoux, D. Churchill, and M. Preuss. A surveyof real-time strategy game AI research and competition in starcraft. IEEE Trans. Comput.Intellig. and AI in Games, 5(4):293–311, 2013.

8. P. Peng, Q. Yuan, Y. Wen, Y. Yang, Z. Tang, H. Long, and J. Wang. Multiagentbidirectionally-coordinated nets for learning to play starcraft combat games. CoRR,abs/1703.10069, 2017.

9. J. Schulman, F. Wolski, P. Dhariwal, A. Radford, and O. Klimov. Proximal policy opti-mization algorithms. CoRR, abs/1707.06347, 2017.

10. S. Shalev-Shwartz, S. Shammah, and A. Shashua. Safe, multi-agent, reinforcement learningfor autonomous driving. CoRR, abs/1610.03295, 2016.

19

11. D. Silver, A. Huang, C. J. Maddison, A. Guez, L. Sifre, G. van den Driessche, J. Schrit-twieser, I. Antonoglou, V. Panneershelvam, M. Lanctot, S. Dieleman, D. Grewe, J. Nham,N. Kalchbrenner, I. Sutskever, T. P. Lillicrap, M. Leach, K. Kavukcuoglu, T. Graepel, andD. Hassabis. Mastering the game of go with deep neural networks and tree search. Nature,529(7587):484–489, 2016.

12. D. Silver, J. Schrittwieser, K. Simonyan, I. Antonoglou, A. Huang, A. Guez, T. Hubert,L. Baker, M. Lai, A. Bolton, et al. Mastering the game of go without human knowledge.Nature, 550(7676):354, 2017.

13. R. Sutton and A. Barto. Introduction to reinforcement learning, volume 135. MIT pressCambridge, 1998.

14. R. S. Sutton, D. Precup, and S. P. Singh. Between mdps and semi-mdps: A framework fortemporal abstraction in reinforcement learning. Artif. Intell., 112(1-2):181–211, 1999.

15. Y. Tian, Q. Gong, W. Shang, Y. Wu, and C. L. Zitnick. ELF: an extensive, lightweight andflexible research platform for real-time strategy games. In Advances in Neural InformationProcessing Systems 30: Annual Conference on Neural Information Processing Systems2017, 4-9 December 2017, Long Beach, CA, USA, pages 2656–2666, 2017.

16. N. Usunier, G. Synnaeve, Z. Lin, and S. Chintala. Episodic exploration for deep determin-istic policies: An application to starcraft micromanagement tasks. CoRR, abs/1609.02993,2016.

17. A. S. Vezhnevets, S. Osindero, T. Schaul, N. Heess, M. Jaderberg, D. Silver, andK. Kavukcuoglu. Feudal networks for hierarchical reinforcement learning. In Proceed-ings of the 34th International Conference on Machine Learning, ICML 2017, Sydney, NSW,Australia, 6-11 August 2017, pages 3540–3549, 2017.

18. O. Vinyals, T. Ewalds, S. Bartunov, P. Georgiev, A. S. Vezhnevets, M. Yeo, A. Makhzani,H. Kuttler, J. Agapiou, J. Schrittwieser, J. Quan, S. Gaffney, S. Petersen, K. Simonyan,T. Schaul, H. van Hasselt, D. Silver, T. P. Lillicrap, K. Calderone, P. Keet, A. Brunasso,D. Lawrence, A. Ekermo, J. Repp, and R. Tsing. Starcraft II: A new challenge for rein-forcement learning. CoRR, abs/1708.04782, 2017.

19. X. Yan, J. Han, and R. Afshar. Clospan: Mining closed sequential patterns in large datasets.In Proceedings of the Third SIAM International Conference on Data Mining, San Fran-cisco, CA, USA, May 1-3, 2003, pages 166–177, 2003.

20

20. V. F. Zambaldi, D. Raposo, A. Santoro, V. Bapst, Y. Li, I. Babuschkin, K. Tuyls,D. P. Reichert, T. P. Lillicrap, E. Lockhart, M. Shanahan, V. Langston, R. Pascanu,M. Botvinick, O. Vinyals, and P. Battaglia. Relational deep reinforcement learning. CoRR,abs/1806.01830, 2018.

21