looting

DT: Smarter Hearthlings

Hey everyone, welcome to another Stonehearth Desktop Tuesday! In the month since we last spoke, the team has been super busy, working on a number of projects for Alpha 23 and beyond. This week, I’d like to show off some complex AI changes that Engineer Max spearheaded that should solve some longstanding pain points, help to create a sense of intelligence in our hearthlings, and that also unlock future capabilities for upcoming gameplay designs.

Smarter Hearthlings

For literally years, many of you have pointed out that hearthlings have tiny attention spans and aren’t great at prioritizing complex, context-sensitive actions. For example, though they know to eat when they’re hungry or run away when they’re hurt, sometimes, they used to prioritize having a conversation over hauling, even when the item they’re hauling is the berry bush that will save their own town from starvation, because our system doesn’t have any way of letting them know that this item will indirectly solve their starvation problem and in the final version of A22, we had to special-case this to make sure it didn’t happen. In less dire situations, you often see far-away loot or items go unharvested or unrestocked, because people need to run back home to sleep or eat before they can retrieve those items.

This problem, of hearthling oscillation has been incredibly hard to fix because back in 2013, Engineer Tony designed our AI with the following five principles:

  • AI should be easy to decompose down into small, reusable chunks,
  • AI should be easy to write for people making new actions,
  • Hearthlings shouldn’t start doing things they cannot finish,
  • There should be just one master module that does all the decision-making
  • Hearthlings always do SOMETHING that they know how to do, instead of standing still like automatons. (Ironically it so happens, when the CPU is pegged, being idle is the only thing that will complete in the AI, so that is the animation they play.)

These last two principles, having one decision maker, and always doing the right thing, mean that the logic for deciding things and the logic for reacting to things are always in conflict, leading to situations where reacting detracts from decisions made leading to oscillation and stupid looking behavior, like a hearthling deciding to place a table, and then, five seconds later, reacting to their hunger meter ticking down, and then going instead to find food.

So, if oscillation is the result of the base principles around which the AI is designed, how can we fix it without building an entirely new AI system? Enter Designer Richard, who proposed several new systems to sit on TOP of the AI, including inertia, so things that are started, are likely to be continued, and dynamic priority, so the game can change the importance of a task to a hearthling based on things going on in the world. Engineer Max, with surgical precision, then took our entire AI system apart so that he could fully understand it and put it back together with these new ideas inside. Here are some simple results:

In Alpha 22, crafters who are crafting will drop what they are doing and go to sleep. In Alpha 23, if a crafter is in the middle of crafting, they are more likely to finish their task before going to sleep.

Likewise, if you’ve asked someone to place something or if someone is hauling something, they’re more likely to finish before they hit their hunger threshold and go eat.

I really want to emphasize how incredibly like brain surgery this task was–our AI system is complex, and its modularity distributes actions over lots and lots of files. Actions also have unintended consequences on each other all the time. In the course of this work, Max touched countless files, and worked with QA Analyst Ana to test dozens of edge cases, many of which were culled bug reports that you all put up on discourse, so thank you for that!

The end result, we feel is quite worth it, and we also look forward to how it opens up new tools for our team’s designers. For example, w/ this system, we were able to make a number of optimizations that were impossible before, like specifying that hearthlings should prioritize looting over restocking. In this save, which is an old one from Discourse, the hearthlings would never manage to get around to clearing all this loot. In Alpha 23, over time, you can see that the loot is eventually cleared away.

Hearthlings will also do subtle, smarter things like prioritizing hauling stuff we don’t have–like, if you have a ton of stone but no copper, they’ll prioritize copper over stone. They will also prioritize things your crafters need: so if you’ve queued up a bunch of wooden swords, because the goblins are coming, but you’re out of wood, they’ll automatically prioritize wood over other things. Finally, going forward, we expect these changes to unlock more complex topics, like exploration of greater distances.

And that’s it for this week! We don’t yet have a date for A23, but when this touches down on unstable, we want you to push hard on these systems and maybe even mess in our config files with the default inertia for different tasks etc to see if you can find a way to make hearthlings even smarter and more responsive than they are now.

Other Announcements

Quarterly Europe Stream, featuring Allie and Chris, happens at 8:30am PST on Wednesday, 11/8. Bring all your art and building questions!

You can also find Linda’s very first solo stream on Thursday, 6:00pm PST. Ask her about crafting and the new appeal system, which is our focus for Alpha 23, or about her recent forays into long term multiplayer security/reliability infrastructure.