White Shining Rock Logo
White Shining Rock Logo

Designing the AI

February 16, 2021 | Dukus | 40 Comments

I like designing new code. Especially when I'm starting with a blank slate. I've got the initial framework for AI built now and am slowly testing ideas and fleshing it out. I went through several iterations of design, and I've ended up with something I think will work, and that can grow as the game does.

(The bad thing about new code is it generally doesn't come with screenshots or videos of cool things right away...)

Before designing anything, or writing any code, I went through a bit of time just writing down what I'd like the AI to do in the game. I'm going to list some of it here, plus some of my vision for what the game will be, but remember, game design is fluid and not all my ideas will necessarily end up in what I finish.

What I'm trying to explore this time is a colony simulation that is higher in detail than Banished, with a smaller set of villagers. This includes things like beds to sleep in, each villager owning equipment that's stored somewhere, and having skills unique to each citizen that are needed to make the village work. I'd like to slow down the simulation to days, including time to sleep, rest, work, and join in town festivities, like weddings or annual celebrations.

So here are some things I'd like to see.

Let's say a villager wants to paint her stone house white. But she doesn't have a painting skill. So she'll let the village know what she wants. If there's a painter in the village, he'll do the job, but there might not be paint. So he'll let the village know there's a need for paint. The worker that makes paint gets to work gathering limestone, or white clay, or white flowers, or whatever it ends up being ingredients. He'll make the paint. The painter will later grab it, and paint the house. And if I want the complication, a tool maker needs to make a paint brush first using animal hair and wood. And the animal hair comes from... etc, etc. And then the first villager gets what she wants.

The main idea there is that if you've got the production line and workers setup, the player won't have to manage turning things on and off, or setting limits. The village will just do it as needed. But the player will have the option of specifying that they want to drive production of a certain resource on purpose.

I'd also like to see group activities. There might be large bison-like animals that take more than one hunter take down. So the villagers need to get organized somehow, and then all follow the same plan to get close to one and attack at the same time.

Lastly I want smarter villagers. If you've directed villagers to build a building and you need a log to complete it, it's probably more efficient to cut down the tree that's nearby rather than walk all the way across the village and back to get one. Similarly, if a wood splitter has a store of logs nearby but isn't working to cut firewood, it's okay to grab the log from that location rather than a far away generic storage yard.

My final goal is that all this needs to be data driven and extensible without the need for a full scripting language. After working with it for a few months, I should be able to add new things villagers do and locations they use without modifying any game code. There are certainly a lot of similarities to what Banished had, but that code is too rigid, messy, and not configurable. It's nice to start again knowing what sort of issues to deal with.

So how am I going to accomplish all this? We'll first I need to start with the smallest case and grow. But also keep in mind my future needs. I've also been doing some research to see what others are doing. Over the last year or so, I've read a lot of game postmortems and AI papers on getting AI characters to do things like I describe. There's a few algorithms that stand out. Namely Utility AI, Behavior Trees, and Goal Oriented Action Planning.

None of them are perfect for what I want, but they all have good ideas. So I'm blending and modifying, to get what I want.

The basics of my idea is to have each villager have goals they want, and keep track of how strongly or weakly they want to do them. As the player places buildings and objects, those objects will be able to fill those needs. Each object gives a score to the villager as to how useful it is to perform it's actions, which will be combined with the desires of the villager. Considering all the possible actions available to them, the villager will pick one of the top ones. Objects can also have their own desires. For example, if a location turns reeds into baskets, the location will desire the source materials if the number of stored materials is low. This in turn will cause villagers to consider collecting reeds when needed.

Objects and locations will also be compartmentalized. A boat building area will handle telling villagers how to use it, rather than the villager handling each and every object it can interact with. The object would hold the animations, particle systems, audio, and other resources needed for use, the actions it can give out to villagers, and the desires that it can satisfy. This way, as the game grows, I (hopefully) don't have to modify existing resources to add a new object.

But where to start!? Designing and writing a giant system with a zillion requirements is hard. Without being able to test its parts as you work is very difficult and usually doesn't work. If you try this, as the code expands it shows you where your design falls flat and needs fixing. It's hard to debug, and it's time consuming to change things when you hit the walls of your design. There are too many unknowable design issues to be able to decide on them up front and roll with it. So I like to start small and simple then grow.

I decided to find the simplest thing the villagers will actually do that makes simple cases for everything I want to be able to handle. This took me a while to come up with, because it's not really a focus in the game, but it's still in there. Of course once I thought of it, it was obvious.

I originally thought I'd implement a campfire to satisfy the desire of villagers to be warm. Seems simple, and is a scenario that will play out in many similar ways throughout the game. But it requires a lot of structure all at once and doesn't quite cover the wide berth of ai systems that I want. When the villager is cold, it desires warming up. The campfire can handle that, but it needs to be burning fuel of some sort for that. I could fake that with the campfire turning on and off automatically for testing. But I feel like to continue down that path, fuel needs to be harvested and/or stored and brought to the fire, which requires inventory, and more locations and actions, cutting trees, splitting firewood, or collecting something else that can burn. That's all too complex, and doesn't have an obvious outlet for group actions.

Trying smaller actions villagers will be able to perform was a non-starter as well. Just collecting rocks and putting them somewhere else seemed a bit to big for a start, as it still requires other systems like inventory, carrying things, and an object that can store things. I wanted to be up a running with the ai without writing other systems at the same time.

So what did I come up with? It's idling. That's right, doing sort of nothing. Find places to hang out, pick one based on distance criteria, walk around. Talking to each other, or have a party. I can get things up and running without harvesting resources, needing storage and inventory, or production chains. There's no game there, but it meets the needs of most of what I want to do. And all I had to write is the core AI systems to make it work. Extending it with more things that objects in the word can do should then be easy(ish).

So that's where I am. After my paper design phase and coming up with a plan, I've implemented the basic structure of villagers with desires, objects that can satisfy those desires, and being able to pick the best action from it's weights. It's all data driven. Each object has animations it can hand out to villagers to make interacting with it look unique and correct. Villagers look at what they can idle near, weight it based on distance and pick from the top choices. They can satisfy their own need to idle and wander randomly as another possible action. Currently it seems to be in a flexible space where it will be easy to extend and add features.

Coming up I'll be working on group idling - getting two or more villagers to decide to stand close to each other and play synced animations as if they are having a conversation. (I hope in the future this sort of thing will build friendships and relationships, but that's really getting ahead of myself...) I also want to setup up triggers for group events, where villagers immediate desire becomes attending that event over anything else. I'll probably also add some rudimentary time of day schedule which changes what sort of idling occurs at different times.

