learning to design games: strategic environments in … · 2018. 7. 4. · learning to design...

7
Learning to Design Games: Strategic Environments in Reinforcement Learning Haifeng Zhang 1* , Jun Wang 2 , Zhiming Zhou 3 , Weinan Zhang 3 , Ying Wen 2 , Yong Yu 3 , Wenxin Li 1 1 Peking University 2 University College London 3 Shanghai Jiao Tong University [email protected], [email protected], [email protected] Abstract In typical reinforcement learning (RL), the environ- ment is assumed given and the goal of the learning is to identify an optimal policy for the agent tak- ing actions through its interactions with the envi- ronment. In this paper, we extend this setting by considering the environment is not given, but con- trollable and learnable through its interaction with the agent at the same time. This extension is moti- vated by environment design scenarios in the real- world, including game design, shopping space de- sign and traffic signal design. Theoretically, we find a dual Markov decision process (MDP) w.r.t. the environment to that w.r.t. the agent, and de- rive a policy gradient solution to optimizing the parametrized environment. Furthermore, discon- tinuous environments are addressed by a proposed general generative framework. Our experiments on a Maze game design task show the effectiveness of the proposed algorithms in generating diverse and challenging Mazes against various agent settings. 1 Introduction Reinforcement learning (RL) is typically concerned with a scenario where an agent (or multiple agents) taking actions and receiving rewards from an environment [Kaelbling et al., 1996], and the goal of the learning is to find an op- timal policy for the agent that maximizes the cumulative reward when interacting with the environment. Success- ful applications include playing games [Mnih et al., 2013; Silver et al., 2016], scheduling traffic signal [Abdulhai et al., 2003], regulating ad bidding [Cai et al., 2017], to name just a few. In most RL approaches, such as SARSA and Q-learning [Sutton and Barto, 1998], the model of the environment is, however, not necessarily known a priori before learning the optimal policy for the agent. Alternatively, model-based approaches, such as DYNA [Sutton, 1990] and prioritized sweeping [Moore and Atkeson, 1993], require establishing the environment model while learning the optimal policy. Nonetheless, in either case, the environment is assumed given * This work is done during Haifeng Zhang’s visit at UCL. Jun Wang and Weinan Zhang are the corresponding authors of this paper. and mostly either stationary or non-stationary without a pur- posive control [Kaelbling et al., 1996]. In this paper, we extend the standard RL setting by consid- ering the environment is strategic and controllable. We aim at learning to design an environment via interacting with an also learnable agent or multiple agents. This has many potential applications, ranging from designing a game (environment) with a desired level of difficulties in order to fit the current player’s learning stage [Togelius and Schmidhuber, 2008] and designing shopping space to impulse customers purchase and long stay [Penn, 2005] to controlling traffic signals [Ceylan and Bell, 2004]. In general, we propose and formulate the de- sign problem of environments which interact with intelligent agents/humans. We consider designing these environments via machine learning would release human labors and ben- efit social efficiency. Comparing to the well-studied image design/generation problem [Goodfellow et al., 2014], envi- ronment design problem is new in three aspects: (i) there is no ground-truth samples; (ii) the sample to be generated may be discontinuous; (iii) the evaluation of a sample is through learning intelligent agents. Our formulation extends the scope of RL by focusing on the environment modeling and control. Particularly, in an adversarial case, on one hand, the agent aims to maximize its accumulative reward; on the other hand, the environment tends to minimize the reward for a given optimal policy from the agent. This effectively creates a minimax game between the agent and the environment. Given the agent’s playing en- vironment MDP, we, theoretically, find a dual MDP w.r.t. the environment, i.e., how the environment could decide or sam- ple the successor state given the agent’s current state and an action taken. Solving the dual MDP yields a policy gradient solution [Williams, 1992] to optimize the parametric environ- ment achieving its objective. When the environment’s param- eters are not continuous, we propose a generative modeling framework for optimizing the parametric environment, which overcomes the constraints on the environment space. Our ex- periments on a Maze game generation task show the effec- tiveness of generating diverse and challenging Mazes against various types of agents in different settings. We show that our algorithms would be able to successfully find the weaknesses of the agents and play against them to generate purposeful environments. The main contributions of this paper are threefold: (i) we propose the environment design problem, which is novel and Proceedings of the Twenty-Seventh International Joint Conference on Artificial Intelligence (IJCAI-18) 3068

Upload: others

Post on 03-Jan-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Learning to Design Games: Strategic Environments in … · 2018. 7. 4. · Learning to Design Games: Strategic Environments in Reinforcement Learning Haifeng Zhang1, Jun Wang2, Zhiming

Learning to Design Games: Strategic Environmentsin Reinforcement Learning

Haifeng Zhang1∗, Jun Wang2, Zhiming Zhou3, Weinan Zhang3, Ying Wen2, Yong Yu3, Wenxin Li11 Peking University

2 University College London3 Shanghai Jiao Tong University

[email protected], [email protected], [email protected]

AbstractIn typical reinforcement learning (RL), the environ-ment is assumed given and the goal of the learningis to identify an optimal policy for the agent tak-ing actions through its interactions with the envi-ronment. In this paper, we extend this setting byconsidering the environment is not given, but con-trollable and learnable through its interaction withthe agent at the same time. This extension is moti-vated by environment design scenarios in the real-world, including game design, shopping space de-sign and traffic signal design. Theoretically, wefind a dual Markov decision process (MDP) w.r.t.the environment to that w.r.t. the agent, and de-rive a policy gradient solution to optimizing theparametrized environment. Furthermore, discon-tinuous environments are addressed by a proposedgeneral generative framework. Our experiments ona Maze game design task show the effectiveness ofthe proposed algorithms in generating diverse andchallenging Mazes against various agent settings.

