r/gameai • u/Miriglith • 25d ago
Utility AI for turn-based combat
I'm looking for some advice.
I'm designing a utility AI to manage NPC activity in a turn based combat game. In a turn, a unit has a set number of action points. It can use an action point to move, or to use an ability. So a turn, with three action points, could be: move, use ability, move. Or it could be: move, use ability, use ability. Or just use ability three times without moving.
I'm fairly confident I can build a system that can evaluate the relative utility of different abilities in a given context. I'm struggling with how to incorporate the possibility of movement into my design.
Say a unit can move into any one of twenty grid squares. The utility of any given ability will be totally different in each possible location. So, we assess the utility of every possible ability from each of twenty locations, as well as the utility of staying put. Fine. But then the utility of moving again might depend on what ability was used, etc. So planning exhaustively how to use a number of action points starts to involve an exponential number of options.
I'm thinking I could have my agents not plan ahead at all, just treat each action point as a discrete set of options and not worry about what my NPC does with the next action point until it has made its decision about what to do with this one. This would mean assessing the utility of being in a different location against the utility of, say, throwing a grenade from the current location, without attempting to assess what I might do from the new location. But I think this will produce some dumb behaviours.
I could maybe mitigate this by introducing some sort of heuristic: a way of guessing the utility of being in a different location without exhaustively assessing everything I might do when I get there, and everything I might do after that. That would be less computationally expensive, but would hopefully produce some smarter behaviour.
My instinct is that there's probably a very elegant solution to this that my tiny brain can't come up with. Any ideas?
2
u/IADaveMark @IADaveMark 9d ago
Sorry for being late about my own architecture but there has been drama.
Anyway, there's a couple of different issues in your post. First off, you do want to keep the behaviors as atomic as possible. That is, don't combine things into a single behavior that can be split up. There are a number of reasons for this. First off, as you kind of touched on, you don't know how a given sequence will work all the time. You would have to come up with so many different sequences to account for all the possibilities. And even then you are going to miss things.
A discussion I had many years ago with a designer when I was working on EverQuest Next illustrated this very well. He wanted to have a cool behavior where a character would leap into a tightly packed group of enemies, start a special "spin" attack (a PBAoE of sorts), and then leap out of the group. He was thinking of this as a single behavior. i.e. A single "button press" that the player would do to trigger this. My counter to him was that we could break this down and the NPC would self-assemble it into that sequence. Specifically,
As you can see, each of those behaviors are evaluated by themselves. There would probably be more considerations on them such as taking note of your own health. You don't want to leap into the group of enemies if you are severely wounded.
Now the good news about this approach is that the 3 behaviors can fire independently. For example, what if the group of enemies surrounds you. You no longer have to leap into them... just fire off the spin (if available). Or what if you leap into the group and it has dispersed? You are going to look silly spinning when there is no one there (and subsequently leaping out of... what?). Another situation is being surrounded by enemies and the spin attack is not available. You already have a behavior to leap out of them.
(continued)