That should set me up with a fairly solid foundation for the more complex systems that will be built on top of the desire/satisfaction system. Then it will make more sense to get into the fun game parts where resources are harvested, production lines are setup, and players try to balance everything so that everyone survives.

Leave a Reply

Your email address will not be published.

40 comments on “Designing the AI”

  1. This is an amazing idea you are working on. I can not wait to hear more and play it when it is ready.

    Thank you for the update!

  2. This is really exciting, I one day want to make a similar world. It must be the greatest thing to see a world function 'by itself' after you've made all these systems.

    What scripting language will you be using, or will it be your own custom thing?

    And can you elaborate a bit on what 'data driven' means in this context?

    Thanks for sharing!

  3. I look forward to your developer blogs. I followed them during the Banished days and still play Banished, great game! I like the idea outlined here, it seems like it should give villagers more "personality" that isn't locked in. Keep up the great work.

  4. I think that starting with idling is absolutely brilliant. In a sense you can build the behaviour of the villagers before they are forced to work or perform needed actions. Even in Banished I was always interested in where villagers were going and when they decided to go home or eat. It's nice to see how villagers come across to they players at rest? I think that this is where the immersive experience and storytelling that builds up in a players head starts building and gets time to develop.

    Have you thought about adding variance to how quickly villagers respond to desires and how often they switch focus on tasks? It would be cool to have some villagers inherent personalities represented through their gameplay- like having an adhd type villager rapidly switch tasks while having another type of villager remained focused on a task and be a bit more resilient to switching to a second task before finishing or completing a cycle of the first one. This might be a way to keep things a bit unpredictable without having to code in a separate personality system, for instance.

  5. Loved and still loving Banished! Canโ€™t wait to play another game from you with the in depth control of my people and they surroundings. Thank you and keep up the great work!

  6. Wow, can't wait. Just to stress I love Banished, making use of every possible MOD to build amazing and functional economies and cities.
    I can already see that our MODers are going to have a field day with the new game, and that makes it all the more exciting for me.
    LOL I play and lose myself Banished almost on a daily basis hehehehehehe Love it.

  7. The first thing I thought after reading this is that if it was made modular enough I don't see why this couldn't replace or enhance banished's own AI or or any other macro level colony sim with micro level AI.

  8. I'm wondering if you can have 'scheduled idling' like someone has planned a party for some reason? ( maybe it's someone's birthday, but that seems like it's more of a specific case. ) people invited would look forward to it, or not. or decide to go, or not ? oh man. I'm thinking too much about this. the guy who doesn't have any friends has a birthday and no one comes ๐Ÿ™

  9. After reading this the first thing I am thinking about is whether or not you're planning to allow for weights to be calculated based on an action satisfying multiple needs. For example, a party might satisfy a need to idle, be social, and eat, whereas a park might satisfy the need to idle only. If the character has a high need to idle but some need for food, might the AI weight the party higher simply because it can satisfy more needs? This also seems like it will be really flexible for mods, since any mod would only need to specify what needs it has and/or satisfies. Really great ideas, so glad you're posting these logs!

  10. This sounds really fun and interesting. I love reading your updates, and I'll be buying this game as soon as it's available.

  11. "Idling" by Banished people was annoying, it meant non-productivity. It was necessary for them to interact though, and kept them 'happy'. So this is taking that a few steps further, interesting. It's all interesting. Thank you for keeping us up to date.
    Looking forward to the Beta edition...
    All the best to everyone.

  12. Amazing blog entry can't wait to play the game. Happy to be part of the test team. Let me know when we can start to contribute or preorder

  13. I would love a game like that where I can focus on bigger picture and the AI will do all the micromanagement and I could watch it do that. Distant Worlds game was something like that.

  14. Idling is such an appropriate first start. It's the foundation of us humans after all. Until a need or a desire becomes so strong that action is required, I'll choose idling over everything. Awesome!
    Are there introverted and extraverted characters? Characters who are more or less fond of interaction?

  15. As someone who would like to become a game developer one day I would love to hear more on how you intend to be keeping track of all these wishes and orders.
    Keeping these orders in some list that you iterate periodically in order to determine if an existing order can be completed by a game character can become quite lengthy if there are lots of unfinished orders. Especially if at the same time you also have bunch of idle characters that can't fulfill such order because they lack necessary skill.
    On the other hand searching for available orders from idle characters could also lead to slowdowns if there are lots of idle characters.
    These are most common reasons for slowdowns in similar games.

  16. As a workaround for possible problems in my previous post I was thinking of perhaps having two lists. One for storing pending work orders and another for storing idle units or their available talents.
    Then upon creating a new work order I would go and first check to see if there is an idle unit available that could finish that work order. If it is I would assign order to that unit. If not I would add that work order to pending work list.
    Similarly when a unit finishes some work order and becomes idle I would first check to see if there is any pending work order to assign to this unit. If it is I would assign the order to it. If not I would add this unit to idle units list.
    This way I believe it would be possible to avoid the need to loop either though pending work order list or idle list at fixed intervals. So if any of those lists would have high number of entries the general performance impact would be much lower.

  17. Really excited to play with it :).

    Please, during development don't forget about Linux users (or portability in general). That'd be fantastic if it were released to Linux on the launch day.

  18. Hello! Big fan of your work for so many years.
    Still a bit confused if all those devlogs, especially with the AI are for Banished or a future game of yours?
    Keep up the good work!

  19. Hello ! This is a very good new to see "february 2021" !!
    Count on me to get the game in Early Access. I hope we can consider it as "Banished 2". This is my favorite city builder !

  20. Thanks for sharing your development itinerary. I'm working on a similar goal, although not for gaming but for self-deploying, individuals-based simulations of macroeconomy. In addition to the "game postmortems and AI papers on getting AI characters to do things like I describe" and would like to suggest you to have a look to this recent article: https://arxiv.org/ftp/arxiv/papers/2009/2009.10823.pdf

  21. I cant wait to see what else you are coming up with..

    Banished and Factorio is probably the most fun games i have played in the last 20 years..

    But i keep coming back to Banished..

  22. This reminds me of two of my favorite games, Stonehearth and Founders' Fortune. Consider me in line for this one as well!

  23. So exciting to see the progress, I check the site out every few months to see your progress. I has been an exciting surprise to see three new posts. Keep it up you have a sale in the future with me.

  24. Can't wait to give you money for another game you'll never finish, keep up the great work!

  25. Thanks for your last input and always hf on your development road! Do not forget to take some breaks. ๐Ÿ˜‰

    Your ai aiming reminds a bit on the classic: Children of the Nile.

  26. Luke, we messaged back and forth a long time ago in the pre Banish days. Nothing has changed in several years. Your ability to put your thoughts and ideas to paper and share your passion with others is just as refreshing today as then. I appreciate the updates and the work you do. Remember, caffeine good when coding, alcohol bad... ~Todd

  27. I think that you are overthinking it. I've enjoyed the simplicity of Banished for quite a long time, and there is value to simplicity. What Banished lacks for extended gameplay is CURRENCY EXCHANGE. Even simple societies understand trading with currency rather that the bartering system. How about add gold and silver to trade with for Pete sake!

  28. Thats something similar to my idea of a game id love to play. The difference is its more merecenary oriented with fighting similar to Kenshi, and character traits like in Crusader Kings. playing your village builder would definitely "scratch my itch" but please make it gridless to allow amazing designs!

More Posts

Code Rot

April 17, 2022
1 2 3 47
Back to devlog
Back to devlog
ยฉ Copyright 2021 Shining Rock Software
Website Design & Branding by Carrboro Creative
menu-circlecross-circle linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram