• Welcome to Final Fantasy Hacktics. Please login or sign up.
 
April 23, 2024, 10:42:09 am

News:

Use of ePSXe before 2.0 is highly discouraged. Mednafen, RetroArch, and Duckstation are recommended for playing/testing, pSX is recommended for debugging.


Game AI code/logic

Started by IronCactuar, April 15, 2012, 11:02:14 pm

IronCactuar

Does anyone know where I might be able to see a decision tree or AI algorithm? I'd love to analyze the code to learn how to make AI for future games.

I apologize if this request breaks any rules of this forum.

formerdeathcorps

April 16, 2012, 12:57:07 am #1 Last Edit: April 16, 2012, 01:05:26 am by formerdeathcorps
Xif, please move this to hacking.

SA is currently working on exactly that, but there is a rough hierarchy for AI decisions.

1. Remove Golem
2. Put unit into critical or worse (status effects that add KO status count too)
3. Adding Slow > Charm > Frog = Chicken > Don't Act > Stop > Sleep > 0 CT to enemies and Golem > Haste > Defend > 100 CT to self.
4. Attack charging/Don't Acted units
5. Heal Self/Ensuring survival of allies/run if in critical health
6. Remove KO status from others
7. Heal Others
8. Unevadable attacks
9. AoE/Ranged attacks
10. Normal Attacks > Breaks > Stat Breaks (Other than CT)
11. Charged Attacks (Damage takes precedence over Charge Time)
12. Stat Boosts

Exceptions: When the AI only has one non-crystallized unit left alive, the AI will never run, even if in critical health
Exceptions: Units with statii like sleep/charm/stop will be ignored until the status is just about to wear off.
Exceptions: Death Sentenced units will be completely ignored.
Exceptions: If the AI sees a multi-unit combination that can end the match, the AI will override healing.

Movement behavior:
Will try to move into range and attack the enemy.  If multiple squares are possible, the AI picks the square that minimizes the target's evasion and the number of units that can hit the attacker.  This latter behavior is observed even when the attacker is not in range.  Certain maps also affect behavior.
If berserk, movement will be full.
Teleport will occasionally teleport beyond the movement limit.
Unit will always retreat after healing HP.  Units may occasionally retreat or not move after removing negative status or adding positive status.
Units moving after charging or performing will always move in an inhibited manner.

Flaws:
Tries to remove Golem at all costs.
Does not see evasion except in the roughest sense of 0% vs. not 0%.  Wrongly assumes all attacks always hit, so evasion is only used to determine whether an unevadable attack should be used.
Does not see counter abilities.
Wrongly assumes multi-status spells always inflict every status mentioned. 
If a unit's spells do not add a KO or inhibitory status, the unit is not considered an MP user even if the spells cost MP.
Considers units PA/MA/MP dependent based on skillset alone rather than considering skillset + weapon.
Considers poison and regen to be equal to damage and healing, respectively.
Considers haste to be the only positive status effect worth casting when a unit isn't wounded.
As long as allies are not wounded to critical or worse, does not assess net damage.  (This means the AI will kill/status an enemy even if nearby allies took more damage.)
If a unit is due to die in a few turns and cannot save himself and is not in range to heal others or midcharge the incoming cast, the AI will pick the attack that has the biggest effect, not the one it can actually use before the cast would resolve.
The destruction of the will is the rape of the mind.
The dogmas of every era are nothing but the fantasies of those in power; their dreams are our waking nightmares.

Pickle Girl Fanboy

Wow, FFT is stupid.

Does this apply to Allied and Guest AI, as well as Enemy?

The Damned

(This really needs to be posted somewhere more visible if it's not already on wiki considering I've been wondering about some of these for a while.)

Ironically, despite sussing out a great many of these myself over the years and being annoyed with some of the more visible flaws, FFT has fewer problems than I thought. This gives me a rather...odd sense of hope.

You should probably note, under Exceptions, that AI won't target a Confused unit either unless it can do < 50% of its HP in one attack. Hence why that dumb-ass Loss strategy worked for SSC and SSSC challenges; I am not proud that I had to use that against Adrammelech as a solo Summoner...and it worked.

Also maybe that the (enemy) AI will literally never use Invite even if that's all it has.

Quote from: Pickle Girl Fanboy on April 16, 2012, 03:32:52 pm
Wow, FFT is stupid.

Does this apply to Allied and Guest AI, as well as Enemy?


I'm pretty sure this applies to all AI, including Allied and Guest ones. I mean, we've all seen how dumb Mustadio at Zaland can act and how Alma & Ovelia prioritize Mbarrier/Aegis over literally everything else. So even though I can't answer "officially", I can't imagine how Allied & Guests would differ from Enemies from what I've seen.
"Sorrow cannot be abolished. It is meaningless to try." - FFX's Yunalesca

"Good and evil are relative, but being a dick cannot be allowed." - Oglaf's Thaumaturge in "The Abyss"

"Well, see, the real magic isn't believing in yourself. The real magic is manipulating people by telling them to believe in themselves. The more you believe, the less you check facts."  - Oglaf's Vanka in "Conviction"


IronCactuar

I'm glad to see that this is being shown such interest. I would like to know, however, where did this information come from? Has someone found the game engine code and looked at it, or has it just been a bunch of trial and error?

I'd be very interested in seeing some visual representation of this logic, like in the form of a decision tree. Does anyone know if something like this is available?

Eternal

I don't think anyone's fully deciphered the actual AI code, most of what we know is from trial and error and the various AI tournaments we've had.
  • Modding version: PSX & WotL
"You, no less human than we? Ha! Now there's a beastly thought. You've been less than we from the moment your baseborn father fell upon your mother in whatever gutter saw you sired! You've been chattel since you came into the world drenched in common blood!"
  • Discord username: eternal248#1817