Suggested AI Crowd Simulation

J Young Kim

New Member
Contributor
Design
Getting started with AI Crowd Simulation for the virtual citizens or NPCs of settlements generated by the DynamicCities module (https://github.com/Terasology/DynamicCities).

AI Crowd Simulation Sources


· Decision Making AI in The Sims© (http://itinerantgames.tumblr.com/)

o Article Summary: The Sims© implements one of the most realistic Non-Real Characters (NPCs) in the gaming industry. The NPCs are realistic mainly due to the high number of needs it requires to “survive” and their ability to decide which action to take in a more or less human-like way. An easy method of doing so is having a method which updates the needs constantly, with a need being incremented differently (i.e. Need for sleep increments more slowly than need for food). This increment should attempt to follow a logical pattern (i.e. need for food should increase exponentially). The decisions are based on what is needed most (i.e. if the need for food is higher than any other need, then NPC eats).

o Terasology Implementation: The NPC can have several needs and have an update function which updates the needs. In the case of a shopkeeper, the shopkeeper can follow a possible layout for behavior:
  • Need: Item
    • Description: The number of merchandise to sell at the shop
    • Action to Address Need: Go into storage and “get” more items
    • Causes for Increase for Need: When the player or NPC buys something from the shopkeeper
  • Need: Hunger
    • Description: The level of hunger which the shopkeeper has
    • Action to Address Need: Eat (Whether it be close the shop and eat at a restaurant or go inside the back of the shop to eat)
    • Causes for Increase for Need: Increases passively, the rate increases if he’s moving around
  • Need: Sleep
    • Description: The level of sleep which the shopkeeper has
    • Action to Address Need: Sleep (close shop and go home or sleep at the shop)
    • Causes for Increase for Need: Increases passively, the rate increases if he’s moving around
  • Need: Social
    • Description: The need for social interactions
    • Action to Address Need: Go around the shop to talk to customers (other NPCs or player)
    • Causes for Increase for Need: Increases passively
  • *If no needs, then stands in front of the shop

· Need Based AI (http://www.zubek.net/robert/publications/Needs-based-AI-draft.pdf )

o Article Summary: Discusses a similar algorithm as The Sims© (see Decision Making AI in The Sims©). This article however further goes into how decisions based on the needs can be made by the NPC. The article describes an “Overall” score can be used. All the needs can be weighted and contribute to the score. The NPC can “think” of all the possible actions that it can do at the moment, and the action which greatly increases in the score would be conducted. The article also states to stay realistic, the actions should not be simple (i.e. eating would require getting food, sitting at table, eating, and putting away empty dishes).

o Terasology Implementation: Using a system of needs for the NPC, the NPC can have a weighted score of its “happiness.” It can generate the list of the actions the NPC can do, and pair each action with the effect it would result in once the action has taken place (i.e. eat steak = +10 and eat eggs = +5). The action which contributes highest to the “happiness” would be executed. If Terasology wanted a more realistic AI, it can add intermediate steps to achieve the effect of the action (i.e. sleeping would first require one to change into their pajamas, go inside the covers, then sleep).

· Crowd Simulation Incorporating Agent Psychological Models, Roles and Communication (http://oai.dtic.mil/oai/oai?erb=getRecord&metadataPrefix=html&identifier=ADA522128)

o Article Summary: The article mainly focuses on the psychological aspect of Artificial Intelligence. It mainly describes two algorithms. The first regards wayfinding, decisions made while traversing through an unknown area. Figure 3 under 3.1.1 High Level: Wayfinding provides an excellent model for such an algorithm. The second regards local motion, the behavioral changes which result from the NPC being placed in a room full of people. This change can be things such as a slower pace of movement, staying in areas where there’s not too many NPCs and players, etc. It’s described in 3.1.2 Local Level: Local Motion.

o Terasology Implementation: A major problem with the Villager NPCs in Minecraft is that they are not too smart: many congest into one house, some get lost in caves, etc. With the inclusion of psychology, the NPCs can be given social personality traits, which can be used for the NPC to exhibit happiness in big crowds, hate towards big crowds, etc. In regards for the NPCs to explore, using the wayfinding algorithm outlined by the article, the NPCs won’t get lost and will be able return safely from their trip. With wayfinding and psychology, the NPCs won’t seem like human-like decision making bots that does actions to satisfy their needs, but rather seem more like a human with an actual personality and preference when out in the “real world.”

Final Words

The research shows that the best method of showing a human-like artificial intelligence is for each NPC to have a needs system which updates constantly. Based on the needs, an algorithm will decide for the NPC an action which will be of best interest for the NPC. With this algorithm of decision making based on needs alone, the NPC will seem too robotic. Thus, the NPC can have a psychology factor, which would react socially when in different areas (areas that have flowers, lots of people, etc.), and a wayfinding algorithm to “explore” outside of its designated area. This would make the NPC more like a human, rather than an android.
 

Cervator

Org Co-Founder & Project Lead
Contributor
Design
Logistics
SpecOps
Nice write-up! I do love the idea of needs and desires being the base of some more advanced AI :)

We've got a few other older AI threads floating around in the forum, like http://forum.terasology.org/threads/three-tier-ai.637 (pretty old at this point)

The Pathfinding module has/had a workboard that was meant to track available tasks for a grouping of creatures. While that was more the Dwarf Fortress style workstation "Player queues up some stuff, creatures find their way to work when they are idle" it might give some ideas for how tasks can be tracked and maintained behind the scenes, or turned into needs and desires as well.

We talked about AI brains at some point too, can't recall if the thread I linked was it.

Our behavior tree setup may also be handy since that could likely sit on top of needs to help a creature guide it down the paths towards fulfilling said needs.
 
Top