The intelligent game designer: Game design as a new domain for automated disc...
A Case Study of Expressively Constrainable Level Design Automation Tools for a Puzzle Game
1. A Case Study of
Expressively Constrainable
Level Design Automation Tools
for a Puzzle Game
Adam M. Smith⌘⌥ (presenter),
Erik Andersen⌥, Michael Mateas⌘, Zoran
Popovid⌥
expressiveintelligencestudio centerforgamescience
⌘ UC Santa Cruz ⌥ University of Washington
amsmith@soe.ucsc.edu
FDG 2012 – Raleigh, USA
3. Towards Infinite Refraction
Automatically designed levels & progressions
Customization for individual players
Educational soundness
expressiveintelligencestudio UC Santa Cruz
4. Requirements for Design Automation
Solves hard combinatorial search problems in
reasonable amounts of time
Small amount of code
Trustable output
Hard constraints
Global optimization
expressiveintelligencestudio UC Santa Cruz
10. Example: Puzzle Solving
S2
B
x
S2
S2
x x x x x x x
S2
Tgt B
x x x x x
3/4 B
B
x x
E2
B
x
C2
Tgt Src S2
1/2 1/4 C2
S2
x
S2
Src B
x x x x
1/1 B
B
x x x
Puzzle Solution
expressiveintelligencestudio UC Santa Cruz
11. Six Design Automation Tools
Problem Original Approach New Approach
Mission Generation Custom, feed-forward ASP (AnsProlog + Lua)
algorithm (Java)
Grid Embedding Depth-first search (Java) ASP (AnsProlog)
Puzzle Solving Depth-first search (Java) ASP (AnsProlog + Lua)
S2
B
x
S2
S2
x x x x x x x
S2
Tgt B
x x x x x
3/4 B
B
x x
E2
B
x
C2
Tgt Src S2
1/2 1/4 C2
S2
x
S2
Src B
x x x x
1/1 B
B
x x x
expressiveintelligencestudio UC Santa Cruz
12. Original Mission Generator
Custom feed-forward algorithm:
Several stages that iteratively expand graph
Expression translation
Opportunistic connection
Target completion
…
Note:
Common PCG strategy
Output meets requirements by construction
expressiveintelligencestudio UC Santa Cruz
13. Original Grid Embedder
Depth-first search:
Transfer pieces from mission to spots on grid one-
by-one
Notes:
This is a tough combinatorial search problem!
DFS is complete on finite problems.
A* would be faster, but more complex.
We want to maintain less code!
expressiveintelligencestudio UC Santa Cruz
14. Original Puzzle Solver
Depth-first search:
Place pieces from tray one-by-one
Note:
Harder: math not resolved, no solution template
A* ... we really want more control over
solutions!
expressiveintelligencestudio UC Santa Cruz
15. Brief intro to ASP (not Prolog!)
ASP (“answer set programming”)
… is a declarative logic programming paradigm
focused on complex (NP and NPNP) combinatorial
search an optimization problems.
Overview:
Designer defines problem (in AnsProlog syntax).
Grounder transforms problem into SAT-like.
High-performance solver enumerates solutions.
expressiveintelligencestudio UC Santa Cruz
16. Answer Set Program Design
Guess a solution so that
none of its deduced properties are forbidden,
optionally optimizing a metric.
expressiveintelligencestudio UC Santa Cruz
17. Answer Set Program Design
“Which two numbers that multiply to 42 have
the smallest sum?”
% guess two numbers
2 { picked(1..42) } 2.
% deduce if they multiply to 42
product_ok :- picked(A), picked(B), 42==A*B.
% forbid lack of proper product
:- not product_ok.
% optimize (weighted) sum
#minimize [ picked(A)=A ].
expressiveintelligencestudio UC Santa Cruz
18. New Grid Embedder
Answer Set Program:
Guess:
Absolute positions for pieces (x;y)
Directions for laser ports (n;e;w;s)
Deduce:
Relative positions from absolute positions
Free paths from relative positions
Beam production from free paths
Expression instantiation from beams
Forbid:
Overlapping pieces
Lack of embedding for mission edges
Illegal port configurations
Notes:
How do I place and configure the pieces so that the apparent
mission subsumes the required mission?
This tool involves 75 lines of code.
expressiveintelligencestudio UC Santa Cruz
19. New Mission Generator
Answer Set Program:
Guess node and edge descriptions so that
required expressions and piece counts are
satisfied.
Notes:
“What” vs. “How” – clarifies problem
Now easy to drop in additional constraints
without redesign.
Concatenate this with embedder to make
monolithic generator!
expressiveintelligencestudio UC Santa Cruz
20. New Puzzle Solver
Answer Set Program:
Guess placement of player pieces so that all
targets are powered correctly.
Notes:
100% faithful model of game
“How many pieces are used in the simplest
solution that does not cross any beams or use an
expander?”
expressiveintelligencestudio UC Santa Cruz
21. Code Size Comparison
Problem Original Solution New Solution
Mission Generation 1,145 Java 194 AnsProlog + 38 Lua
Grid Embedding 987 Java 75 AnsProlog + 0 Lua
Puzzle Solving 988 Java 83 AnsProlog + 61 Lua
Improvements:
- Much smaller than even simple custom algorithms
- No procedural commitments
- Freely include extra constraints in input
expressiveintelligencestudio UC Santa Cruz
22. Search Time Comparison
Problem Java Search ASP Search
Mission Generation < 1 ms. < 1 ms.
Grid Embedding 650 ms.* 110 ms.
Puzzle Solving No solutions within 350 ms.
one hour*
* Including an advanced feature borrowed from the answer set solver.
Problems derived from running example:
(representative of late-stage gameplay)
expressiveintelligencestudio UC Santa Cruz
24. Lessons Learned
We rebuilt our design automation tools for a
real, deployed game on a substrate that
natively understood hard constraints and
global optimization…
… and they were smaller and went a bit faster.
… and they transformed the way we’re
designing our new game.
expressiveintelligencestudio UC Santa Cruz
25. Design Process Impact
Got out of the search algorithm design business
Got into the expressive authoring business
We clarified our design automation problems
Found new uses for tools:
Mission Gen. + Grid Embed. = Unified Puzzle Synthesizer
Solver = Puzzle Analysis Power Tool
Discovered new constraints:
Stylistic
Educational
Gained rapid prototyping tools
expressiveintelligencestudio UC Santa Cruz
Educational game focused on teaching fractionsOngoing research project at UW Center for Game ScienceI joined the Refraction team for just over a month
Replace hand-made levels and progression form original.
A few seconds maxFlexible and maintainable so we can iterate on game designTools should really do what they say
Place pieces from rightDivide and add beams with fractional powersPower spaceships with correct fraction to solve puzzleVideo from Infinite Refraction prototype
Synthesizing new puzzles and analyzing old puzzles
Input comes from our progression manager (educational goals).Output is plan of player actions; not yet a complete puzzle.Involves all of the game’s mathematical mechanics: adding, dividing, simplifying
Involves all of game’s spatial mechanics: blocking, bending, crossing.Realize one mission in several different ways.
How else can you solve our hand-made puzzles?Are there ways to solve a generated puzzle without using mathematical concept?
This was a highly reasonable algorithm to develop.Valid missions are subject to a lot of hard constraints.Requires encoding almost all non-spatial mechanics of the game in the generator.
What matters: we used a complete search algorithm – guaranteed to get answers and terminate (termination is important because not all missions are embeddable)Lots of improvements could be made if search was full-time job, but we want to make a videogame.
What matters: we used a complete search algorithm – guaranteed to get answers and terminate.Speed: speed is not an issue so long as it is under some threshold.Improvements: Can we ask for the simplest solution? The solution never crossing beams? The solution never using an expander?
ASP is LP, but not Prolog!Algorithms: things people spend there entire lives polishing. Hundreds of people have spent several decades working on this.This one is based on automatically learning new constraints from dead-ends in search space – crazy stuff!
This is the only code in whole talk.
This is the only algorithm design slide.
Previously, what counted as a valid mission was never really defined anywhere, we were just happy with what the algorithm made.Now we have a clear definition.Require and forbid arbitrary subgraphs, parameterize length of bender chains, etc.
Original solver simply produced solutions if they existed.This one accepts constraints on structure and style of solution.Now it’s a powerful analysis tool that accepts a rich language of queries.Faithful means we can use this to test educational goals: do our hand-made puzzles actually follow a math concept progression?This “simplest” thing is where we actually used optimization (not used much otherwise).When we do ask for this, it’s nice to know that we’re getting the global optimum, not the best effort.
Lua: effects of each piece on fraction, simplificationSmaller: A* or other “improvements” necessarily would have added codeSmaller: less to adjust as we explore alternative designs for Infinite gameCommitments: we can try different algorithms and heuristics without changing the code (parameters to solver)Style: particularly for puzzle solving, these style constraints become our language for formal analysis of hand-made levels
Actual times are not important… what is?Fast responses for previously intractable problems (late-state example)All of these algorithms scale exponentially with number of pieces, but this isn’t scary. We care about results on our real-world problems.Outside of adding once advanced feature to the DFS tools, neither is optimized for speed.Remember, we’re game developers, not search experts.
Adding deductive rules for detecting facets of style, we can easily drive the embedder in different directions.Good for producing results that look nice as well as being appropriate for players.We’re not done here, new style to be discovered and used.Once we find these, they often become hard constraints because we like them so much.
Smaller/faster: not at all guaranteedTransform: important result of case study.