1 IntroductionReinforcement learning (RL) is typically concerned with ascenario where an agent (or multiple agents) taking actionsand receiving rewards from an environment [Kaelbling etal., 1996], and the goal of the learning is to find an op-timal policy for the agent that maximizes the cumulativereward when interacting with the environment. Success-ful applications include playing games [Mnih et al., 2013;Silver et al., 2016], scheduling traffic signal [Abdulhai et al.,2003], regulating ad bidding [Cai et al., 2017], to name just afew.

In most RL approaches, such as SARSA and Q-learning[Sutton and Barto, 1998], the model of the environment is,however, not necessarily known a priori before learning theoptimal policy for the agent. Alternatively, model-basedapproaches, such as DYNA [Sutton, 1990] and prioritizedsweeping [Moore and Atkeson, 1993], require establishingthe environment model while learning the optimal policy.Nonetheless, in either case, the environment is assumed given

∗This work is done during Haifeng Zhang’s visit at UCL. JunWang and Weinan Zhang are the corresponding authors of this paper.

and mostly either stationary or non-stationary without a pur-posive control [Kaelbling et al., 1996].

In this paper, we extend the standard RL setting by consid-ering the environment is strategic and controllable. We aim atlearning to design an environment via interacting with an alsolearnable agent or multiple agents. This has many potentialapplications, ranging from designing a game (environment)with a desired level of difficulties in order to fit the currentplayer’s learning stage [Togelius and Schmidhuber, 2008] anddesigning shopping space to impulse customers purchase andlong stay [Penn, 2005] to controlling traffic signals [Ceylanand Bell, 2004]. In general, we propose and formulate the de-sign problem of environments which interact with intelligentagents/humans. We consider designing these environmentsvia machine learning would release human labors and ben-efit social efficiency. Comparing to the well-studied imagedesign/generation problem [Goodfellow et al., 2014], envi-ronment design problem is new in three aspects: (i) there isno ground-truth samples; (ii) the sample to be generated maybe discontinuous; (iii) the evaluation of a sample is throughlearning intelligent agents.

Our formulation extends the scope of RL by focusing onthe environment modeling and control. Particularly, in anadversarial case, on one hand, the agent aims to maximizeits accumulative reward; on the other hand, the environmenttends to minimize the reward for a given optimal policy fromthe agent. This effectively creates a minimax game betweenthe agent and the environment. Given the agent’s playing en-vironment MDP, we, theoretically, find a dual MDP w.r.t. theenvironment, i.e., how the environment could decide or sam-ple the successor state given the agent’s current state and anaction taken. Solving the dual MDP yields a policy gradientsolution [Williams, 1992] to optimize the parametric environ-ment achieving its objective. When the environment’s param-eters are not continuous, we propose a generative modelingframework for optimizing the parametric environment, whichovercomes the constraints on the environment space. Our ex-periments on a Maze game generation task show the effec-tiveness of generating diverse and challenging Mazes againstvarious types of agents in different settings. We show that ouralgorithms would be able to successfully find the weaknessesof the agents and play against them to generate purposefulenvironments.

The main contributions of this paper are threefold: (i) wepropose the environment design problem, which is novel and

Proceedings of the Twenty-Seventh International Joint Conference on Artificial Intelligence (IJCAI-18)

3068

Page 2: Learning to Design Games: Strategic Environments in … · 2018. 7. 4. · Learning to Design Games: Strategic Environments in Reinforcement Learning Haifeng Zhang1, Jun Wang2, Zhiming

potential for practical applications; (ii) we reduce the prob-lem to the policy optimization problem for continuous casesand propose a generative framework for discontinuous cases;(iii) we apply our methods to Maze game design tasks andshow their effectiveness by presenting the generated non-trivial Mazes.

2 Related WorkReinforcement learning (RL) [Sutton and Barto, 1998] stud-ies how an intelligent agent learns to take actions through theinteraction with an environment over time. In a typical RLsetting, the environment is unknown yet fixed, and the fo-cus is on optimizing the agent policies. Deep reinforcementlearning (DRL) is a marriage of deep neural networks [LeCunet al., 2015] and RL; it makes use of deep neural networks asa function approximator in the decision-making frameworkof RL to achieve human-level control and general intelligence[Mnih et al., 2015]. In this paper, instead, we consider a fam-ily of problems that is an extension of RL by considering thatthe environment is controllable and strategic. Unlike typicalRL, our subject is the strategic environment not the agent, andthe aim is to learn to design an optimal (game) environmentvia the interaction with the intelligent agent.

Our problem of environment design is related to the well-known mechanism design problem[Nisan and Ronen, 2001],which studies how to design mechanisms for participants thatachieves some objectives such as social welfare. In most stud-ies, the designs are manual. Our work focuses on automatedenvironment (mechanism) design by machine learning. Thus,we formulate the problem based on MDP and provide solu-tions based on RL. In parallel, the automated game-level de-sign is a well-studied problem by applying search-based pro-cedural content generation[Togelius et al., 2011]. For gen-erating game-levels that conform to design requirements, ge-netic algorithm (GA) is proposed as a searcher. Our work in-stead providing sound solutions based on RL methods, whichbring new properties such as gradient direction searching andgame feature learning.

