# How would you do AI for this?

## Recommended Posts

hello all, i'm having a problem with figuring out how to appoach ai for the game i'm making.

basically, the battle system is a real time version of final fantasy tatics turn based system, only battled with creatures instead of people, and where stamina/Mana governs how creatures can attack/move.

here's a video of an earlier build of me fighting myself.

anyway, i just don't know where to begin with in terms of ai, it's all going to be scripted in lua so i can do things with unique npc's, but the most i can come up with is checking each action a creature the npc controls can do against another creature. and factoring a number to see how it affects(this number can be partially controlled by the action's own scripting.) and eventually choosing the highest action factored. also, as you can see, you can avoid attacks by moving away before they hit, i'd like to approach this as well.

but i also need to figure out how to factor in movement to other spaces and such.

in short, looking at the basic mechanics in the video, i'd like to hear how people would implement ai in this game.

##### Share on other sites
The method you are describing uses a utility function to decide the next move. It is a totally valid approach in your situation. You can find some information on implementing such a system by searching around by the name, or checking out this book by the resident utility-master Dave Mark: [url="http://www.amazon.com/Behavioral-Mathematics-Game-Dave-Mark/dp/1584506849"]http://www.amazon.com/Behavioral-Mathematics-Game-Dave-Mark/dp/1584506849[/url]

I would probably write a simple finite state machine or behavior tree that then uses utility functions like you described to drive the transitions from one state to another. Check out some of the sites in the stickied resource thread if you want to learn more about those methods!

##### Share on other sites
[quote name='Benholio' timestamp='1326815933' post='4903659']
The method you are describing uses a utility function to decide the next move. It is a totally valid approach in your situation. You can find some information on implementing such a system by searching around by the name, or checking out this book by the resident utility-master Dave Mark: [url="http://www.amazon.com/Behavioral-Mathematics-Game-Dave-Mark/dp/1584506849"]http://www.amazon.co...k/dp/1584506849[/url]

I would probably write a simple finite state machine or behavior tree that then uses utility functions like you described to drive the transitions from one state to another. Check out some of the sites in the stickied resource thread if you want to learn more about those methods!
[/quote]

What he said.

##### Share on other sites
[quote name='Benholio' timestamp='1326815933' post='4903659']
The method you are describing uses a utility function to decide the next move. It is a totally valid approach in your situation. You can find some information on implementing such a system by searching around by the name, or checking out this book by the resident utility-master Dave Mark: [url="http://www.amazon.com/Behavioral-Mathematics-Game-Dave-Mark/dp/1584506849"]http://www.amazon.co...k/dp/1584506849[/url]

I would probably write a simple finite state machine or behavior tree that then uses utility functions like you described to drive the transitions from one state to another. Check out some of the sites in the stickied resource thread if you want to learn more about those methods!
[/quote]

That is an excellent book, without a doubt and is a highly recommended read for anyone looking into game AI. But Behavioral Mathematics for Game AI is more about the theory of behavioral mechanics. It sound as though this game would be a perfect canidate for a combination of Finite State Machines and Fuzzy Logic. FSM is a fairly simple AI mechanic, but Fuzzy Logic is a bit more in depth and deals with probabilities. I recommend "Programming Game AI by Example, by Mat Buckland". He provides an excellent implementation of Fuzzy Logic in his book, plus much, much more

[url="http://www.amazon.com/Programming-Game-Example-Mat-Buckland/dp/1556220782/ref=sr_1_1?s=books&ie=UTF8&qid=1327336093&sr=1-1"]http://www.amazon.com/Programming-Game-Example-Mat-Buckland/dp/1556220782/ref=sr_1_1?s=books&ie=UTF8&qid=1327336093&sr=1-1[/url]

##### Share on other sites
Fuzzy logic is utility theory in a different light. And considering that my book is almost entirely about utility theory, you can see the overlap.

That said, Mat's book is great for learning how to do all the different AI techniques such as FSM. However, note that an FSM doesn't decide anything for you. It is an architecture, not a reasoner. The OP didn't want to know about an architecture for representing/storing what he is doing [i]now[/i] (e.g. a FSM) but rather suggestions on a reasoner about what to do [i]next[/i].

##### Share on other sites
In my opinion, that is what fuzzy logic would help the AI controlled character determine. Based on what the player is doing "now", fuzzy logic can return a weighted value as to what the AI should do next. If the player is, say shooting a lighting ball at the AI, fuzzy logic can determine that the best thing to do next is to try and dodge the players lighting ball. With FSM, the AI can then switch to something like an Evade state in order to try and dodge the incoming attack.

