The Sims is a digital dollhouse,  filled with little computer people. And it's your job to keep  them alive, keep them happy, and keep their house furnished  with ever more expensive trinkets. But micromanaging the needs and desires of  an entire family can get pretty tedious. So the developers at Maxis soon realised that they'd need to give these guys  a certain amount of autonomy. Free will. The power to think for themselves, if  the player stops giving direct commands. Which is actually... a pretty complicated task! These characters  need to read as believable humans. And they need to be able to adapt to any  possible house you build around them, or any social situation they find themselves in. And - crucially - they can't be so smart that  the player can just sit back and do nothing. So how do you make a video game  AI that can do all of that? Well, that's what I want to explore in this video. I'm going to break down the clever ways that Maxis  designed autonomy in this four-game franchise - though with a focus on the original game, and - let's be honest - the  best one, which is The Sims 3. It's not going to get too technical, but there is a metric buttload of resources  in the description if you want to dive deeper. With that out of the way, I'm Mark Brown, this is Game Maker's Toolkit,  and here's how The Sims... think. Okay - decision making in The Sims  is all driven by a set of mental and physical needs - dubbed "motives", by Maxis. In The Sims 1 that's hunger,  hygiene, fun, energy, bladder, social, comfort, and room, or tidiness. They all go from negative 100 to positive 100, and if you combine them all, you get  the Sim's overall level of happiness. These meters are constantly ticking down -  each decaying at slightly different rates, and faster if the Sim is  performing a related action. The bladder meter drops more quickly  when the Sim is eating, for instance. Maxis carefully tuned all of these  rates to hopefully match a normal human schedule - like needing eight  hours of sleep, and three meals a day. So. If the player doesn't give the Sim  a command, it will decide what to do by itself - and that decision is driven  by a desire to fulfil these motives. Now you might assume that a Sim  knows how to meet its own needs: that a toilet will solve bladder,  that fridges and stoves solve hunger, and books, TVs, and pinball tables solve fun. But it doesn't work like that -  it's actually, the other way around. Instead, all of the objects in  the Sim's house contain this data, and will broadcast what they can offer. A bed will say "sleep on me to get 10 energy", a toilet offers plus 20 to bladder if you  use it, or plus 5 to room if you clean it. And other Sims will offer themselves  as a way to top up social points. Maxis calls these "advertisements". So. Whenever the Sim decides what to do, it quickly makes a list of every object  in the house - and what they can offer. The Sim can then take that advertised number  and weigh it based on its current needs. It does this by applying a  multiplier to the promised score, based on the Sim's current motive levels. For example, if the Sim is well-rested,  the bed's energy-boosting score is damped down - but if the Sim is knackered, then  that same score is boosted dramatically. Now, the Sim can take the list of interactions,  and their weighted scores, and rank them. At the top of the list is the interaction that  will give the most benefit to the Sim right now... and so the digital dude should do just that. This clever system was actually inspired by one  of designer Will Wright's previous games: SimAnt - a virtual ant colony where the critters would  be tempted to move by attractive pheromones. It's basically the same idea  - but instead of pheromones, its TVs, fridges, pinball machines, and bath tubs. However - people aren't ants. And so if this was implemented  exactly as I just described, it would lead to weird behaviours that make  Sims seem either robotic or irrational. So, many careful tweaks are  needed to make it work properly. For instance, not all needs are equal. If a Sim is both starving  to death and utterly bored, they should probably eat a  sandwich rather than binge Netflix. But if the fridge and TV are  both offering the same reward... which should The Sim pick? Well, more rational behaviour can be achieved  by defining unique curves for each motive. For hunger, we want a curve like this:  now, the fridge's score will be reduced to almost zero when the Sim is full, but will  be extremely high when the Sim is starving - making that more important than any other motive. Similar, smaller curves are used for the  other physiological needs like bladder, hygiene, and energy. However, less important needs like fun, social, and comfort actually increase  as the Sim becomes more happy. This was inspired by Maslow's hierarchy  of needs, which says humans will focus on cognitive and social tasks only when their  more basic lizard-brain needs are met. Plus - while peeing will satiate your  bladder, you can never have too much fun. We can also weigh the scores  based on other factors, too. For instance, each Sim has its own  personality - based on their score in areas like niceness, neatness, and playfulness. So while a pinball machine and a bookcase  might advertise the same boost to fun, a Sim will weigh this based  on their level of playfulness. Therefore, a more serious Sim  will choose to pick up a book. Plus, we can weigh the interaction based on its distance from the Sim - which will  make nearby objects more tempting. Finally, some interactions can override everything  - like a telephone call or a school bus. And other interactions can  be locked entirely - so, certain objects won't advertise themselves  to kids, or adults, or a visiting guest. All of these factors combined  give us a much more useful score, which has been adjusted to the different  needs, personality, and proximity of the Sim. And it's from these scores that  the Sim's next move is picked. But - perhaps most importantly of all - the Sim doesn't actually choose  the best option every time. Instead - the Sim picks one of the  top scoring interactions... at random. This stops the Sims from feeling  robotic and overly predictable, and it also means they're not able  to fulfil all their needs perfectly. Which, you know, actually gives  the player something to do. What I've just described is a special type  of AI called utility AI, or needs-based AI. This is a system where a character  has a predefined set of needs, then looks around at its current options, and  picks the one that will fulfil its needs best - the one with the most utility. And in The Sims, it means a little person can be dropped into any house and will  then act in a lifelike manner: carefully attending to its  hunger and energy when necessary, but socialising and having fun when not. Plus, by putting the information  on the objects, instead of the Sim, it's really easy for Maxis to add  hundreds of objects to the game - or make endless expansion packs -  without touching the rest of the code. And so for these reasons, this basic system has  been used in all four games in the franchise. But, Maxis wanted to take things even further when  making the ambitious third game in the series. Okay, so, in The Sims 1, we saw how  each Sim's personality - like their neatness and playfulness - would  impact their decision making. This would make each Sim feel somewhat distinct. But for The Sims 3 this idea  was expanded dramatically by swapping the personality meters with traits. Things like neat, neurotic, heavy  sleeper, and commitment issues. With five trait slots, and 60-odd  traits in the base game alone, that's about 5 million possible Sims -  effectively making every character unique. Now these traits have many impacts on  the Sim - like, how a clumsy Sim will trip themselves up while walking, and  a slob will fart and burp while idle. Sims also get bonus moodlets  for acting to their traits - and there are certain interactions that are  exclusive to Sims with certain traits: like how a computer whizz can  make cash through hacking. But these traits also impact  on the Sim's decision making. This time, however, instead of weighing  the scores against the Sim's personality, the Sims 3 actually just adds  more motives to the pile. So, in the code, every Sim has their  usual basic needs, like hunger, energy, and bladder - but also five more  motives related to their traits. Therefore a couch potato needs  to sit on the sofa and watch TV, just like how they need to pee, eat, and sleep. And then, in the same way that a fridge  advertises itself as a fix for hunger, objects can advertise themselves as a  fix for the Sim's trait-related motives. For instance, interactions like scare a Sim,  steal candy from a child, smash a dollhouse, and write a trolling comment on the computer  are all advertised to Sims with the evil trait. This means that Sims are encouraged  to enact their unique personalities autonomously - while also juggling  their standard, everyday needs. Now this idea - of adding additional motives to a Sim - can also be used to  simulate social situations. For instance, if a Sim enters a gym they  will temporarily be given the additional motive "be in gym" - which is satisfied by  objects like a workout bench or treadmill. When they leave, the motive is removed. Back at home, a Sim will be motivated to act as a hospitable host for as long  as they have guests around - meanwhile, the guests will be motivated to  act in an way that's socially acceptable. And in The Sims Medieval, a Sim  is given work-related motives while they're on the clock, and  then loses them during breaks. However: these motives can  also be affected by traits. For example, if a Sim sits down to have a picnic, then the Sim's friends and family are motivated  to join them - while strangers are discouraged. But a Sim with the "inappropriate"  trait will override this - and they will in fact be motivated to  sit with people they don't know. Just to make them feel uncomfortable. All of this means that Sims will act naturally and  believably in whatever location they end up in - but with a few Sims standing out as acting  unusually, because of their unique personality. And this is all done by simply tweaking the Sim's motivations - rather than hand-scripting a  bunch of specific rules and interactions. Though, that being said, sometimes  you do need more hard-coded rules. Take that house visit I mentioned. A visiting sim is indeed motivated  to act in an appropriate way. But what happens if they stay for too long? Or if the player steps in and makes  the Sim act inappropriately? Well, to make this work, the house visit is overseen by a set  of rules that dictate social norms. So if a Sim sleeps in the host's  bed or uses their computer, the ruleset will instruct the host to warn the Sim, and  then kick them out if they go even further. Likewise, conversations need  more hands-on authoring to reflect extremely specific pair-ups of  people, or super distinct social cues. For example, how should a Sim respond to  a joke if they are steaming mad at the joke teller? Or if the other Sim has  said the same joke 5 times in a row? This is done through a series of rules - with  an input, a set of conditions, and the output. So for that joke I just mentioned... if the listener has the 'good sense  of humour' trait, they'll laugh. If their long-term relationship  is sour, they'll be insulted. And if the Sim repeatedly tells  jokes, the listener will be bored. These so-called "production rules" are ranked in  order of specificity, as defined by the designer, and the top-scoring outcome  is used to pick the response. Maxis ended up writing 1000s of hand-crafted rules to determine the outcome of 100s  of possible conversation topics. But, because the rules just go in a big  stack and the most specific one is picked, they can't clash, break the game, cause an  infinite loop, or lead to any other issue. Just like with the objects, designers can  simply keep adding more and more to the pile. So far, I've been talking about individual Sims, or small social situations  like a conversation or a party. But what about simulating an entire  town's worth of little people? You see, in The Sims 3, your house  exists in an open world neighbourhood with dozens of other Sims, and features  homes, restaurants, a park, and so on. Maxis needed to invent new tools to  make all of this work - but, in truth, the neighbourhood actually operates in  a similar way to the Sims themselves. That's because the town  also has a bunch of motives, and will make choices that  will help it fulfil its needs. For instance - it ideally wants to  maintain a 50/50 gender balance. So when a new Sim is added to the neighbourhood, the probability of it being male or female  is weighted by the current needs of the city. It also has a desired employment  rate of about 80% - so it can force background Sims to get hired or fired as seen fit. Basically - once a day, at midnight, the  town will check its own happiness level, and take a few actions in  order to satisfy its needs. The individual lots have  motives too - for instance, the restaurant may wish to have roughly 8 people  eating outside, during lunch and dinner hours. To achieve this, the lot will temporarily give the "eat outside" motive to a bunch of  Sims to tempt them to the restaurant. It can even narrow the focus to  Sims with certain traits - like culinary - and discourage those  with other traits - like frugal. Now, these Sims that appear at the restaurant  seem like fully autonomous characters. They have needs, they have families, they may even have had a baby and  changed job since you last saw them. So are they are actually living out their  own little simulated lives, just off camera? Well, not quite. The background Sims are actually  simulated at a very low level of detail. Each day, the system looks at each Sim, and scores possible big life  changes that could happen to them - like getting a job, falling in love  with someone, or getting married. These are, of course, weighted using things like  traits, existing relationships, and career paths. Also, the designers created  charts for what a Sim's needs will likely look like throughout the day. If it's just after lunch, for instance,  they're probably not going to be very hungry. And so when a background Sim is  promoted into being a foreground Sim, because they're in proximity to the player, the system checks the time of day and  snaps all their motives to the chart. Clever stuff. So we've got tools to simulate characters, conversations, house visits,  restaurants and entire towns. And when you have such clever tech, it's  tempting to simulate, well, everything. Take, for instance, the urinal rule. If you pee while standing up, you know the  deal: when picking a place to take a leak, you should always try to maintain a  one urinal buffer from other people. It's like an unwritten social rule. So Maxis added this rule to the game, as well... but, before the game launched, they took it out. That's because when the Sim followed that  rule it was just kind of predictable and dull. But if Sims picked toilets at random, it would often lead to funny and memorable  moments of Sims acting awkwardly. You see, while The Sims might  have started life as a rather nerdy simulation game - essentially  SimCity, but at a much smaller scale - it quickly grew into something very different. In playtests for the original  game, Will Wright was surprised that players would tell elaborate  stories about their Sim families - embellishing details, reading into their  decisions, and playing up random moments. "It was fascinating to me how readily people  would build a story around this," Wright says. To support this, Maxis added a  last-minute feature to the game: the ability to take a screenshot, write a caption, and create a simple comic book which could  be uploaded to EA's website with a click. The feature was extremely popular,  proving that for many people... The Sims was an avenue for storytelling. And that's still true today - just search  YouTube for The Sims to see what I mean. But supporting storytelling is a delicate  balance: the game needs to be specific enough to create stories, but not so specific that  there's no room for the player's imagination. So the final piece of this AI puzzle... is knowing when to hold back. Knowing what NOT to simulate. Knowing when to make urinal choice  random, rather than scripted. One way to do this is to  carefully employ ambiguity. Basically, to leave some things unsaid, so players can make assumptions, and project  their own head-canon on the events on screen. A good example of this is the Sim's  iconic babbling dialect, known as Simlish. In early design documents we can see  that Maxis experimented with having the Sims speak real world languages like  English, Navajo, Estonian, and Ukranian - but due to technical and logistical reasons, they ended up hiring two improv comics  to just make up absolute nonsense. Sim: Droba droba droba. Seeka neeba huh. But this actually works wonders - when the  Sims babble gobbledygook at each other, the player can assume, fill in gaps, project their own imagination on the  Sims, and make the game their own. "If we used actual language, the game  would flatten and shrink, and everyone would be having the same experience",  says EA's Matt Brown - no relation. Ambiguity can also make Sims feels smarter than they actually are, and hide cases where  the simulation is doing something wrong. Another avenue is to always follow  the player's lead - and never use autonomy to go against the story  the player is trying to tell. That's why Sims will use free will to  relieve their bladder and fill their stomach, but won't autonomously quit their  job or try romancing a random Sim. Just like with the Nemesis  System in Shadow of War, Maxis took inspiration from the concept  "yes, and", from improvisational comedy - so the Sims try to build on the player's  actions, and try not to negate them. For instance, if a player makes two  Sims fall in love - the autonomous system shouldn't make them break up again. Likewise, user-created Sims enter  the world with no sexual preference. But if you instruct a male Sim  to, say, flirt with other dudes, you're suggesting that he should be bi  or gay and the game will run with that. The game should always try to maintain  the consistency of the player's story. So, The Sims has a fascinating AI system -  which allows for realistic human simulations, and creative player-led storytelling. And most of it is driven by a very simple concept. Characters, locations, and entire  neighbourhoods are given a bunch of needs - and then try to make choices  that will best fulfil those needs. With a little clever tuning, this leads to  characters who feel believable, social situations where Sims act appropriately, and entire  neighbourhoods that stay consistent and balanced. But this is not just useful for  running quirky goal-free life simulations - and we can see utility AI  being used in other types of games, too. For instance, in XCOM, an enemy unit will consider  every tile it can move to and score them based on factors like distance, flanking opportunities,  angle, cover bonus, visibility, and proximity - before moving to the tile with the best score. It can also be used in procedural generation, to  build worlds that fit predetermined requirements. Utility AI is a fantastic addition  to a game maker's toolkit, and its implementation in The Sims should serve as  wonderful inspiration to game designers. And now, just to melt your brain,  here's Katy Perry singing in Simlish. Katy Perry: [Absolute nonsense] Katy Perry: [Just complete gobbledegook] Katy Perry: [I think I'm having a stroke]