sholloway / agents-playground

MIT License
4 stars 0 forks source link

Sim's Town Simulation #26

Open sholloway opened 2 years ago

sholloway commented 2 years ago

Todo

In the GDC talk Emergent Storytelling Techniques in the Sims by Matt Brown the speaker demonstrates a demo that they made of a bunch of green boxes living in homes. Each agent is given a simulated backstory. You can click on an agent and see it's history. For example:

This is the type of thing I'd like to try building.

Thoughts

Goals Learn how to implement AI techniques that deal with autonomous agents. Specifically:

Our Town

The town was founded 100 years ago when a wealthy man built a factory to produce shoes. Over time a small town grew up around the factory. There is now a main street with restaurants and entertainment options. Religious institutions for community and faith. A park for exercise and relaxation. An educational system and justice system.

Town Locations

What can happen in an Agent's life?

An Agent

UI

sholloway commented 2 years ago

Thinking about Systems

Identified Town Systems

Time as a Resource

Example Time Scales Example Real Time (mins) Simulation Time Notes
Minecraft 20 1 day Minecraft is 72x faster than real life. 1440 minutes in a day/20 FPS = 72
Sims 4 24 minutes 1 day Sim Rules Sims uses 1 s = 1 minute 1 Sim Year is only 22 Simulation Days Winter and Spring are 5 sim days each. Summer and Fall are 6 days each. Sims has three speeds: Normal, Fast, Ultra Time is shortened for children and teens. Each has two weeks of simulation time.
RDR2/GTA V 48 1 day
Elden Ring 60 1 day
Fallout 4 72 1 day 1 s in real life is 20 secs in the sim.
sholloway commented 2 years ago

Agent: The Emotional Creature

Emotions begin in the body, influenced by environmental stimuli. The brain responds to low-level perceptions, which translate into persistent characteristics (e.g. fear). These emotions can potentially become visible via behaviors (e.g. crying, laughing, running away).

There is a chain of concepts: Stimuli -> Sensations -> Emotion -> (Moods | Feelings/Beliefs) | Behavior

Stimuli

Stimuli are produced by things in the agent's environment. The things in the town that can stimulate an agent are composed of two categories (locations, other agents).

Location Based Stimuli

Schools: Factory: Churches Dinner Fancy Restaurant Food Truck Coffee Bar Bar Bowling Ally Movie Theater Roller Rink Park Town Square City Hall Grocery/Supply Store Cemetery Homes (houses/apartments) Court Jail Prison

Agent Interactions Stimuli

Sensations

A sensation is an immediate reaction to an agent's current status. Sensations can be caused by stimuli or by cognitive activity (i.e. thinking).

Sensations Table

Emotions

An emotion is a lasting characteristic of an agent's state. Emotions are initiated by sensations. Each primary emotions may have a variable intensity (e.g. fear). The various degrees of a primary emotion are called secondary emotions.

Fear Secondary Emotions Example Fear Amount Secondary Emotion
0.1 Caution
0.2 Caution
0.3 Worry
0.4 Worry
0.5 Anxiety
0.6 Anxiety
0.7 Dread
0.8 Panic
0.9 Horror
0.10 Terror

An agent could have an irrational fear of something (i.e phobia) that invokes a higher fear response than other agents.

Primary emotions may also be defined such that two of them may not be present at the same time. These pairs are called complementary emotions.

Moods

A mood is a complete set of emotions that constitutes someone's mental state at a particular time.

A mood is represented as a set of primary emotions, each with their degree of secondary emotion. The combination of the primary emotions produce complex emotions (e.g. love, optimism, depression)

Feelings

A feeling is a persistent association of an emotion with a class of object (e.g. food, house, institution, location, another agent, a concept). They can be expressed about the past or future. They do not rely on the current agent's state.

Examples: pity, love, hatred, affection Look at this list.

Beliefs

How the agent sees their world. This applies to their own sense of self ( I am a good person), how they see others, their political leanings, and religious practices.

Behaviors

tbd

D & D Character Rules

One thought is to leverage D&D as a template for thinking through generating characters. The D&D rule set is available as a free PDF.

sholloway commented 2 years ago

Procedural Generation

Fixed Truths

Agent Creation and Town Population

Agent Characteristics

Agent History

sholloway commented 2 years ago

General Implementation Thoughts

Simulation Database

For example, in a simulation run a history might be:

Technical Thoughts

Creating the Town Simulation with the Current Framework

Have a master task that only runs that bootstraps the simulation generation. This might look something like the following.

def populate_town(context) -> None:
  simulation = context.scene.simulation
  # Generate the population of agents.
  # Initially create the base characteristics of each agent individually.
  # The parameters should ideally all be in the TOML file.
  general_population = create_agents(
    simulation.total_pop_size, 
    simulation.gender_distribution, 
    simulation.faith_distribution, 
    simulation.political_distribution, 
    simulation.age_range,
    simulation.life_span_range, 
    simulation.attraction_distribution,
    simulation.education_distribution,
    simulation.financial_status_distribution,
    additional personality traits...
  )

  # Who is in relationships (friends, dating, co-habitating, married, divorced). 
  # Matching Challenge
  establish_initial_relationships(general_population) 

  # Assign jobs, academic status, job status.
  assign_initial_roles(general_population) 

  # Based on relationships, financial status, and roles, assign a house to each agent.
  # Packing problem
  assign_housing(general_population)   

Creating the Physical Town

sholloway commented 2 years ago

Streets and Agent Navigation

The various locations are connected via streets/walkways. Agents go from one location to another by traversing the streets. This is done in real-time.

Challenges

Implementation Thoughts

The agent traversal algorithm is going to need to focus on segments. The render is going to care about the streets.

An adjacency list can be used to internally store a bi-directional graph of junctions.

segment_graph: dict[junction, list[junction]

segment_graph[a] = [b]
segment[b] = [a, c, d]

In the TOML file it may be simpler to just define the street network twice. The simplified street network, and the invisible more detailed junction network.

# Streets are long and just define their start and end points since they're all linear.
# They are rendered in the simulation.
[scene.entities]
streets = [
  # The N/S highway that connects all of the E/W streets
  {'interstate': [a, b,...], label='Interstate', start_loc = [14, 22], end_loc = [415, 22]}
  {'main_street': [a, b,...], label='Main Street', start_loc = [14, 22], end_loc = [415, 22]}
]

# A directed graph is used for a navigation mesh.

# Nodes in the navigation graph are called junctions.
# A junction can be associated with a location.
[scene.entities]
junctions = [
  { id = 1, cell=[14, 12], location_id=1, description='The Factory'},
  { id = 2, cell=[10, 12]} 
]

# An adjacency list of junctions. 
segments = {
  1 : [2]
  2: [1]
}

Rendering Streets

Cell based navigation.

One thought is to lay the streets out, and then generate a navigation mesh dynamically based on the intersection of the buildings and streets. The basic idea is that we'd extend the navigation concept from the mazes. So each cell could potential be a room with four walls. The A* algorithm would traverse the network of cells to devise the path an agent takes.

sholloway commented 1 year ago

Agent Utility

I want to leverage utility theory to a degree in the Agent's cognitive model.

Consider prospect theory and loss aversion in this model. Look at the model of prospect theory for an example of how to implement this.