Based on the video posted by the OP, this is how I would construct the AI, which is the reason I suggested this approach. In all honesty, I meant no disrespect, just merely trying to provide a direction in which the OP could take in designing the AI for his game.

##### Share on other sites
[quote name='xByteCode' timestamp='1327348079' post='4905535']
In my opinion, that is what fuzzy logic would help the AI controlled character determine. Based on what the player is doing "now", fuzzy logic can return a weighted value as to what the AI should do next. If the player is, say shooting a lighting ball at the AI, fuzzy logic can determine that the best thing to do next is to try and dodge the players lighting ball. With FSM, the AI can then switch to something like an Evade state in order to try and dodge the incoming attack.

Based on the video posted by the OP, this is how I would construct the AI, which is the reason I suggested this approach. In all honesty, I meant no disrespect, just merely trying to provide a direction in which the OP could take in designing the AI for his game.
[/quote]
No problem, you're on the right track... you are just enamored with the term "fuzzy logic", that's all. Utility theory is the practice of weighing things based on their pros and cons and deciding which gives the best "return on investment" so to speak. It's a much more flexible superset of fuzzy logic.

Also, the fact that probably 90% of all RTS and TBS AI uses utility theory in some form or another is a pretty solid recommendation. [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

##### Share on other sites
thanks all for the input, i'm sorry it's been a little bit since i've responded, i haven't been able to do work on the ai at the moment, as i realized that the ai systems would benefit greatly by incorporating multi threading in my application, to allow my render, ai, and animation routines to be ran side by side, instead of one choking the other.

anyway, that's just about finished now, so, i can again focus on ai.

so, utility theory is the word i'm looking for, thank you for linking me to some book's on the subject, i think i'll purchase both, and gain a better understanding of how to approach ai in my current game, and future game's i work on.

thanks everyone, and if their's anymore input on the subject, i'd be much appreciated to hear more.

##### Share on other sites
risk/reward analysis for the evaluations.

complexity may be significant when several moves/actions are required to carry out goals (and factors like facings and terrain blockage effect results)

'planners' might be useful as well as influence maps if multiple object interactions/coordinations are part of the game problem

##### Share on other sites
[quote name='wodinoneeye' timestamp='1327567478' post='4906359']
risk/reward analysis for the evaluations.

complexity may be significant when several moves/actions are required to carry out goals (and factors like facings and terrain blockage effect results)

'planners' might be useful as well as influence maps if multiple object interactions/coordinations are part of the game problem
[/quote]
That about covers it. I planner would be an OK solution but might be a bit harder to pull off in Lua. Even then, you need to use the utility theory stuff to create the edge weights of your plan graph. Influence maps, as you mention, are very valuable here but really only if you have multi-unit things going on. Even then, influence maps are pretty much 2D grid-based utility in that they are combining the risk and reward factors into discrete values in space.

Still, all of those terms are very valuable to look up in this situation.

##### Share on other sites
The description I found in ( http://en.wikipedia.org/wiki/Final_fantasy_tactics ) mention multiturn involvement, what sounds like the need to sometimes concentrate fire to kill opposing units and area effect attacks. Definitely coordinating mutiple units movement and firing for best effect AND to deny the same to your enemy -- alot of combinatorics and including the unknowns of what your opponent does (exploding the possibilities further).

Methods of partial reevaluation would likely have a big payoff.

Lua I would assume allows you to write C/C++ functional code which for a planner and pathfinding would likely be needed to speed up the AI for this level of complexity. SInce its not a realtime game the time the user spends on input could be used to reevaluate the game situation.

Good point.

##### Share on other sites
hey guys, i just wanted to give an update on how it's coming along:

essentially it's a state machine for each player, and it subdivides long ai processing by spacing out alot of the checks over several frames. it's pretty decent for my needs, and puts up a nice fight. it also required a lot of involment from the action's scripts themselves to maintain what they are about to hit, and what tile's they could potentially hit(to avoid walking onto another tile that might be targeted.)

it also showed alot of bugs that i couldn't find myself due to lack of speed for input's(such as the sliding death at the end.), it's kindof interesting to see that it brings out alot of bugs in how the game handles things when the ai is unrestricted at how fast it can process and do things.

one suggestion by wodinoneeye is the coordination. doing this in real time means alot of spacing the algorithm across multiple steps. and keeping track of alot more data to weight in the need for multiple units striking the same unit. currently, the ai works on 1 unit at a time, and evaluates all the opponent's, it then takes each opponent, and checks to see what the least relative cost action it can perform(also looks up if combining movement/attack would cost less than an attack that could potentially hit the target from it's current position.)

it's not perfect, but fits my needs for now.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628383
• Total Posts
2982383

• 10
• 9
• 15
• 24
• 11