In the field of RL, our problem is related to safe/robustreinforcement learning, which maximizes the expectation ofthe return under some safety constraints such as uncertainty[Garcıa and Fernandez, 2015; Morimoto and Doya, 2005],due to the common use of parametric MDPs. However, ourproblem setting is entirely different from safe RL as their fo-cus is on single agent learning in an unknown environment,whereas our work is concerned with the learning of the en-vironment to achieve its own objective. Our problem is alsodifferent from agent reward design [Sorg et al., 2010], whichoptimizes designer’s cumulative reward given by a fixed en-vironment (MDP). However, the environment is learnable inour setting. Another related work, FeUdal networks [Vezh-nevets et al., 2017], introduces transition policy gradient toupdate the proposed manager model, which is a componentof agent policy. This is different from our transition gradientwhich is for updating the environment.

Our formulation is a general one, applicable in the settingwhere there are multiple agents [Busoniu and De Schutter,]. It is worth mentioning that although multi-agent reinforce-ment learning (MARL) studies the strategic interplays amongdifferent entities, the game (either collaborative or com-

petitive) is strictly among multiple agents [Littman, 1994;Hu and Wellman, 2003]. By contrast, the strategic inter-plays in our formulation are between an agent (or multipleagents) and the environment. The recent work, interactivePOMDPs [Gmytrasiewicz and Doshi, 2005], aims to spreadbeliefs over physical states of the environment and over mod-els of other agents, but the environment in question is stillnon-strategic. Our problem, thus, cannot be formulated di-rectly using MARL as the decision making of the environ-ment is in an episode-level, while policies of agents typicallyoperate and update in each time-step within an episode.

In addition, our minimax game formulation can also befound in the recently emerged generative adversarial nets(GANs), where a generator and a discriminator play a min-imax adversarial game [Goodfellow et al., 2014]. Comparedto GANs, our work addresses a different problem, where thetrue samples of desired environments are missing in our sce-nario; the training of our environment generator is guided bythe behaviours of the agent (corresponding the GAN discrimi-nator) who aims to maximize its cumulative reward in a givenenvironment.

3 RL with Controllable Environment3.1 Problem FormulationLet us first consider the standard reinforcement learningframework. In this framework there are a learning agent anda Markov decision process (MDP) M = 〈S,A,P,R, γ〉,where S denotes state space, A action space, P state transi-tion probability function,R reward function and γ discountedfactor. The agent interacts with the MDP by taking action ain state s and observing reward r in each time-step, result-ing in a trajectory of states, actions and rewards: H1...∞ =〈S1, A1, R1, S2, A2, R2 . . .〉, St ∈ S, At ∈ A, Rt ∈ R,where P[St+1 = s′|St = s,At = a] = P(s, a, s′) andE[Rt|St = s,At = a] = R(s, a) hold.1 The agent se-lects actions according to a policy πφ, where πφ(a|s) definesthe probability that the agent selects action a in state s. Theagent learns πφ to maximize the return (cumulative reward)G =

∑∞t=1 γ

t−1Rt.In the standard setting, the MDP is given fixed while the

agent is flexible with its policy to achieve its objective. Weextend this setting by also giving flexibility and purpose toM. Specifically, we parametrize P as Pθ and set the ob-jective of the MDP asO(H), which can be arbitrary based onthe agent’s trajectory. We intend to design (generate) an MDPthat achieves the objective along with the agent achieving itsown objective:

θ∗ = argmaxθ

E[O(H)|Mθ = 〈S,A,Pθ,R, γ〉;

πφ∗ = argmaxπφ

E[G|πφ;Mθ]]. (1)

Adversarial EnvironmentIn this paper, we consider a particular objective of the envi-ronment that it acts as an adversarial environment minimiz-ing the expected return of the single agent, i.e., O(H) =

1In this paper, we use St, At, Rt when they are in trajectorieswhile using s, a, r otherwise.

Proceedings of the Twenty-Seventh International Joint Conference on Artificial Intelligence (IJCAI-18)

3069

Page 3: Learning to Design Games: Strategic Environments in … · 2018. 7. 4. · Learning to Design Games: Strategic Environments in Reinforcement Learning Haifeng Zhang1, Jun Wang2, Zhiming

start end

blank wall

agent path

θTrain Environment : min max G Train Agent : max G

Start

End

1

θ

θ ϕ

2

θm

ϕ

max G = -14

max G = -30

min max G = -38max G = -38

G = -28

G = -22

G = -14

G = -40

G = -32

G = -30

G = -42

G = -40

G = -38

(agent path evolves)(maze map evolves)

Figure 1: An example of adversarial Maze design. The detaileddefinition of the Maze environment is provided in Sec.4. In short,an agent tries to find the shortest path from the start to the end in agiven Maze map, while the Maze environment tries to design a mapto make the path taken by the agent longer. In the direction of φ,the parameter of an agent policy evolves, whereas in the direction ofθ, the parameter of the Maze environment evolves. The cumulativerewardG is defined as the opposite number of the length of the path.∑∞t=1−γt−1Rt = −G. This adversarial objective is use-

ful in the game design domain because for many games thegame designer need to design various game levels or set vari-ous game parameters to challenge game players playing withvarious game strategies. Thus, the relationship between theenvironment(game) and the agent(player) are adversarial. Weintend to transfer this design work from human to machine byapplying appropriate machine learning methods. Formally,the objective function is formulated as:

θ∗ = argminθ

maxφ

E[G|πφ;Mθ = 〈S,A,Pθ,R, γ〉]. (2)

