SLIDE 1 SIMULATING
A FREEZING SOCIETY BUILDING THE AI OF FROSTPUNK
SLIDE 2 HELLO
I’M MACIEJ CZERWONKA GAMEPLAY PROGRAMMER | SIMULATION TEAM GAME DEVELOPER FOR 15 YEARS @Calveit
SLIDE 4
FROSTPUNK AI BUILDING BLOCKS PERFORMANCE
SLIDE 5
FROSTPUNK
SLIDE 6
SLIDE 7
SIMULATION
SLIDE 8
AI BUILDING BLOCKS
SLIDE 9
AGENTS
SLIDE 10 Agent
- Core simulation element
- Represents a citizen
- Interacts with environment
SLIDE 11 State
- Agent memory and needs
- Private set of data
- Accessable only for decision
tree
SLIDE 12 Perception
- Eyes and ears of the agent
- Translates environment to
format usable by decision tree
SLIDE 13 Decision tree
- Agent brain
- Has access to state and
perception
- Behaviour tree
- Affects the state
SLIDE 14
ACTIVITIES
SLIDE 15 Activity
- Verb of a simulation
- Not atomic
- Not an action
SLIDE 16 Activity tree
- Action factory (produce actions
for agents)
- Behaviour tree
- Multiple agents allowed
SLIDE 17 Target selector
- Matcher (assigns agents to
- bjects)
SLIDE 18 Priority
- Number
- Decides the order
- Easy to change
! Hard to maintain
SLIDE 19 Activity list
- One dimensional list
- Decides the order
- Transparency
- Visibility
- Cheap maintenance
SLIDE 20 Preferences
- Set of values
- Agent decision
- Fallback activities always in the
collection
SLIDE 21 Action
- Controlling agent
- Can influence state
- Can influence visuals
SLIDE 22 Plan
- Collection of actions
- FIFO
- Fed by activity tree
- Consumed by agent when
current action is finished
SLIDE 23
POINT OF INTEREST
SLIDE 24 Point of interest
- POI
- Agents perform activities here
- Attached to building or other
place in the game
- Place can have more than 1 POI
SLIDE 25 Activity
- Activity type available at POI
- Each POI declares an activity
SLIDE 26 Conditions
- Collection of expressions
- Evaluates to boolean value,
which decides if active
SLIDE 27 Space
- Range (eg. 1-10)
- How many agents can perform
activity here
SLIDE 28 Target
- Agent always has a target
- Binds agent with POI
- Idle agents have target
- Dead agents have target
SLIDE 29
SLIDE 30 Is this model good enough?
- Doctors leave their patients to build a road
- Children fight in Fight Club
- Hunters return from 3-day expedition to get a snack
- Guards join the protest, they were supposed to disperse
- Prison workers leave their work to bury the dead, letting convicts escape
No, it is not. We need to distinguish agents!
SLIDE 31
AGENTS
SLIDE 32
AGENTS
SLIDE 33
AGENTS
SLIDE 34
AGENTS
SLIDE 35 Features
- Collection of Label objects
- Label is just a string, can be
anything
- Examples: OnExpedition, Female,
Engineer, Disabled, etc.
SLIDE 36 POI spaces
- Collection of Space objects
- Count below minimum is
forbidden
forbidden
- Only agents with labels in
Required collection are accepted
- Agents with labels present on
Prohibited collection are denied
SLIDE 37
We have model. What now? Let’s assign agents to POIs.
SLIDE 38
How to assign agents?
SLIDE 39 Assignment problem
The assignment problem deals with assigning machines to tasks, workers to jobs, soccer players to positions, and so on. The goal is to determine the optimum assignment that, for example, minimizes the total cost or maximizes the team effectiveness.
Reference: http://www.hungarianalgorithm.com
SLIDE 40 Hungarian algorithm
- Solves assignment problem,
- Developed by Harold Kuhn in 1955,
- Based on work of Hungarian mathematicians
Dénes Kőnig and Jenő Egerváry (thus the name Hungarian),
- Fairly easy to understand,
- Our implementation is based on Topcoder
article.
Reference: http://www.convexoptimization.com
SLIDE 41 Assignment problem - example
Reference: http://www.hungarianalgorithm.com
SLIDE 42 Assignment problem - example
Reference: http://www.hungarianalgorithm.com
SLIDE 43
Formulating assignment problem
SLIDE 44
COST FUNCTION? DISTANCE
SLIDE 45
One activity at a time
SLIDE 46
One activity at a time
SLIDE 47
Occupied POIs
SLIDE 48
Rebalancing
SLIDE 49
Invalid assignment POI
SLIDE 50
Minima satisfaction
SLIDE 51
Minima satisfaction algorithm
SLIDE 52
Hungarian algorithm
SLIDE 53
Eliminate POIs with broken minima
SLIDE 54
Sort spaces by saturation level
SLIDE 55
Saturate spaces
SLIDE 56
Results
SLIDE 57 Targeting overview
- Determine a target for each agent
- Centralized process, not an agent decision
- One activity at a time
- All agents at a time
- All POIs at a time
- Rebalancing
- Satisfy POI minima
- Kicking an agent is also targeting
- Agent death is also targeting
SLIDE 58
We have model. We have targeting. Are we good?
SLIDE 59 Let’s see
- People change houses every day
- Families do not stay together
- People change work every day
- Patients who are almost cured get kicked out of medical posts
Why does it happen? Distance is not universal cost descriptor!
SLIDE 60 Target selectors
- Function which matches agents with POIs
- Activity may want to override default target selector
- Target selector should have its own cost function
- Target selector should decide if it wants rebalancing
- Transparent for targeting
SLIDE 61
SLIDE 62 Target selector examples
- NEAREST
- Cost descriptor: distance
- No rebalancing
- Use case: construction
- PERSISTENT ASSIGNMENT
- Cost descriptor: assignment
- No rebalancing
- Use case: work
- MEDICAL TREATMENT
- Cost descriptor: distance, but heal the almost cured in the first place, prefer patients who are
gravely ill
- Rebalancing
- Use case: healing
SLIDE 63 Does it work?
- Mass protests are attended by 3 people
- Convict decides not to show up on his execution
- Idle citizens just „stand” there
- Production output is unpredictable
Living city still miss reliability Smoke and mirrors!
SLIDE 64
IDLE BEHAVIOURS
SLIDE 65
SLIDE 66
DIRECTED SCENES
SLIDE 67
INDEPENDENT ECONOMY
SLIDE 68
INDEPENDENT ECONOMY
SLIDE 69
INDEPENDENT ECONOMY
SLIDE 70
PERFORMANCE
SLIDE 71
Event Driven Behaviour Trees
SLIDE 72
Budgeting and distributed update
SLIDE 73
Parallel targeting
SLIDE 74 Limit number of processed entities
○ Dirty - kicked out of its POI or changed its preferences since last update
- Update only dirty points of interest
○ Dirty - constructed, upgraded, targeted/left by an agent, state changed
- Not possible with rebalancing
SLIDE 75 Lessons learned
From the very beginning of development, we focused too much on the simulation, failing to achieve living city reliability and economy stability. What we really wanted was not simulation, but experience. We wanted the player to believe that what he/she sees is a city populated with people who behave in reliable manner. We also wanted to have stable economy, which is a core system for a city-builder survival game. Doing this by parametrizing simulation is hard. Having said that, we should not have put most of our effort into the simulation. We should have focused more on player perception of the living city.
SLIDE 76
THANK YOU