SIMULATING A FREEZING SOCIETY BUILDING THE AI OF FROSTPUNK
HELLO I’M MACIEJ CZERWONKA GAMEPLAY PROGRAMMER | SIMULATION TEAM GAME DEVELOPER FOR 15 YEARS @Calveit
WE ARE HIRING
FROSTPUNK AI BUILDING BLOCKS PERFORMANCE
FROSTPUNK
SIMULATION
AI BUILDING BLOCKS
AGENTS
Agent Core simulation element ● Represents a citizen ● Interacts with environment ●
State Agent memory and needs ● Private set of data ● Accessable only for decision ● tree
Perception Eyes and ears of the agent ● Translates environment to ● format usable by decision tree
Decision tree Agent brain ● Has access to state and ● perception Behaviour tree ● Affects the state ●
ACTIVITIES
Activity Verb of a simulation ● Not atomic ● Not an action ●
Activity tree Action factory (produce actions ● for agents) Behaviour tree ● Multiple agents allowed ●
Target selector Matcher (assigns agents to ● objects)
Priority Number ● Decides the order ● Easy to change ● ! Hard to maintain
Activity list One dimensional list ● Decides the order ● Transparency ● Visibility ● ● Cheap maintenance
Preferences Set of values ● Agent decision ● Fallback activities always in the ● collection
Action Controlling agent ● Can influence state ● Can influence visuals ●
Plan Collection of actions ● FIFO ● Fed by activity tree ● Consumed by agent when ● current action is finished
POINT OF INTEREST
Point of interest POI ● Agents perform activities here ● Attached to building or other ● place in the game ● Place can have more than 1 POI
Activity Activity type available at POI ● Each POI declares an activity ●
Conditions Collection of expressions ● Evaluates to boolean value, ● which decides if active
Space Range (eg. 1-10) ● How many agents can perform ● activity here
Target Agent always has a target ● Binds agent with POI ● Idle agents have target ● Dead agents have target ●
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!
AGENTS
AGENTS
AGENTS
AGENTS
Features Collection of Label objects ● Label is just a string, can be ● anything Examples: OnExpedition, Female, ● Engineer, Disabled, etc.
POI spaces Collection of Space objects ● Count below minimum is ● forbidden Count over maximum is ● forbidden Only agents with labels in ● Required collection are accepted Agents with labels present on ● Prohibited collection are denied
We have model. What now? Let’s assign agents to POIs.
How to assign agents?
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
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
Assignment problem - example Reference: http://www.hungarianalgorithm.com
Assignment problem - example Reference: http://www.hungarianalgorithm.com
Formulating assignment problem
COST FUNCTION? DISTANCE
One activity at a time
One activity at a time
Occupied POIs
Rebalancing
Invalid assignment POI
Minima satisfaction
Minima satisfaction algorithm
Hungarian algorithm
Eliminate POIs with broken minima
Sort spaces by saturation level
Saturate spaces
Results
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 ●
We have model. We have targeting. Are we good?
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!
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 ●
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
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!
IDLE BEHAVIOURS
DIRECTED SCENES
INDEPENDENT ECONOMY
INDEPENDENT ECONOMY
INDEPENDENT ECONOMY
PERFORMANCE
Event Driven Behaviour Trees
Budgeting and distributed update
Parallel targeting
Limit number of processed entities Update only dirty agents ● 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 ●
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.
THANK YOU
Recommend
More recommend