In general, we adopt an iterative framework for learning θand φ. In each iteration, the environment updates its param-eter to maximize its objective w.r.t. the current agent policythen the agent updates its policy parameter by taking suffi-cient steps to be optimal w.r.t. the updated environment, asillustrated by Fig. 1 for learning the environment of a Maze.Since the agent’s policy can be updated using well-studiedRL methods, we focus on the update methods for the envi-ronment. In each iteration, given the agent’s policy parameterφ∗, the objective of the environment is

θ∗ = argminθ

E[G|Mθ = 〈S,A,Pθ,R, γ〉;πφ∗ ]. (3)

In the following sections, we propose two methods to solvethis problem for continuous and discontinuous environments.

3.2 Gradient Method for Continuous EnvironmentIn this section, we propose a gradient method for continuousenvironment, i.e. the value of the transition probability forany 〈s, a, s′〉 can be arbitrary in [0, 1]. Thus, the parameterθ of the environment actually consists of the values of thetransition function P(s, a, s′) for each 〈s, a, s′〉. Our task isto optimize the values of the transition function to minimizethe agent’s cumulative reward.

To update the environment, we try to find the gradient ofthe environment objective w.r.t. θ. We derive the gradientby taking a new look at the environment and the agent in the

opposite way, that the original environmentMA as an agentand the original agent as a part of the new environmentME .Viewing in this way, the original environmentMA takes ac-tion AEt to determine the next state SAt+1 given the currentstate SAt and the agent’s action AAt . Thus we define the statesE inME as the combination 〈sA, aA〉. On the other hand,given the original environment’s action AEt = SAt+1 , theagent policy πAφ∗(s

A) acts as a transition in ME to deter-mine AAt+1 as part of the next state SEt+1 = 〈SAt+1, A

At+1〉 in

ME . Furthermore, optimizing agent policy inME is equalto optimizing environment transition inMA.

Theoretically, we reduce our transition optimization prob-lem in Eq. (3) to the well-studied policy optimization problemthrough a proposed concept of a duel MDP-policy pair.Definition 1 (Duel MDP-policy pair). For any MDP-policypair 〈MA, πA〉, whereMA = 〈SA,AA,PA,RA, γA〉 withstart state distribution pA1 and terminal state set SAT , thereexists a dual MDP-policy pair 〈ME , πE〉, where ME =〈SE ,AE ,PE ,RE , γE〉 with start state distribution pE1 andterminal action set AET satisfying:

• SE = SA × AA = {〈sA, aA〉|sA ∈ SA, aA ∈ AA}, astate inME corresponds to a combination of successivestate and action inMA;• AE = SA = {sA|sA ∈ SA}, an action inME corre-

