Procedural Generation
   of Game content
Procedural Content
                     Generation
    • Procedural Content Generation is the process of
     using techniques based on AI, maths and other
     disciplines to automatically create game content.
    • Consider a game set in a city
      ‣ How many unique buildings are there in a city?
      ‣ How frequently could you duplicate a building before
        players noticed?
      ‣ What about trees?
2
Trees

    • Trees are complicated.
      ‣ Easy to get wrong
      ‣ The same tree over and over breaks immersion
      ‣ Lots of trees in a forest
    • You could pay an artist to sit and come up with the
     look of a whole bunch of trees, then model them,
     put them into levels etc.
      ‣ Costly, time consuming, bloats game’s size
3
Lindenmayer Systems

    • L-Systems are recursive grammar rewriting
     frameworks.
    • Defined as a tuple (A, S, R)
       ‣ Alphabet of symbols
       ‣ Starting state
       ‣ Rules that are used to rewrite the initial state
    • Great for creating fractal patterns
    • Iterate n times to get interesting shapes appearing
4
Koch Snowflakes




    • A : variables - { f } constants - {+, -}
    • S :f - - f - - f
    • R :f > f + f - - f + f



5
Koch Snowflakes




    • Board work




6
Koch Snowflakes


    • n=0 : f -- f -- f
    • n=1 : f + f -- f + f -- f + f -- f + f -- f + f -- f + f
    • n=2 : f + f -- f + f + f + f + f -- f + f -- f + f -- f + f + f
     + f -- f + f -- f + f -- f + f + f + f + f -- f + f -- f + f -- f
     + f + f + f -- f + f -- f + f -- f + f + f + f + f -- f + f -- f
     + f -- f + f + f + f -- f + f

7
Koch Snowflakes



    • Assign meaning to each component of the alphabet
    • f draw forwards
    • + turn 60 degrees right
    • - turn 60 degrees left



8
Koch Snowflakes




         N=0
9
Koch Snowflakes




          N=1
10
Koch Snowflakes




          N=2
11
Koch Snowflakes




          N=3
12
Koch Snowflakes




          N=3
13
L-System Example


     • A :Variables : {X, F} Constants : {+, -}
     • S :X
     • R : {X > F - [ [X] + X ] + F [ + F X ] - X, F > F F}
     • Meanings :
        ‣ F draws forward, X is a dummy variable (no real action)
        ‣ - + left and right 25 degrees
        ‣ [ begins subtree, ] returns to start of sub tree

14
L-System Example




15
L-System Example




16
Rocks


     • Rocks have the same problem as trees.
     • Seeing the same rock over and over has the same
      issues as trees.
     • Rocks can also be generated using L-Systems
       ‣ “SpeedRock: Procedural rocks through grammar and
         evolution” Dart, Di Rossi and Togelius, Proceedings of the
         FDG Workshop on Procedural Content Generation, 2011

17
Evolving L-Systems


     • It’s possible to take an L-System definition and
      represent it chromosomally.
     • From there we can apply all the kinds of tricks.
        ‣ Clustering
        ‣ Evolution
     • We can evolve “art” based on our L-System
      representation

18
The Morph Lab


     • Part of the ALife suite at http://alife.fusebox.com
     • Starts from a single dot, player select the “fittest”
      candidate from a selection of drawn L-Systems.
     • Chromosome defines size, colour, rewrite rules and
      number of iterations to rewrite for.
     • Rapidly create interesting distinct patterns.

19
The Morph Lab




     • Demo




20
Weaponry


     • Procedural generation can be used for a lot more
      than art.
     • We can use it to generate the weapons that the
      player might find in a game.
       ‣ Not just the models of the weapons
       ‣ Also the stats and effects


21
Borderlands




22
Borderlands

     • Borderlands has over 650,000 weapons in it.
       ‣ Different stats
       ‣ Different models
       ‣ Different names
     • In many ways, just a simple combinatorics problem
       ‣ Given a set of different options for these various
         parameters, how many ways can we combine them?
     • Beats sitting down and designing each one by hand!
23
Galactic Arms Race




24
Galactic Arms Race

     • GAR uses the cgNEAT algorithm to evolve different
      types of weaponry in the game.
     • Fitness is based on the amount a weapon is used
     • Parameters evolved include
       ‣ Colour
       ‣ Effects
       ‣ Trajectory
       ‣ Bullet lifetime
25
Galactic Arms Race




26
Galactic Arms Race


     • Important - none of the behaviour the GAR
      weapons exhibit is defined by the developer
     • Completely emergent
     • Randomised weapons guided by player preference
     • Interesting effects appear quickly
     • Balance could be difficult

27
Quests


     • Typically Role Playing Games (RPG) involve “quests”
     • A mechanic for giving the player tasks and goals.
     • Two different types
        ‣ Storyline - part of the narrative of the game
        ‣ Side-quest - time-wasting stuff that has no impact other
         than giving the player things to do.


28
Skyrim




29
Skyrim - Radiant


     • Skyrim is the debut for Bethesda’s Radiant quest
      generator.
     • Various quest-givers across the world are
      generating quests procedurally.
     • Not part of the core story arcs.
     • Can have an effect on the world.

30
Example - Thieves Guild


     • The Thieves Guild is a group that the player can join
     • Major quest arc related to the group
     • Range of side quests
        ‣ Burglary, pickpocket, “shill” jobs
     • Each type of quest has standard objectives
     • The location of the objective changes each time, as
      do the details e.g. what to steal.
31
Mechanics

     • In order to adequately execute this kind of system
       ‣ Need a rich selection of potential locations
       ‣ More immersive when we can talk about specific people
         rather than generic villagers
     • What does the player get from this diversion?
       ‣ Reward
       ‣ Experience and reputation
       ‣ Perhaps affects the world more broadly
32
Levels


     • It’s possible not only to generate components of the
      game such as scenery and objective procedurally.
     • Also entire environments for the player to
      experience.
     • Keeps the game fresh
     • Enhances replayability

33
Tiny Wings


     • iPhone game based around a bird
     • Touch the screen to fold wings, untouch to flap
      wings
     • Landscape features valleys
        ‣ Slide down the valley to gain speed
        ‣ Flip up the other side to fly through the air
     • Aim is to get as far as possible in a given time
34
Tiny Wings




35
Tiny Wings


     • Landscape is broken into discrete islands
     • Each island has a general character
        ‣ 1st island has gentle rolling hills
        ‣ 4th island has sharp, deep valleys
     • The level changes every day, but the overall tone of
      it doesn’t.
     • How can this be achieved?
36
Parametric Definitions


     • Landscape in Tiny Wings is effectively defined by a
      single function for each island.
       ‣ Sinosoidal function.
       ‣ (More likely a unification of several sinosoidals)
     • We can define the function with parameters
       ‣ The non-parameterised components define the character
       ‣ The parameters define the specific shape for today’s level

37
Parametric Definitions




     Sin(x) - note the characteristic roll
38
Parametric Definitions




     Contrast with 2sin(2x) - totally different “character”
39
Parametric Definitions




     2sin(2x) with 2.3sin(1.8x+15)
40
Levels


     • We can specify the level design in Tiny Wings as a
      parameterised function.
     • We can update the parameters on a regular basis to
      alter the experience the player gets.
     • We can control the way the experience changes by
      how the parameters are applied.

41
Difficulty

     • Lots of games give players options of what difficulty
      they want.
     • There are obvious (naive) ways we can alter
      difficulty.
        ‣ Give bad guys more health / make player weapons deal
         less damage.
        ‣ More bad guys.
        ‣ Fewer items, less ammo
42
Difficulty


     • We can also do stuff that’s way more subtle.
       ‣ Alter timings
       ‣ Decrease visibility of “signposts” (markers within the
         level that cue the player - often subconsciously - where
         to go)
       ‣ Mess around with the design of the level in more detail


43
Difficulty of Levels


     • We can make the same kind of manipulations to the
      functions generating a Tiny Wings level dependent
      on what difficulty the player has selected
        ‣ Easy level gives the functions a more gentle curve
        ‣ Hard level gives the functions a harsher minima
     • Even within the different islands characters, we can
      generate “easy” versions and “hard” versions.

44
Difficulty in a
                     Mario-style game


     • Consider a game like Mario
     • Side scrolling
        ‣ Lots of jumping over obstacles
        ‣ Gaps to jump between
     • How can we modify the difficulty of the level?


45
Summary


     • Procedurally Generated Content
       ‣ In-game assets
       ‣ Levels
       ‣ Quests
     • Introduced concept of difficulty in games
     • Talked about the difference between obvious and
      subtle changes in difficulty

46
Next Lecture




     • Talking about how we can use the player models we
      created last week to understand video games better
     • Using these models to build better content



47

Lecture 5 - Procedural Content Generation

  • 1.
    Procedural Generation of Game content
  • 2.
    Procedural Content Generation • Procedural Content Generation is the process of using techniques based on AI, maths and other disciplines to automatically create game content. • Consider a game set in a city ‣ How many unique buildings are there in a city? ‣ How frequently could you duplicate a building before players noticed? ‣ What about trees? 2
  • 3.
    Trees • Trees are complicated. ‣ Easy to get wrong ‣ The same tree over and over breaks immersion ‣ Lots of trees in a forest • You could pay an artist to sit and come up with the look of a whole bunch of trees, then model them, put them into levels etc. ‣ Costly, time consuming, bloats game’s size 3
  • 4.
    Lindenmayer Systems • L-Systems are recursive grammar rewriting frameworks. • Defined as a tuple (A, S, R) ‣ Alphabet of symbols ‣ Starting state ‣ Rules that are used to rewrite the initial state • Great for creating fractal patterns • Iterate n times to get interesting shapes appearing 4
  • 5.
    Koch Snowflakes • A : variables - { f } constants - {+, -} • S :f - - f - - f • R :f > f + f - - f + f 5
  • 6.
    Koch Snowflakes • Board work 6
  • 7.
    Koch Snowflakes • n=0 : f -- f -- f • n=1 : f + f -- f + f -- f + f -- f + f -- f + f -- f + f • n=2 : f + f -- f + f + f + f + f -- f + f -- f + f -- f + f + f + f -- f + f -- f + f -- f + f + f + f + f -- f + f -- f + f -- f + f + f + f -- f + f -- f + f -- f + f + f + f + f -- f + f -- f + f -- f + f + f + f -- f + f 7
  • 8.
    Koch Snowflakes • Assign meaning to each component of the alphabet • f draw forwards • + turn 60 degrees right • - turn 60 degrees left 8
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
    L-System Example • A :Variables : {X, F} Constants : {+, -} • S :X • R : {X > F - [ [X] + X ] + F [ + F X ] - X, F > F F} • Meanings : ‣ F draws forward, X is a dummy variable (no real action) ‣ - + left and right 25 degrees ‣ [ begins subtree, ] returns to start of sub tree 14
  • 15.
  • 16.
  • 17.
    Rocks • Rocks have the same problem as trees. • Seeing the same rock over and over has the same issues as trees. • Rocks can also be generated using L-Systems ‣ “SpeedRock: Procedural rocks through grammar and evolution” Dart, Di Rossi and Togelius, Proceedings of the FDG Workshop on Procedural Content Generation, 2011 17
  • 18.
    Evolving L-Systems • It’s possible to take an L-System definition and represent it chromosomally. • From there we can apply all the kinds of tricks. ‣ Clustering ‣ Evolution • We can evolve “art” based on our L-System representation 18
  • 19.
    The Morph Lab • Part of the ALife suite at http://alife.fusebox.com • Starts from a single dot, player select the “fittest” candidate from a selection of drawn L-Systems. • Chromosome defines size, colour, rewrite rules and number of iterations to rewrite for. • Rapidly create interesting distinct patterns. 19
  • 20.
    The Morph Lab • Demo 20
  • 21.
    Weaponry • Procedural generation can be used for a lot more than art. • We can use it to generate the weapons that the player might find in a game. ‣ Not just the models of the weapons ‣ Also the stats and effects 21
  • 22.
  • 23.
    Borderlands • Borderlands has over 650,000 weapons in it. ‣ Different stats ‣ Different models ‣ Different names • In many ways, just a simple combinatorics problem ‣ Given a set of different options for these various parameters, how many ways can we combine them? • Beats sitting down and designing each one by hand! 23
  • 24.
  • 25.
    Galactic Arms Race • GAR uses the cgNEAT algorithm to evolve different types of weaponry in the game. • Fitness is based on the amount a weapon is used • Parameters evolved include ‣ Colour ‣ Effects ‣ Trajectory ‣ Bullet lifetime 25
  • 26.
  • 27.
    Galactic Arms Race • Important - none of the behaviour the GAR weapons exhibit is defined by the developer • Completely emergent • Randomised weapons guided by player preference • Interesting effects appear quickly • Balance could be difficult 27
  • 28.
    Quests • Typically Role Playing Games (RPG) involve “quests” • A mechanic for giving the player tasks and goals. • Two different types ‣ Storyline - part of the narrative of the game ‣ Side-quest - time-wasting stuff that has no impact other than giving the player things to do. 28
  • 29.
  • 30.
    Skyrim - Radiant • Skyrim is the debut for Bethesda’s Radiant quest generator. • Various quest-givers across the world are generating quests procedurally. • Not part of the core story arcs. • Can have an effect on the world. 30
  • 31.
    Example - ThievesGuild • The Thieves Guild is a group that the player can join • Major quest arc related to the group • Range of side quests ‣ Burglary, pickpocket, “shill” jobs • Each type of quest has standard objectives • The location of the objective changes each time, as do the details e.g. what to steal. 31
  • 32.
    Mechanics • In order to adequately execute this kind of system ‣ Need a rich selection of potential locations ‣ More immersive when we can talk about specific people rather than generic villagers • What does the player get from this diversion? ‣ Reward ‣ Experience and reputation ‣ Perhaps affects the world more broadly 32
  • 33.
    Levels • It’s possible not only to generate components of the game such as scenery and objective procedurally. • Also entire environments for the player to experience. • Keeps the game fresh • Enhances replayability 33
  • 34.
    Tiny Wings • iPhone game based around a bird • Touch the screen to fold wings, untouch to flap wings • Landscape features valleys ‣ Slide down the valley to gain speed ‣ Flip up the other side to fly through the air • Aim is to get as far as possible in a given time 34
  • 35.
  • 36.
    Tiny Wings • Landscape is broken into discrete islands • Each island has a general character ‣ 1st island has gentle rolling hills ‣ 4th island has sharp, deep valleys • The level changes every day, but the overall tone of it doesn’t. • How can this be achieved? 36
  • 37.
    Parametric Definitions • Landscape in Tiny Wings is effectively defined by a single function for each island. ‣ Sinosoidal function. ‣ (More likely a unification of several sinosoidals) • We can define the function with parameters ‣ The non-parameterised components define the character ‣ The parameters define the specific shape for today’s level 37
  • 38.
    Parametric Definitions Sin(x) - note the characteristic roll 38
  • 39.
    Parametric Definitions Contrast with 2sin(2x) - totally different “character” 39
  • 40.
    Parametric Definitions 2sin(2x) with 2.3sin(1.8x+15) 40
  • 41.
    Levels • We can specify the level design in Tiny Wings as a parameterised function. • We can update the parameters on a regular basis to alter the experience the player gets. • We can control the way the experience changes by how the parameters are applied. 41
  • 42.
    Difficulty • Lots of games give players options of what difficulty they want. • There are obvious (naive) ways we can alter difficulty. ‣ Give bad guys more health / make player weapons deal less damage. ‣ More bad guys. ‣ Fewer items, less ammo 42
  • 43.
    Difficulty • We can also do stuff that’s way more subtle. ‣ Alter timings ‣ Decrease visibility of “signposts” (markers within the level that cue the player - often subconsciously - where to go) ‣ Mess around with the design of the level in more detail 43
  • 44.
    Difficulty of Levels • We can make the same kind of manipulations to the functions generating a Tiny Wings level dependent on what difficulty the player has selected ‣ Easy level gives the functions a more gentle curve ‣ Hard level gives the functions a harsher minima • Even within the different islands characters, we can generate “easy” versions and “hard” versions. 44
  • 45.
    Difficulty in a Mario-style game • Consider a game like Mario • Side scrolling ‣ Lots of jumping over obstacles ‣ Gaps to jump between • How can we modify the difficulty of the level? 45
  • 46.
    Summary • Procedurally Generated Content ‣ In-game assets ‣ Levels ‣ Quests • Introduced concept of difficulty in games • Talked about the difference between obvious and subtle changes in difficulty 46
  • 47.
    Next Lecture • Talking about how we can use the player models we created last week to understand video games better • Using these models to build better content 47