SIMULATING A FREEZING SOCIETY BUILDING THE AI OF FROSTPUNK HELLO - - PowerPoint PPT Presentation

simulating
SMART_READER_LITE
LIVE PREVIEW

SIMULATING A FREEZING SOCIETY BUILDING THE AI OF FROSTPUNK HELLO - - PowerPoint PPT Presentation

SIMULATING A FREEZING SOCIETY BUILDING THE AI OF FROSTPUNK HELLO IM MACIEJ CZERWONKA GAMEPLAY PROGRAMMER | SIMULATION TEAM GAME DEVELOPER FOR 15 YEARS @Calveit WE ARE HIRING FROSTPUNK AI BUILDING BLOCKS PERFORMANCE FROSTPUNK


slide-1
SLIDE 1

SIMULATING

A FREEZING SOCIETY BUILDING THE AI OF FROSTPUNK

slide-2
SLIDE 2

HELLO

I’M MACIEJ CZERWONKA GAMEPLAY PROGRAMMER | SIMULATION TEAM GAME DEVELOPER FOR 15 YEARS @Calveit

slide-3
SLIDE 3

WE ARE HIRING

slide-4
SLIDE 4

FROSTPUNK AI BUILDING BLOCKS PERFORMANCE

slide-5
SLIDE 5

FROSTPUNK

slide-6
SLIDE 6
slide-7
SLIDE 7

SIMULATION

slide-8
SLIDE 8

AI BUILDING BLOCKS

slide-9
SLIDE 9

AGENTS

slide-10
SLIDE 10

Agent

  • Core simulation element
  • Represents a citizen
  • Interacts with environment
slide-11
SLIDE 11

State

  • Agent memory and needs
  • Private set of data
  • Accessable only for decision

tree

slide-12
SLIDE 12

Perception

  • Eyes and ears of the agent
  • Translates environment to

format usable by decision tree

slide-13
SLIDE 13

Decision tree

  • Agent brain
  • Has access to state and

perception

  • Behaviour tree
  • Affects the state
slide-14
SLIDE 14

ACTIVITIES

slide-15
SLIDE 15

Activity

  • Verb of a simulation
  • Not atomic
  • Not an action
slide-16
SLIDE 16

Activity tree

  • Action factory (produce actions

for agents)

  • Behaviour tree
  • Multiple agents allowed
slide-17
SLIDE 17

Target selector

  • Matcher (assigns agents to
  • bjects)
slide-18
SLIDE 18

Priority

  • Number
  • Decides the order
  • Easy to change

! Hard to maintain

slide-19
SLIDE 19

Activity list

  • One dimensional list
  • Decides the order
  • Transparency
  • Visibility
  • Cheap maintenance
slide-20
SLIDE 20

Preferences

  • Set of values
  • Agent decision
  • Fallback activities always in the

collection

slide-21
SLIDE 21

Action

  • Controlling agent
  • Can influence state
  • Can influence visuals
slide-22
SLIDE 22

Plan

  • Collection of actions
  • FIFO
  • Fed by activity tree
  • Consumed by agent when

current action is finished

slide-23
SLIDE 23

POINT OF INTEREST

slide-24
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
SLIDE 25

Activity

  • Activity type available at POI
  • Each POI declares an activity
slide-26
SLIDE 26

Conditions

  • Collection of expressions
  • Evaluates to boolean value,

which decides if active

slide-27
SLIDE 27

Space

  • Range (eg. 1-10)
  • How many agents can perform

activity here

slide-28
SLIDE 28

Target

  • Agent always has a target
  • Binds agent with POI
  • Idle agents have target
  • Dead agents have target
slide-29
SLIDE 29
slide-30
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
SLIDE 31

AGENTS

slide-32
SLIDE 32

AGENTS

slide-33
SLIDE 33

AGENTS

slide-34
SLIDE 34

AGENTS

slide-35
SLIDE 35

Features

  • Collection of Label objects
  • Label is just a string, can be

anything

  • Examples: OnExpedition, Female,

Engineer, Disabled, etc.

slide-36
SLIDE 36

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

slide-37
SLIDE 37

We have model. What now? Let’s assign agents to POIs.

slide-38
SLIDE 38

How to assign agents?

slide-39
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
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
SLIDE 41

Assignment problem - example

Reference: http://www.hungarianalgorithm.com

slide-42
SLIDE 42

Assignment problem - example

Reference: http://www.hungarianalgorithm.com

slide-43
SLIDE 43

Formulating assignment problem

slide-44
SLIDE 44

COST FUNCTION? DISTANCE

slide-45
SLIDE 45

One activity at a time

slide-46
SLIDE 46

One activity at a time

slide-47
SLIDE 47

Occupied POIs

slide-48
SLIDE 48

Rebalancing

slide-49
SLIDE 49

Invalid assignment POI

slide-50
SLIDE 50

Minima satisfaction

slide-51
SLIDE 51

Minima satisfaction algorithm

slide-52
SLIDE 52

Hungarian algorithm

slide-53
SLIDE 53

Eliminate POIs with broken minima

slide-54
SLIDE 54

Sort spaces by saturation level

slide-55
SLIDE 55

Saturate spaces

slide-56
SLIDE 56

Results

slide-57
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
SLIDE 58

We have model. We have targeting. Are we good?

slide-59
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
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 61
slide-62
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
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
SLIDE 64

IDLE BEHAVIOURS

slide-65
SLIDE 65
slide-66
SLIDE 66

DIRECTED SCENES

slide-67
SLIDE 67

INDEPENDENT ECONOMY

slide-68
SLIDE 68

INDEPENDENT ECONOMY

slide-69
SLIDE 69

INDEPENDENT ECONOMY

slide-70
SLIDE 70

PERFORMANCE

slide-71
SLIDE 71

Event Driven Behaviour Trees

slide-72
SLIDE 72

Budgeting and distributed update

slide-73
SLIDE 73

Parallel targeting

slide-74
SLIDE 74

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
slide-75
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
SLIDE 76

THANK YOU