How to use game world clock, calendar and random offsets in Utility AI?

Started by
3 comments, last by IADaveMark 5 years, 9 months ago

Let's say I have a bunch of NPCs that need to go to work every weekday. There will be additional considerations for cases when they would choose to stay home (low health etc.).

So, the basic logic is as follows:

Behavior "GoToWork", should be considered only if it's Monday to Friday AND only if clock time is after 6:00 AM, applying random shift of up to 3 hours to prevent all NPCs rushing out at the same time.

The world clock and calendar is knowledge base and I can map clock (minutes) to input range. But days and random shifting are not that straight forward. I could map minutes for entire week as a single input and build a custom piecewise curve with sharp transitions (because it's essentially yes/no decision - I don't want to consider it at night or on Sundays at all) and use that as the second consideration for GoToWork. 

But still I'm not sure how it is supposed to be implemented "the right way" with utility AI. Which condition checks belong where and how to add that random offset for each NPC separately?

Advertisement

This has very little to do with utility AI... of any AI for that matter... and more about knowledge representation. For the most part, it can be solved by Programming 101 sorts of answers.

  • Create a representation of what a day is.
  • Create a function for determining that.
  • Create another boolean function for "is it a weekday" that checks to see if the day returns M-F. 
  • Create a representation for what time of day it is.
  • Create a boolean function for whether or not it is a work hour or not.

if (IsItWeekday && IsItWorkHours) { GoToWork(); )

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

Oh, I see, yes, I can fall back to boolean inputs for considerations for cases when I clearly need opt-in / opt-out.

I guess, my brain switched into curves mode and failed to think in simple booleans; or maybe I felt that boolean considerations are evil in utility AI because of being too strict and breaking the "fuzzy logic" feeling of it :D

I use them all the time and encourage them. There are some things that simply make sense that way. For example, if you have a stealthy action that you only want to do when you are invisible, you can do a boolean check to see if you have the "invisible" tag. If you don't, the behavior is automatically 0 (since the consideration is 0) and you move on.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

This topic is closed to new replies.

Advertisement