Pier Luca Lanzi
Procedural Content Generation
Pier Luca Lanzi, Daniele Loiacono, Michele Pirovano
Pier Luca Lanzi
What is Procedural Content Generation?
Procedural Generation
with no or limited human intervention, algorithmically
of Content
of “things that affect the gameplay”, not non-player
character behavior, not the game engine
Pier Luca Lanzi
so what exactly is procedurally generated?
levels, tracks, maps, terrains, dungeons, puzzles,
buildings, trees, grass, fire, plots, descriptions,
scenarios, dialogues, quests, characters, rules,
boards, parameters, camera viewpoint, dynamics,
weapons, clothing, vehicles, personalities, etc.
Pier Luca Lanzihttp://en.wikipedia.org/wiki/Rogue_(video_game)#mediaviewer/File:Rogue_Screen_Shot_CAR.PNG
Pier Luca Lanzi
Pier Luca Lanzi
BBC Micro – 2 MHz MOS Technology 6502/6512
16-128 kB RAM 32-128 kB ROM
Pier Luca Lanzihttps://www.youtube.com/watch?v=ISR4ebdGlOk
Pier Luca Lanzi
Pier Luca Lanzi
Pier Luca Lanzi
What the ingredients?
domain knowledge
artificial intelligence
structured randomness
multi-layering
filters, limits & restrictions
specialized algorithms
gameplay integration
Pier Luca Lanzi
Ingredients #1 & #2
Domain Knowledge & Artificial Intelligence
•  Domain Knowledge
§ To generate something you need to know it
§ PCG typically aims at building an artificial level
designer, usually needs domain knowledge
about level design
•  Artificial Intelligence
§ Need algorithms that can work on complex
knowledge and generate plausible content
§ Search-based methods, L-systems, evolutionary
computation, fractals, cellular automata,
agent-based methods, planning, etc.
11
Pier Luca Lanzi
Pier Luca Lanzi
ingredient #3
structured randomness
things look like they have been randomly
generated but it is not completely at random!
Pier Luca Lanzi
f(x) = sin(x)
Pier Luca Lanzi
Pier Luca Lanzi
they both look like “noise”
but one of them feels like it has structure…
it is structured randomness
Pier Luca Lanzi
Pier Luca Lanzi
Example: Building Mario Levels
•  Library of chuncks.
•  Irregular in size.
•  Mixed purpose:
§ Mainly geometry.
§ Mainly gameplay.
•  Anchor points (Mario)
18
Pier Luca Lanzi
Algorithm
•  Chunk Filtering
§ Some chunks just don‘t match the current level.
•  Chunk Selection
§ Various metrics, randomness and designer settings.
•  Chunk Insertion
§ Remove overlapping components.
•  Post-Processing
§ Cosmetic and gameplay adjustments.
19
Pier Luca Lanzi
Infinite Mario Level 20
Pier Luca Lanzi
Map & Cave Generators
•  Cave generators typically are based on Cellular Automata
•  Map generators typically an approach
§ Tile-Based
§ Digger
§ Uniform
21
Pier Luca Lanzi
Tile-Based Map Generation
•  Simple to implement
•  Requires rich tileset or it can easily lead to repetitions
22
Pier Luca Lanzi
Uniform Map Generators
•  Two steps
§ First create rooms based on
a high level grid
§ Next, create the corridors
to connect the rooms
•  Rather simple to implement
•  Limited topology by the room
shape and the grid
23
Rogue (1980)
Pier Luca Lanzi
Digger Generators
•  Simulates the behavior of a mole that digs its den
•  Generates maps that have a tree like structure
24
Pier Luca Lanzi
ingredient #4
multi-layering
typically more layers of procedural
content generation are applied in sequence
Pier Luca Lanzi
•  Warzone 2100
§ Heights & Cliffs
§ Roads
§ Textures
§ Player Bases
§ Local Features
•  Civilization 4
§ Fractal Heightfield
§ Plate Tectonics
§ Tile Types
§ Rivers and Lakes
§ Map Bonuses
Pier Luca Lanzi
ingredient #5
Filters, Limits & Restrictions
“In Civ3 I would say we even shipped with a sub-standard resource
placement algorithm where all the iron could be concentrated in just
a few small locations on the map, and for one player there may be
literally no way for them to build swordsmen.” – Soren Johnson
"With Civ4 we instituted randomness with limitations. There
always has to be a minimum distance between each element of
iron, or each element of horses, and that completely solved the
problem.” – Soren Johnson
Pier Luca Lanzi
ingredient #6
specialized algorithms
placing special items, requires special tricks
this tricks must be encoded in the PCG
Pier Luca Lanzi
1.  Connect all bases, the resources,
pick three random points and
connect them
2.  Apply a customize A* heuristic
and reuse roads!
3.  Customize A* heuristic with
randomize cost of non-road
grid cells.
Pier Luca Lanzi
ingredient #7
gameplay integration
Is it fun to play? Is the progression adequate?
Pier Luca Lanzi
Pier Luca Lanzi
is this all there is?
Pier Luca Lanzi
PCG
Is it done online?
Or offline?
Is it necessary content?
Or optional?
Do you use random
seeds or parameter
vectors?
Is it stochastic?
Or deterministic?
Generate and test?
Constructive?
Pier Luca Lanzi
Domain Knowledge
•  To build an artificial intelligence, you typically need a lot of domain knowleddge
•  When using PCG you‘re building an artificial level designer, so you usually need domain
knowledge about level design
•  So you‘ll probably need a real level designer and people who have some experience
•  When you build a particular level you don‘t need to understand the general concepts
behind the game mechanics as much as when you do it procedurally
•  When you go procedurally, you have to understand all the space of options you are
creating and understand how your game mechanics tie in with the level
•  Provide ways to customize your algorithms and tools for controlling and visualizing the
result
34
Pier Luca Lanzi
Inputs & Senses
•  Procedural generation algorithms
work on different sets of inputs
and actions (when compared to
traditional AI)
•  Examples of Inputs
§ Line of Sight
§ Point Distance (A*, Dijkstra)
§ Obstacles & Clearance
§ Height
•  Examples of Actions
§ Place resources
§ Layout buildings
§ Create roads/rivers
§ Adjust terrain
35
Pier Luca Lanzi
Frozen Synapse
Pier Luca Lanzi
Level Generator #1 37
Pier Luca Lanzi
Human Designed Levels 38
Pier Luca Lanzi
Algorithm
1. 2.
3. 4.
39
Pier Luca Lanzi
Step 5. 40
Pier Luca Lanzi
Step 6. Walls & Doors 41
Pier Luca Lanzi
Step 7. Windows & More Doors 42
Pier Luca Lanzi
Step 8. Box Cover 43
Pier Luca Lanzi
Example #1 44
Pier Luca Lanzi
Example #2 45
Pier Luca Lanzi
Example #3 46
Pier Luca Lanzi
Example #4 47
Pier Luca Lanzi
No Man’s Sky
from nucl.ai conference
Pier Luca Lanzi
Philosophy
•  Artist directed
•  Procedural generation is irrelevant to end user
•  Motivation
§ Game world scale
§ Output from small team
§ Unexpected outputs
§ Individual experiences
•  Engine agnostic to content origin
•  Mix of general and specific techniques
49
Pier Luca Lanzi
Multi-Layered Generation 50
Pier Luca Lanzi
Region Creation Process
1. Generation
2. Polygonisation
3. Spherification
4. Physics construction
5. AI knowledge construction
6. Decoration
51
Pier Luca Lanzi
Generation Requirements
•  Directable and consistent
•  Real-time
•  Varied
•  Real world and abstract shapes
•  Easy to modify and add to
•  Data local
52
Pier Luca Lanzi
Perlin/Simplex Noise
•  Well known techniques
§ Widely applicable
§ Scalable
§ Repetitive
§ Insufficient
•  Modified version
§ Perlin worms
§ Noise with a threshold
§ Paths, caves, lines
53
Pier Luca Lanzi
Structured Shapes
•  Cellular noise patterns
•  Worley/Voronoi Noise
•  Pickpoints
•  Calculate min distances
•  Cliffs, paths, regions...
54
Pier Luca Lanzi
Mathematical Solids
•  Gielis, Johan (2003), "A generic geometric transformation that
unifies a wide range of natural and abstract shapes", American
Journal of Botany
•  Natural looking shape additions
55
Pier Luca Lanzi
Map Generation in In Verbis Virtus
(Mattia Ferrari)
56
Pier Luca Lanzi
Map Generation for In Verbis Virtus
• Requirements
§ Control over the complexity of the generated maps
§ Continuous representation
§ Avoid decors overlaps
•  Combination of diggers
and uniform approaches
•  Map elements from human
designed levels
§ Walls
§ Doors
§ Decors
57
Pier Luca Lanzi
Step 1: Growth
•  Similar to the digger approach
•  Builds a map structured as a tree
•  Growth is controlled by a set of
parameters, including,
§ Type of elements
§ Number of rooms
§ Number of branches
§ Available area
58
Pier Luca Lanzi
Step 2 & 3: Additional Corridors and
Deadline Elimination
•  Additional Corridors
§ Similar to uniform generators
§ Based on the required percentage
of connections to create
§ Distance between areas
•  Deadline Elimination
§ Based on the percentage
of dead ends to eliminate
59
Pier Luca Lanzi
Map Evaluation
•  Given a map we needed to compute several statistics to filter the
most interesting ones
•  Maps are encoded as graphs
•  Compute several metrics
§ Max distance among rooms
§ Reachability
§ Flow
§ …
60
Pier Luca Lanzi
Some Findings
•  75% or more additional connections increase the complexity of
the map without improving complica le mappe senza migliorare la
raggiungibilità
•  The generator is robust with
respect to the room shape
•  By eliminating the start room,
we can reduce the reachability
over the entire map
Pier Luca Lanzi
Mappa generata
Pier Luca Lanzi
Video finale
Pier Luca Lanzi
we can do it, so can you!
Pier Luca Lanzihttp://trackgen.pierlucalanzi.net
Pier Luca Lanzi
http://www.youtube.com/watch?v=uIUYWzdMXog
Pier Luca Lanzihttp://www.michelepirovano.com/portfolio_swordgenerator.php
Pier Luca Lanzihttp://www.michelepirovano.com/portfolio_swordgenerator.php
Pier Luca Lanzi
http://www.facebook.com/polimigamecollective
https://twitter.com/@POLIMIGC
http://www.youtube.com/PierLucaLanzi
http://www.polimigamecollective.org

