Slides from the 2016/2017 edition of the Video game Design and Programming course at the Politecnico di Milano. More information at http://www.polimigamecollective.org Some of the video games developed by the students during the course are available at https://polimi-game-collective.itch.io
2. 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
3. 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.
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
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-Based Map Generation
• Simple to implement
• Requires rich tileset or it can easily lead to repetitions
22
23. 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)
24. Pier Luca Lanzi
Digger Generators
• 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
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.
33. 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?
34. 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
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
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
51. Pier Luca Lanzi
Region Creation Process
1. Generation
2. Polygonisation
3. Spherification
4. Physics construction
5. AI knowledge construction
6. Decoration
51
52. 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
53. 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
55. 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
57. 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
58. 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
59. 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
60. 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
61. 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