sponds to a state inMA;• PE(sEi , aE , sEi′ ) = PE(〈sAj , aAk 〉, sA, 〈sAj′ , aAk′〉) ={

πA(aAk′ |sA) sA = sAj′0 sA 6= sAj′

, the transition in ME de-

pends on the policy inMA;• RE(sEi , aE) = RE(〈sAj , aAk 〉, sA) = RA(sAj , aAk ), the

rewards inME are the same as inMA;• γE = γA, the discounted factors are the same;• pE1 (sE) = pE1 (〈sA, aA〉) = pA1 (s

A)πA(aA|sA), startstate distribution inME depends on start state distribu-tion and the first action distribution inMA;

• AET = {sA|sA ∈ SAT }, terminal action in ME corre-sponds to terminal state inMA;• πE(aE |sE) = πE(sAi′ |〈sAi , aA〉) = PA(sAi , aA, sAi′ ),

policy inME corresponds to transition inMA.We can see that the dual MDP-policy pair in fact describes

an equal mechanism as the original MDP-policy pair fromanother perspective. Based on the dual MDP-policy pair, wegive three theorems to derive the gradient of the transitionfunction. The proofs are omitted for space reason.Theorem 1. For an MDP-policy pair 〈MA, πA〉 and its du-ality 〈ME , πE〉, the distribution of trajectory generated by〈MA, πA〉 is the same as the distribution of a bijective tra-jectory generated by 〈ME , πE〉, i.e. P[HA|MA, πA] =P[HE |ME , πE ], where HE = b(HA), HA = b−1(HE).Theorem 2. For an MDP-policy pair 〈MA, πA〉 and its du-ality 〈ME , πE〉, the expected return of two bijective state-action trajectories, HA = b−1(HE) from 〈MA, πA〉 andHE = b(HA) from 〈ME , πE〉, are equal.

Proceedings of the Twenty-Seventh International Joint Conference on Artificial Intelligence (IJCAI-18)

3070

Page 4: Learning to Design Games: Strategic Environments in … · 2018. 7. 4. · Learning to Design Games: Strategic Environments in Reinforcement Learning Haifeng Zhang1, Jun Wang2, Zhiming

1. Generate

Environments2. Agent is trained in

each environment

3. Operate in theenvironments with

updated policy

4. Agent returnsG ...G1 6

Agentπµ

θ

θA

EnvironmentGenerator

M

ϕw

θ1AM θ2

AM θ3AM

θ4AM θ5

AM θ6AM

generator updateguide the

Figure 2: Framework dealing with discontinuous environment. Gen-erator generates environment parameter θ. For eachMA

θ , the agentpolicy is trained. Then the policy is tested in the generated environ-ments and the returns are observed, which finally guide the generatorto update.

Theorem 3. For an MDP-policy pair 〈MA, πA〉 and its du-ality 〈ME , πE〉, the expected return of 〈MA, πA〉 is equalto the expected return of 〈ME , πE〉, i.e., E[GA|πA,MA] =E[GE |πE ,ME ].

Theorem 2 can be understood by the equivalence betweenHA and HE and the same generating probability of them asgiven in Theorem 1. Theorem 3 naturally extends Theorem 2from the single trajectory to the distribution of trajectory ac-cording to the equal probability mass function given by The-orem 1.

Now we consider 〈MAθ , π

A〉 and its duality 〈ME , πEθ 〉,where PAθ and πEθ are of the same form about θ. Given θ, PAθand πEθ are exactly the same, resulting in E[GA|πA,MA

θ ] =E[GE |πEθ ,ME ] according to Theorem 3. Thus optimizingPAθ as Eq. (3) is equivalent to optimizing πEθ :

θ∗ = argminθ

E[G|MAθ ;π

Aφ∗ ] = argmin

θE[G|πEθ ;ME

φ∗ ].

(4)

We then apply the policy gradient theorem [Sutton et al.,1999] on πEθ and derive the gradient for PAθ :

∇θJ(θ) = E[∇θ log πEθ (aE |sE)QE(sE , aE)|πEθ ;MEφ∗ ]

= E[∇θ logPAθ (sAi , aA, sAi′ )V A(sAi′ )|MAθ ;π

Aφ∗ ],

(5)where J(θ) is cost function, QE(sE , aE) and V A(sAi′ ) areaction-value function and value function of 〈ME , πEθ 〉 and〈MA

θ , πA〉 respectively; and can be proved equal due to the

equivalence of the two MDPs.We name the gradient in Eq. (5) as transition gradient.

Transition gradient can be used to update the transition func-tion in an iterative way. In theory, it performs as well as pol-icy gradient since it is equivalent to the policy gradient in thecircumstance of the dual MDP-policy pair.

3.3 Generative Framework for DiscontinuousEnvironment

The transition gradient method proposed in the last sectiononly works for continuous environment. For discontinu-ous environment, i.e. the range of the transition functionP(s, a, s′) is not continuous in [0, 1], we cannot directly takethe gradient of the transition function w.r.t. θ.

To deal with the discontinuous situation, we propose a gen-erative framework to find the optimal θ alternative to the gra-dient method. In general, we build a parametrized generator

to generate a distribution of the environment, then update theparameter of the generator by evaluating the environments itgenerates (illustrated in Fig. 2). Specifically, we generate en-vironment parameter θ using a w-parametrized generator µw,then optimize w to obtain the (local) optimal w∗ and a corre-sponding optimal distribution of θ. Formally, our optimiza-tion objective is formulated as

w∗ = argminw

Eθ∼µw[E[G|

MAθ = 〈SA,AA,PAθ ,RA, γA〉;πφ∗ ]

]. (6)

We model the generation process using an auxiliary MDPMµ, i.e., the generator µw generates θ and updates w in areinforcement learning way. The reason we adopt reinforce-ment learning other than supervised learning is that in thisgenerative task, (i) there is no training data to describe thedistribution of the desired environments so we cannot com-pute likelihood of generated environments and (ii) we canonly evaluate a generated environment through sampling, i.e.,performing agents in the generated environment and gettinga score from the trajectory, which can be naturally modeledby reinforcement learning by viewing the score as a rewardof the actions of the generator.

In detail, the generator µw consists of three elements〈Mµ, πµw, f

µ〉. For generating θ, an auxiliary agent with pol-icy πµw acts inMµ to generate a trajectory Hµ, after that θ isdetermined by the transforming function θ = fµ(Hµ), i.e.,the distribution of θ is based on the distribution of trajecto-ries, which are further induced by playing πµw in Mµ. Foradversarial environments, the reward of the generator is de-signed to be opposite to the return of the agent got in Mθ,which reflects the minimization objective in Eq. (6). Thus, wcan be updated by applying policy gradient methods on πµw.

There are various ways to designing Mµ for a particularproblem. Here we provide a general design that can be ap-plied to any environment. Briefly, we generate the environ-ment parameter in an additive way and ensures the validityalong the generation process. In detail, we reshape the ele-ments of θ as a vector θ = 〈x1, x2, . . . , xNθ 〉, xk ∈ Xk anddesignMµ = 〈Sµ,Aµ,Pµ,Rµ, γµ = 1〉 to generate θ:

• Sµ = {vk = 〈x1, x2, . . . , xk〉|k = 0 . . . Nθ, ∃vNθ =〈x1, x2, . . . , xk, x′k+1 . . . x

′Nθ〉 = θ, s.t. PAθ ∈ PA};

• Aµ =⋃k=1...Nθ

Xk;

• Pµ is defined that for the current state vk =〈x1, x2, . . . , xk〉 and an action xk+1, if xk+1 ∈ Xk+1

and vk+1 = 〈x1, x2, . . . , xk+1〉 ∈ Sµ the next state isvk+1, otherwise vk;

• Rµ is defined that for terminal state vNθ =〈x1, x2, . . . , xNθ 〉 = θ the reward is the opposite num-ber of the averaged return got by πAφ∗ acting in MA

θ ,otherwise the reward is 0.

In addition, the start state is v0 = 〈〉 and the terminal statesare vNθ = 〈x1, x2, . . . , xNθ 〉. Corresponding to this Mµ,πµw(xk+1|vk;w) is designed to take an action xk+1 ∈ Xk+1

depending on the previous generated sequence vk, and thetransforming function fµ is designed as fµ(Hµ) = vNθ = θ.Note that due to the definition of Sµ, any partial parametervt without potential to be completed as a valid parameter θ

Proceedings of the Twenty-Seventh International Joint Conference on Artificial Intelligence (IJCAI-18)

3071

Page 5: Learning to Design Games: Strategic Environments in … · 2018. 7. 4. · Learning to Design Games: Strategic Environments in Reinforcement Learning Haifeng Zhang1, Jun Wang2, Zhiming

Round 0

OPT

Round 100 Round 200 Round 300 Round 400

S

E

S

E

S

E

S

E

S

E

DQN

Round 0 Round 100 Round 200 Round 300 Round 400

S

E

S

E

S

E

S

E

S

E

Figure 3: Heatmaps of the blockage probability (soft wall, indicatedby the intensity of the color in the cell) distribution throughout 5×5soft wall Maze learning against the OPT and DQN agents.

is avoided to be generated. This ensures any constraint onenvironment parameter can be followed. On the other hand,any valid θ is probable to be generated once πµw is exploratoryand of enough expression capacity.2

4 Experiments with Maze Design4.1 Experiment SettingIn our experiment, we consider a use case of designing Mazegame to test our solutions over the transition gradient methodand the generative framework respectively. As shown in bothFigs. 4 and 5, the Maze is a grid world containing a map ofn × n cells. In every time-step, the agent is in a cell andhas four directional actions {N,S,W,E} to select from, andtransitions are made deterministically to an adjacent cell, un-less there is a wall (e.g., the black cells as illustrated in Figs.4 and 5), in which case no movement occurs. The minimaxgame is defined as: the agent should go from the north-westcell to the south-east cell using steps as few as possible, whilethe goal of the Maze environment is to arrange the walls in or-der to maximize the number of steps taken by the agent.

Note that the above hard wall Maze results in an environ-ment that is discontinuous. In order to also test the case ofcontinuous environments, we consider a soft wall Maze asshown in Fig. 3. Specifically, instead of a hard wall that com-pletely blocks the agent, each cell except the end cell has ablockage probability (soft wall) which determines how likelythe agent will be blocked by this cell when it takes transitionaction from an adjacent cell. It is also ensured that the sumof blockage probabilities of all cells is 1 and the maximumblockage probability for each cell is 0.5. Thus, the task forthe adversarial environment in this case is to allocate the softwall to each cell to block the agent the most.

Our experiment is conducted on PCs with common CPUs.We implement our experiment environment using Keras-RL[Plappert, 2016] backed by Keras and Tensorflow. 3

4.2 Results for the Transition Gradient MethodWe test the transition gradient method considering the 5 × 5soft wall Maze case. We model the transition probabilityfunction by a deep convolutional neural network, which isupdated by the transition gradient following Eq. (5). We con-sider the two types of agents: Optimal (OPT) agent and Deep

2The generative framework could also be applied for continuousenvironment generation although it results in low efficiency compar-ing to directly updating the environment by gradient.

3Our experiment is repeatable and the code is at goo.gl/o9MrDN.

start end blank wall agent path

OPT

5×5Return=16

6×6Return=22

7×7Return=30

8×8Return=38

DFS

5×5Return=28

6×6Return=44

7×7Return=64

8×8Return=86

RHS

5×5Return=28

6×6Return=40

7×7Return=56

8×8Return=74

DQN

5×5Return=10

6×6Return=16

7×7Return=30

8×8Return=87

Figure 4: Best Mazes against OPT, DFS, RHS and DQN agents withsize ranging from 5× 5 to 8× 8.

Q-network learning (DQN) agent. The OPT agent has no pa-rameters to learn, but always finds the optimal policy againstany generated environment. The DQN agent [Mnih et al.,2013] is a learnable one, in which the agent’s action-valuefunction is modeled by a deep neural network, which takesthe whole map and its current position as input, processedby 3 convolutional layers and 1 dense layer, then outputs theQ-values over the four directions. For each updated environ-ment, we train the DQN agent to be optimal, as Fig. 1 shows.

Fig. 3 shows the convergence that our transition gradientmethod has achieved. The change of the learned environmentparameters, in the form of blockage probabilities, over timeare indicated by the color intensity. Intuitively, the most ef-fective adversarial environment to block the agent is to placetwo 0.5 soft walls in the two cells next to the end or the be-ginning cell, as this would have the highest blockage proba-bilities. We can see that in both cases, using the OPT agentand the DQN agent, our learning method can obtain one ofthe two most optimal Maze environments.

4.3 Results for Generative FrameworkWe now test our reinforcement learning generator by the hardwall Maze environment. We follow the proposed generalgenerative framework to design µw = 〈Mµ, πµw, f

µ〉, whichgradually generates walls one by one from an empty map.Particularly, πµw is modeled by a deep neural network thattakes an on-going generated map as input and outputs a po-sition for a new wall or a special action for termination. Ac-tions lead to generating walls that completely block the agentare invalid and prevented. We test our generator against fourtypes of agents each on four sizes of maps (from 5 × 5 to8 × 8). Although the objective for every agent is to mini-mize the number of steps, not every agent has the ability tofind the optimal policy because of model restrictions of πφ orlimitations in the training phase. Therefore, besides testingour generator against the optimal agent (the OPT agent) and

Proceedings of the Twenty-Seventh International Joint Conference on Artificial Intelligence (IJCAI-18)

3072

Page 6: Learning to Design Games: Strategic Environments in … · 2018. 7. 4. · Learning to Design Games: Strategic Environments in Reinforcement Learning Haifeng Zhang1, Jun Wang2, Zhiming

OPT

DFS

RHS

DQN

start end blank wall

Round 1Return=14

Round 1Return=16

Round 50Return=18

Round 10Return=19

Round 100Return=30

Round 100Return=60

Round 150Return=36

Round 75Return=59

Round 400Return=36

Round 300Return=70

Round 400Return=58

Round 200Return=69

Round 600Return=38

Round 500Return=86

Round 600Return=74

Round 350Return=87

Figure 5: Learning to design Mazes against OPT, DFS, RHS andDQN agents in 8× 8 map.

the DQN agent, we also adopt other two imperfect agents forour generator to design specific Mazes in order to understandmore about our solution’s behaviors. They are:

Depth-first search (DFS) agent. The DFS agent searchesthe end in a depth-first way. In each time-step, without lossof generality, the DFS agent is set to select an action accord-ing to the priority of East, South, North, West. The DFS agenttakes the highest priority action that leads to a blank and un-visited cell. If there are none, The DFS agent goes back tothe cell from which it comes.

Right-hand search (RHS) agent. The RHS agent is awareof the heading direction and follows a strategy that alwaysensures its right-hand cell is a wall or the border. In eachtime-step, (i) the RHS agent checks its right-hand cell, if it isblank, the RHS agent will turn right and step into the cell; (ii)if not, then if the front cell is blank, the RHS agent will stepforward; (iii) if the front cell is not blank, the RHS agent willcontinue turning left until it faces a blank cell, then steps intothat cell.

Note that DFS and RHS are designed particularly for dis-continuous Mazes. We also limit the network capacity andtraining time of the DQN agent to make it converge differ-ently from the OPT agent. The learned optimal Mazes aregiven in Fig. 4 for different agents with different Maze sizes.The strongest Mazes designed by our generator are foundwhen playing against the OPT agent, shown in Fig. 4 (OPT).We see that in all cases, from 5 × 5 to 8 × 8, our generatortends to design long narrow paths without any fork, whichmakes the optimal paths the longest. By contrast, the genera-tor designs many forks to trap the DQN agent, shown in Fig. 4(DQN), as the DQN agent runs a stochastic policy (ε-greedy).

In fact our generator could make use of the weakness fromthe agents to design the maps against them. Fig. 4 (DFS)shows the results that our generator designs extremely broadareas with only one entrance for the DFS agent to search ex-haustively (visit every cell in the closed area twice). Fig. 4(RHS) shows the Mazes generated to trouble the RHS agent

(1) OPT (2) DFS

(3) RHS (4) DQNFigure 6: Training curves for OPT, DFS, RHS and DQN agents in8 × 8 map. The lines and the shadows show mean and variance ofgenerator return respectively.

the most by creating a highly symmetric Maze.Next, Fig. 5 shows the snapshots of the results in different

learning rounds. They all evolve differently, depending onthe types of the agents. For the OPT agent, we find that ourgenerator gradually links isolated walls to form a narrow butlong path. For the DFS, our generator gradually encloses anarea then broadens and sweeps it in order to best play againstthe policy that has the priority order of their travel directions.Fig. 5 (RHS) shows that our generator learns to adjust thewall into zigzag shapes to trouble the RHS agent. For theDQN agent, with limited network capacity or limited trainingtime, it is usually the case that it cannot perfectly tell whichroad to go during the learning. As such, the generator tendsto generate many forks to confuse the DQN agent.

Furthermore, Fig. 6 shows the process of training our gen-erator against the four agents in 8 × 8 map. We find thatfor OPT, DFS and RHS agents, the generator learns rapidlyat first and gradually converges. But for the DQN agent,the learning curve is tortuous. This is because the abilityof the DQN agent is gradually improved so it does not ac-curately and efficiently guide the learning of the generator.Also when the ability of the DQN agent improves greatly andsuddenly, the learning curve for the generator may change itsdirection temporarily. Theoretically, training the DQN agentadequately in each iteration is a promising way towards tomonotony and convergence.

5 ConclusionsIn this paper, we presented an extension of standard reinforce-ment learning by considering that the environment is strate-gic and can be learned. We derived a gradient method byintroducing a dual MDP-policy pair for continuous environ-ment. To deal with discontinuous environment, we proposeda novel generative framework using reinforcement learning.We evaluated the effectiveness of our solution by consideringdesigning a Maze game. The experiments showed that ourmethods can make use of the weaknesses of agents to learnthe environment effectively.

In the future, we plan to apply the proposed methods topractical environment design tasks, such as video game de-sign [Hom and Marks, 2007], shopping space design [Penn,2005] and bots routine planning.

Proceedings of the Twenty-Seventh International Joint Conference on Artificial Intelligence (IJCAI-18)

3073

Page 7: Learning to Design Games: Strategic Environments in … · 2018. 7. 4. · Learning to Design Games: Strategic Environments in Reinforcement Learning Haifeng Zhang1, Jun Wang2, Zhiming

AcknowledgementsThis work is financially supported by National Natural Sci-ence Foundation of China (61632017) and National Key Re-search and Development Plan (2017YFB1001904).

References[Abdulhai et al., 2003] Baher Abdulhai, Rob Pringle, and

Grigoris J Karakoulas. Reinforcement learning for trueadaptive traffic signal control. Journal of TransportationEngineering, 2003.

[Busoniu and De Schutter, ] Lucian Busoniu and BartDe Schutter. A comprehensive survey of multiagentreinforcement learning.

[Cai et al., 2017] Han Cai, Kan Ren, Weinan Zhang, Klean-this Malialis, Jun Wang, Yong Yu, and Defeng Guo. Real-time bidding by reinforcement learning in display advertis-ing. In Proceedings of the Tenth ACM International Con-ference on Web Search and Data Mining, pages 661–670.ACM, 2017.

[Ceylan and Bell, 2004] Halim Ceylan and Michael GHBell. Traffic signal timing optimisation based on geneticalgorithm approach, including drivers’ routing. Trans-portation Research Part B: Methodological, 2004.

[Garcıa and Fernandez, 2015] Javier Garcıa and FernandoFernandez. A comprehensive survey on safe reinforcementlearning. JMLR, 2015.

[Gmytrasiewicz and Doshi, 2005] Piotr J Gmytrasiewiczand Prashant Doshi. A framework for sequential planningin multi-agent settings. JAIR, 2005.

[Goodfellow et al., 2014] Ian Goodfellow, Jean Pouget-Abadie, Mehdi Mirza, Bing Xu, David Warde-Farley,Sherjil Ozair, Aaron Courville, and Yoshua Bengio. Gen-erative adversarial nets. In NIPS, pages 2672–2680, 2014.

[Hom and Marks, 2007] Vincent Hom and Joe Marks. Auto-matic design of balanced board games. In Proceedings ofthe AAAI Conference on Artificial Intelligence and Inter-active Digital Entertainment (AIIDE), 2007.

[Hu and Wellman, 2003] Junling Hu and Michael P Well-man. Nash q-learning for general-sum stochastic games.Journal of Machine learning research, 2003.

[Kaelbling et al., 1996] Leslie Pack Kaelbling, Michael LLittman, and Andrew W Moore. Reinforcement learning:A survey. Journal of artificial intelligence research, 1996.

[LeCun et al., 2015] Yann LeCun, Yoshua Bengio, and Ge-offrey Hinton. Deep learning. Nature, 2015.

[Littman, 1994] Michael L Littman. Markov games as aframework for multi-agent reinforcement learning. In Pro-ceedings of the eleventh international conference on ma-chine learning, 1994.

[Mnih et al., 2013] Volodymyr Mnih, Koray Kavukcuoglu,David Silver, Alex Graves, Ioannis Antonoglou, DaanWierstra, and Martin Riedmiller. Playing atari with deepreinforcement learning. arXiv preprint arXiv:1312.5602,2013.

[Mnih et al., 2015] Volodymyr Mnih, Koray Kavukcuoglu,David Silver, Andrei A Rusu, Joel Veness, Marc G Belle-mare, Alex Graves, Martin Riedmiller, Andreas K Fidje-land, Georg Ostrovski, et al. Human-level control throughdeep reinforcement learning. Nature, 2015.

[Moore and Atkeson, 1993] Andrew W Moore and Christo-pher G Atkeson. Prioritized sweeping: Reinforcementlearning with less data and less time. Machine learning,1993.

[Morimoto and Doya, 2005] Jun Morimoto and Kenji Doya.Robust reinforcement learning. Neural computation, 2005.

[Nisan and Ronen, 2001] Noam Nisan and Amir Ronen. Al-gorithmic mechanism design. Games and Economic Be-havior, 35(1-2):166–196, 2001.

[Penn, 2005] Alan Penn. The complexity of the elementaryinterface: shopping space. In Proceedings to the 5th In-ternational Space Syntax Symposium. Akkelies van Nes,2005.

[Plappert, 2016] Matthias Plappert. keras-rl. https://github.com/keras-rl/keras-rl, 2016.

[Silver et al., 2016] David Silver, Aja Huang, Chris J Maddi-son, Arthur Guez, Laurent Sifre, George Van Den Driess-che, Julian Schrittwieser, Ioannis Antonoglou, Veda Pan-neershelvam, Marc Lanctot, et al. Mastering the game ofgo with deep neural networks and tree search. Nature,2016.

[Sorg et al., 2010] Jonathan Sorg, Richard L Lewis, andSatinder P Singh. Reward design via online gradient as-cent. In NIPS, 2010.

[Sutton and Barto, 1998] Richard S Sutton and Andrew GBarto. Reinforcement learning: An introduction. MITpress Cambridge, 1998.

[Sutton et al., 1999] Richard S Sutton, David A McAllester,Satinder P Singh, Yishay Mansour, et al. Policy gradientmethods for reinforcement learning with function approx-imation. In NIPS, 1999.

[Sutton, 1990] Richard S Sutton. Integrated architectures forlearning, planning, and reacting based on approximatingdynamic programming. In ICML, 1990.

[Togelius and Schmidhuber, 2008] Julian Togelius and Jur-gen Schmidhuber. An experiment in automatic game de-sign. In Computational Intelligence and Games, 2008.CIG’08. IEEE Symposium On. IEEE, 2008.

[Togelius et al., 2011] Julian Togelius, Georgios N Yan-nakakis, Kenneth O Stanley, and Cameron Browne.Search-based procedural content generation: A taxonomyand survey. IEEE Transactions on Computational Intelli-gence and AI in Games, 3(3):172–186, 2011.

[Vezhnevets et al., 2017] Alexander Sasha Vezhnevets, Si-mon Osindero, Tom Schaul, Nicolas Heess, Max Jader-berg, David Silver, and Koray Kavukcuoglu. Feudalnetworks for hierarchical reinforcement learning. arXivpreprint arXiv:1703.01161, 2017.

[Williams, 1992] Ronald J Williams. Simple statisticalgradient-following algorithms for connectionist reinforce-ment learning. Machine learning, 1992.

Proceedings of the Twenty-Seventh International Joint Conference on Artificial Intelligence (IJCAI-18)

3074