Procedural Content Generation

  • 1.
    Pier Luca Lanzi ProceduralContent Generation Pier Luca Lanzi, Daniele Loiacono, Michele Pirovano
  • 2.
    Pier Luca Lanzi Whatis Procedural Content Generation? Procedural Generation with no or limited human intervention, algorithmically of Content of “things that affect the gameplay”, not non-player character behavior, not the game engine
  • 3.
    Pier Luca Lanzi sowhat exactly is procedurally generated? levels, tracks, maps, terrains, dungeons, puzzles, buildings, trees, grass, fire, plots, descriptions, scenarios, dialogues, quests, characters, rules, boards, parameters, camera viewpoint, dynamics, weapons, clothing, vehicles, personalities, etc.
  • 4.
  • 5.
  • 6.
    Pier Luca Lanzi BBCMicro – 2 MHz MOS Technology 6502/6512 16-128 kB RAM 32-128 kB ROM
  • 7.
  • 8.
  • 9.
  • 10.
    Pier Luca Lanzi Whatthe ingredients? domain knowledge artificial intelligence structured randomness multi-layering filters, limits & restrictions specialized algorithms gameplay integration
  • 11.
    Pier Luca Lanzi Ingredients#1 & #2 Domain Knowledge & Artificial Intelligence •  Domain Knowledge § To generate something you need to know it § PCG typically aims at building an artificial level designer, usually needs domain knowledge about level design •  Artificial Intelligence § Need algorithms that can work on complex knowledge and generate plausible content § Search-based methods, L-systems, evolutionary computation, fractals, cellular automata, agent-based methods, planning, etc. 11
  • 12.
  • 13.
    Pier Luca Lanzi ingredient#3 structured randomness things look like they have been randomly generated but it is not completely at random!
  • 14.
  • 15.
  • 16.
    Pier Luca Lanzi theyboth look like “noise” but one of them feels like it has structure… it is structured randomness
  • 17.
  • 18.
    Pier Luca Lanzi Example:Building Mario Levels •  Library of chuncks. •  Irregular in size. •  Mixed purpose: § Mainly geometry. § Mainly gameplay. •  Anchor points (Mario) 18
  • 19.
    Pier Luca Lanzi Algorithm • Chunk Filtering § Some chunks just don‘t match the current level. •  Chunk Selection § Various metrics, randomness and designer settings. •  Chunk Insertion § Remove overlapping components. •  Post-Processing § Cosmetic and gameplay adjustments. 19
  • 20.
  • 21.
    Pier Luca Lanzi Map& Cave Generators •  Cave generators typically are based on Cellular Automata •  Map generators typically an approach § Tile-Based § Digger § Uniform 21
  • 22.
    Pier Luca Lanzi Tile-BasedMap Generation •  Simple to implement •  Requires rich tileset or it can easily lead to repetitions 22
  • 23.
    Pier Luca Lanzi UniformMap Generators •  Two steps § First create rooms based on a high level grid § Next, create the corridors to connect the rooms •  Rather simple to implement •  Limited topology by the room shape and the grid 23 Rogue (1980)
  • 24.
    Pier Luca Lanzi DiggerGenerators •  Simulates the behavior of a mole that digs its den •  Generates maps that have a tree like structure 24
  • 25.
    Pier Luca Lanzi ingredient#4 multi-layering typically more layers of procedural content generation are applied in sequence
  • 26.
    Pier Luca Lanzi • Warzone 2100 § Heights & Cliffs § Roads § Textures § Player Bases § Local Features •  Civilization 4 § Fractal Heightfield § Plate Tectonics § Tile Types § Rivers and Lakes § Map Bonuses
  • 27.
    Pier Luca Lanzi ingredient#5 Filters, Limits & Restrictions “In Civ3 I would say we even shipped with a sub-standard resource placement algorithm where all the iron could be concentrated in just a few small locations on the map, and for one player there may be literally no way for them to build swordsmen.” – Soren Johnson "With Civ4 we instituted randomness with limitations. There always has to be a minimum distance between each element of iron, or each element of horses, and that completely solved the problem.” – Soren Johnson
  • 28.
    Pier Luca Lanzi ingredient#6 specialized algorithms placing special items, requires special tricks this tricks must be encoded in the PCG
  • 29.
    Pier Luca Lanzi 1. Connect all bases, the resources, pick three random points and connect them 2.  Apply a customize A* heuristic and reuse roads! 3.  Customize A* heuristic with randomize cost of non-road grid cells.
  • 30.
    Pier Luca Lanzi ingredient#7 gameplay integration Is it fun to play? Is the progression adequate?
  • 31.
  • 32.
    Pier Luca Lanzi isthis all there is?
  • 33.
    Pier Luca Lanzi PCG Isit done online? Or offline? Is it necessary content? Or optional? Do you use random seeds or parameter vectors? Is it stochastic? Or deterministic? Generate and test? Constructive?
  • 34.
    Pier Luca Lanzi DomainKnowledge •  To build an artificial intelligence, you typically need a lot of domain knowleddge •  When using PCG you‘re building an artificial level designer, so you usually need domain knowledge about level design •  So you‘ll probably need a real level designer and people who have some experience •  When you build a particular level you don‘t need to understand the general concepts behind the game mechanics as much as when you do it procedurally •  When you go procedurally, you have to understand all the space of options you are creating and understand how your game mechanics tie in with the level •  Provide ways to customize your algorithms and tools for controlling and visualizing the result 34
  • 35.
    Pier Luca Lanzi Inputs& Senses •  Procedural generation algorithms work on different sets of inputs and actions (when compared to traditional AI) •  Examples of Inputs § Line of Sight § Point Distance (A*, Dijkstra) § Obstacles & Clearance § Height •  Examples of Actions § Place resources § Layout buildings § Create roads/rivers § Adjust terrain 35
  • 36.
  • 37.
    Pier Luca Lanzi LevelGenerator #1 37
  • 38.
    Pier Luca Lanzi HumanDesigned Levels 38
  • 39.
  • 40.
  • 41.
    Pier Luca Lanzi Step6. Walls & Doors 41
  • 42.
    Pier Luca Lanzi Step7. Windows & More Doors 42
  • 43.
    Pier Luca Lanzi Step8. Box Cover 43
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
    Pier Luca Lanzi NoMan’s Sky from nucl.ai conference
  • 49.
    Pier Luca Lanzi Philosophy • Artist directed •  Procedural generation is irrelevant to end user •  Motivation § Game world scale § Output from small team § Unexpected outputs § Individual experiences •  Engine agnostic to content origin •  Mix of general and specific techniques 49
  • 50.
  • 51.
    Pier Luca Lanzi RegionCreation Process 1. Generation 2. Polygonisation 3. Spherification 4. Physics construction 5. AI knowledge construction 6. Decoration 51
  • 52.
    Pier Luca Lanzi GenerationRequirements •  Directable and consistent •  Real-time •  Varied •  Real world and abstract shapes •  Easy to modify and add to •  Data local 52
  • 53.
    Pier Luca Lanzi Perlin/SimplexNoise •  Well known techniques § Widely applicable § Scalable § Repetitive § Insufficient •  Modified version § Perlin worms § Noise with a threshold § Paths, caves, lines 53
  • 54.
    Pier Luca Lanzi StructuredShapes •  Cellular noise patterns •  Worley/Voronoi Noise •  Pickpoints •  Calculate min distances •  Cliffs, paths, regions... 54
  • 55.
    Pier Luca Lanzi MathematicalSolids •  Gielis, Johan (2003), "A generic geometric transformation that unifies a wide range of natural and abstract shapes", American Journal of Botany •  Natural looking shape additions 55
  • 56.
    Pier Luca Lanzi MapGeneration in In Verbis Virtus (Mattia Ferrari) 56
  • 57.
    Pier Luca Lanzi MapGeneration for In Verbis Virtus • Requirements § Control over the complexity of the generated maps § Continuous representation § Avoid decors overlaps •  Combination of diggers and uniform approaches •  Map elements from human designed levels § Walls § Doors § Decors 57
  • 58.
    Pier Luca Lanzi Step1: Growth •  Similar to the digger approach •  Builds a map structured as a tree •  Growth is controlled by a set of parameters, including, § Type of elements § Number of rooms § Number of branches § Available area 58
  • 59.
    Pier Luca Lanzi Step2 & 3: Additional Corridors and Deadline Elimination •  Additional Corridors § Similar to uniform generators § Based on the required percentage of connections to create § Distance between areas •  Deadline Elimination § Based on the percentage of dead ends to eliminate 59
  • 60.
    Pier Luca Lanzi MapEvaluation •  Given a map we needed to compute several statistics to filter the most interesting ones •  Maps are encoded as graphs •  Compute several metrics § Max distance among rooms § Reachability § Flow § … 60
  • 61.
    Pier Luca Lanzi SomeFindings •  75% or more additional connections increase the complexity of the map without improving complica le mappe senza migliorare la raggiungibilità •  The generator is robust with respect to the room shape •  By eliminating the start room, we can reduce the reachability over the entire map
  • 62.
  • 63.
  • 64.
    Pier Luca Lanzi wecan do it, so can you!
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.