So i’m creating a turn based strategy game in the vein of xcom and would like some help to design the AI system responsible for finding a target based on some factors I have set up.
My enemy units use a State machine with a node called “Find target”.
This node contains a list of “factors” it checks for when determining a target to choose.
For example the factor Closest will give each enemy unit a rating from 1-0 depending on how close they are. Closest unit being 1.0 and furthest unit being 0.
I then have a second factor called Lowest health which will rate the units by there remaining health. Again, lowest health being a rating of 1.0 and Highest being a rating of 0.
After these factors are calculated I multiply the factors together so each unit has a rating based on the combination of all factors.
The problem with this design is any units at the end of a list of factors would be given a rating of 0 which when multiplied with any other factors would remain at 0. While this would be handy for any factors that would determine a unit to be completely ignored, it doesn’t work for the distance or remaining health factors because no matter how far away or how much health, I would like them to still be considered a target.
Would anyone care to weight in on their thoughts on this system?
Don’t use 0-1 for everything. Can use 0.1 to 1 for distance, for example.
I’m imagine this is covered better in some general AI forum, but: make a spreadsheet. If you don’t know how, this is a good excuse to learn. Enter sample rows for many different targets (kind of far, but almost dead, near, almost dead but very resistant to your attack … .) Add slots for each category you test to enter min/max (these are the ones that start at 0 to 1.) Play wth those numbers, adjust your formula (don’t have to multiply everything – can add some.) See what formula makes the final target numbers seem reasonable.
When I’d like to get an average of 2 numbers, I add them together and divide by 2
Worth noting, also that if you have 2 numbers that determine you factors, you can simply add them together and use that list (without dividing)… just the range is 0-2. But it’s ordered exactly the same.
My AI system uses a Sum of Products type of formula. A typical AI Brain has a list of “Decisions” (A custom class that encapsulates an action to take). Each Decision has a list of “Concerns” (a scriptableObject class that has a function that evaluates the strength of a specific concern based on the current situation).
The Decision pairs each concern with a weighting factor that it multiplies against its concern. This is done so that two brains can have the same type of concern (providing the same result under the same situation) but altered by the per-instance weighting factor so that the two brains can be more individualized.
The Decision will then add up all the concern results returning the strength for that decision. Finally the AI Brain then chooses the Decision with the highest result (Tie-breaks to first decision), branching off to the action to take that’s tied with that decision. If randomness is desired a Randomness Concern can easily be added to any Decision’s Concern list.
This system was something I came up with on the spot for a tower defense game and then later found out its called a Utility AI System.
Averaging?? Well I think the OP did a very nice job, in the second-to-last paragraph, of explaining why the numbers should be multiplied together. I’d imagine if one took joshuaMKenz’s advice and looked up “AI utility function” one might find more on that, if one were so inclined.