Please login or register.

Login with username, password and session length
Advanced search  

News:

Please use .png instead of .bmp when uploading unfinished sprites to the forum!

Pages: [1]
Internet Cool
Dokurider [Posts: 2806]
  • View Profile
  • http://steamcommunity.com/profiles/76561198023738783/
  • share
  • [December 28, 2016, 10:59:25 PM]
How the AI Works - An ongoing project researching the AI's code
« on: December 28, 2016, 10:59:25 PM »
Hey guys, I'm going to spend some time looking into the AI's code. I don't know exactly how far I'll get, but I already have some great results.

Unit Target Priority

Located in: AI End of turn, in between turn, etc. (0019d37c)

*Note: The entire routine isn't done yet, but the subroutine I'm about to talk about will prove very interesting and is documented.

Summary:
Target Value Formula

(HP Value[curHP * 128 / maxHP] + Total Status Values + (51 * # of items broken up to 7) + Caster Hate [(curMP% / 16) * # MP using Abilities, 0 if not enough MP] + Golem Fear [CurGolem * 128 / Average Team HP (- 1 if Golem not damaged)]) * (-1 if unit is Enemy, 1 if ally)



HP Value goes from 0% to 128%. Multiply by 25/32 to get 0% - 100%.

This is the formula that the AI uses the determine how much priority an individual unit gets.

The more negative the value, the higher on the enemy target priority that unit becomes. The lower the target's HP, the more of a target that unit becomes, which makes sense. However there most likely is a threshold and the unit will be ignored if it gets too negative.

I assume that the Priority Value is interpreted as effective curHP%. So if a unit has -50% effective curHP%, the AI assumes that unit is pretty incapacitated and will ignore them for a unit that has 5% effective curHP%. However, units in critical are flagged and singled out, so the AI doesn't ignore units with no HP left but a ton of non-fatal statuses.

Units that are Petrified, Dead with no Reraise, Death Sentenced, and Charging/Performing skip giving a Target Value at all. Charging and Performing do not need to contribute to Priority because they already have their own routines to processes them. Same goes for Dead and Petrify.

Now, what exactly, does the AI do with this Target Value next, I've yet to determine.

Observations:

You didn't make a sacrifice to the RNG gods today, I'm just gonna sit and spin my wheels instead

This confuses me a bit, but no matter how you slice it, it does seem that the AI will occasionally skip assigning units a Target Value at all or basically decide not to do anything at all this turn. The odds of that happening is pretty small because while this might be a 13.7% of that happening every time you come here, the AI comes to this routine several times. So it's more like a .13X% very tiny chance of that happening. Still, giving the amount of decisions the AI makes just per battle, it can and has been observed to happen.

Blind and Silence gain more value to the AI the more abilities you have that are Evadable/Silenceable

This is probably why the AI doesn't seem to like adding Blind a lot in Arena, or even at all. The AI doesn't take into an account just how much damage a unit can actually do. Attack, even if they deal a truck load of damage, is only one skill to the AI. It cannot tell the immediate difference between a White Mage with Healing Staff and a Berserk Cursed Ring Two Handed Main Gauche killer. Since there aren't too many physically evadable skills in the game, the AI just tends to not want to use Blind all that much it seems, only ever adding -12.5% priority at one time. So simply having no abilities at all is apparently just as good as Blind Immunity. The AI looks at the percentage of units with P-Ev, not the total.

It should be a different story for Silence, but I only ever seen the AI cast Silence as an interrupt, not ever by itself to debuff, even though it's desire to should be much higher, right?

Units become bigger targets the more equips they lose
Seems pretty straight forward. The more stuff you lose, the bigger of a target you become. What is a bit surprising is that all items lost are treated equal. In practice however, you also lose Max HP for losing Armor anyways, so you become an even bigger target than normal.

The AI really fucking hates Mages

The AI puts priority on units that have lots of mana and can cast a variety of spells. So if you ever wondered why they gun after your weak little mages all the time, this is why. The price these guys can gain can get stupid high at time, just take your MP, divide by 16, and multiply it by your number of spells to get a grasp on just how much the AI hates spellcasters.
Robe of Lords might as well be a giant Kick Me sign.
The AI takes into account the percentage of spells with MP costs.

Golem is complete cancer
To clarify, this is not exactly why the AI drops everything it's doing to break Golem and makes the AI retarded. However, this is not really helping at all. You can clearly see the fault in adding the same amount of priority value to all units in a team. it's useless at best. Nuke this section please.


Finally, here are the Status Target Priority Values.

Status Priority Values (19f308)
Values, I assume, are interpreted as curHP%, thus, each status is +/- effective curHP.
Code: [Select]
0x0058: Current Statuses 1
0x80 - 0% (0000)
0x40 - Crystal -150% -c0(ff40)
0x20 - Dead -150% -c0(ff40)
0x10 - Undead -30.5% -27(ffd9)
0x08 - Charging 0% (0000)
0x04 - Jump 0% (0000)
0x02 - Defending 0% (0000)
0x01 - Performing 0% (0000)
0x0059: Current Statuses 2
0x80 - Petrify -90.6% -74(ff8c)
0x40 - Invite -180.4% -e7(ff19)
0x20 - Darkness -50% [-40(ffc0) * Evadable abilities] + 3 / 4
0x10 - Confusion -50% -40(ffc0) (+1 / 4 if slow/stop/sleep/don't move/act/)
0x08 - Silence -70.3% [-5a(ffa6) * Silence abilities] + 3 / 4
0x04 - Blood Suck -90.6% -74(ff8c) (+1 / 4 if slow/stop/sleep/don't move/act/)
0x02 - Cursed 0%(0000)
0x01 - Treasure -150% -c0(ff40)
0x005a: Current Statuses 3
0x80 - Oil -5.5% -7(fff9)
0x40 - Float 9.4% c(000c)
0x20 - Reraise 39.8% 33(0033)
0x10 - Transparent 29.7% 26(0026)
0x08 - Berserk -30.5% -27(ffd9)
0x04 - Chicken -20.3% -1a(ffe6)
0x02 - Frog -40.6% -34(ffcc)
0x01 - Critical -25% -20(ffe0)
0x005b: Current Statuses 4
0x80 - Poison -20.3% -1a(ffe6)
0x40 - Regen 19.5% 19(0019)
0x20 - Protect 19.5% 19(0019)
0x10 - Shell 19.5% 19(0019)
0x08 - Haste 14.8% 13(0013)
0x04 - Slow -30.5% -27(ffd9) 0 if Confusion/Charm/Blood Suck
0x02 - Stop -70.3% -5a(ffa6) 0 if Confusion/Charm/Blood Suck
0x01 - Wall 50% 40(0040)
0x005c: Current Statuses 5
0x80 - Faith 4.7% 6(0006)
0x40 - Innocent -5.5% -7(fff9)
0x20 - Charm -50% -40(ffc0) (+1 / 4 if slow/stop/sleep/don't move/act/)
0x10 - Sleep -30.5% -27(ffd9) 0 if Confusion/Charm/Blood Suck
0x08 - Don't Move -30.5% -27(ffd9) 0 if Confusion/Charm/Blood Suck
0x04 - Don't Act -50% -40(ffc0) 0 if Confusion/Charm/Blood Suck
0x02 - Reflect 19.5% 19(0019)
0x01 - Death Sentence -80.5% -67(ff99)
« Last Edit: January 07, 2017, 04:10:23 AM by Dokurider »
Mediator
Eternal [Posts: 3013]
  • View Profile
  • share
  • [December 29, 2016, 12:25:45 AM]
Re: How the AI Works - An ongoing project researching the AI's code
« Reply #1 on: December 29, 2016, 12:25:45 AM »
This is great stuff! Keep up the amazing work, Doku. :)

"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!"
Internet Cool
Dokurider [Posts: 2806]
  • View Profile
  • http://steamcommunity.com/profiles/76561198023738783/
  • share
  • [December 29, 2016, 12:33:10 AM]
Re: How the AI Works - An ongoing project researching the AI's code
« Reply #2 on: December 29, 2016, 12:33:10 AM »
A few more comments:

Remember that for certain skillsets, the abilities in them only ever count as one skill. For an example, Jump is only ever counted as 0x018a, Level Jump 2 and only that, no matter how many other jumps you've learned. Same goes for Elemental, and I believe Throw as well.

Oil has a very low priority value (-5.5%), which was why it had to be constantly bundled with other statuses and effects to be used by the AI. Makes a bit of sense seeing that in Vanilla, Oil didn't work at all.

Blind is -12.5% for each P-Ev skill known, including Attack. Silence is -17.5% for each silenceable ability known.

Transparent and Reraise have very high positive values, which might be why the AI gets so aggressive when they have them.

Anything that drops the target's priority to -50% might trigger the 'ignore completely' routine, which includes Confuse, Charm, and Blood Suck (Death Sentence gets it's own special flag and gets skipped in this routine). We could experiment and lower them to see if the AI continues to ignore confused/charmed lone targets.
« Last Edit: December 29, 2016, 09:01:53 PM by Dokurider »
Internet Cool
Dokurider [Posts: 2806]
  • View Profile
  • http://steamcommunity.com/profiles/76561198023738783/
  • share
  • [January 07, 2017, 04:04:56 AM]
Re: How the AI Works - An ongoing project researching the AI's code
« Reply #3 on: January 07, 2017, 04:04:56 AM »
Okay before I get into my next deal, a few clarifications and corrections:

The AI does not care how much MP you have, only the current percentage and if you have enough to cast your Lowest MP cost spell.

In fact, as you'll soon see, the AI puts far more stock into your spells than your curMP.

Shout out to Choto for uploading the routine I'm basing this all of on and I presume documenting this routine and pretty much every other routine in the wiki lol.

I'll keep the code down to a minimum this time because the code is already documented.

How the AI calculates it's Blind/Silence/Caster factor

Step 1: Usable Abilites

The AI starts by figuring out what abilities it has is usable. It starts off with Attack, then it starts going into it's skillsets. While it processes Throw, Math, Charge and Jump a little differently, it's nothing really eyebrow raising except perhaps the way Charging with Guns is treated (refuses to use Charge for guns it seems?) In any case, it first checks to see if the skill is flagged as Usable by the AI. It then checks to see if the ability in question uses MP and if it does, do you even have the Max MP to even cast it?

Yes it does reduce the MP Cost by Half of MP, but the 1/3 of MP did not update the AI to reflect this. A fix is in the works, so don't fret too much.

Then it renders abilities unusable if the ability is a faith spell on a unit with innate Innocent, or the unit doesn't have the requred Sword/Materia Blade to use said ability. You can't know a skill that requires Monster Skill without...Monster Skill, and more importantly, if you are not in fact a monster yourself. If the ability in question is 0x170 (Potion and other special abilities) or higher, it will skip all of that and go to the final step. Keep that in mind if you're trying to make those skills normal.

And finally, of course, it has to have actually learned the ability in the first place. Once it has cleared all of that and the skillset in question is not Jump, it will trot out the list of known abilities for that skillset. Repeat for the other skillset. Finally it will save all of this, plus Frog Attack. Yes, the AI always knows Frog Attack as well as Attack. I suppose you can think of it as the Struggle of FFT. It's also what Monster units use when Berserked. The AI always counting Attack and Frog Attack in it's skill counting is very important to remember for later.

Step 2: Deriving Silence/P-Ev/MP skill counts and some small usage flagging

Now that we have our list of Usable abilities, we can derive our Silence/Blind/Caster mods from them. It's about what you'd expect. Add up all abilities that are physically evadable (aka evade with motion), silenceable, and uses MP. There are no restrictions against any of them other than being flagged as such.

It stores the Lowest and Highest MP costs that unit has. It flags Linear/Vertical/Triple Bracelet|Attack, and any attack over 3 range + AoE as 0x0400. It flags Reflect/Silencable or has an AoE of 0 as 0x0200.

Step 3: How to get your Blind/Silence/Caster values and how to game the system.

So the basic formula for determine your unit's Blind/Silence/Caster factor is:
Quote
(# of effected spells * 4) / Total Usable spells
This will get you a number between 0-4, with 0 being less than 25% and 4 being 100%. Remember that you must always factor in both Attack and Frog Attack into your calculations.

For an example, a unit that has no skills learned, will only know Attack and Frog Attack. He has a Silence and Caster factor of 0, but a Blind factor of 4, because:
Quote
[# of P-EV abilities=2] * 4 / [# of total abilities=2] = 4
So he would be a prime Blind target, assuming he was vulnerable to Blind. But if he learned any one (1) non P-Ev ability, his Blind factor would drop dramatically to 2. Picking up two more non P-Ev skills would bump his total skills usable to 5 and his Blind factor to 1. He might as well be a mage with a Healing Staff.

So I wasn't completely accurate when I said the AI can't "tell the immediate difference between a White Mage with Healing Staff and a Berserk Cursed Ring Two Handed Main Gauche killer", because it kinda can. But it can be easily gamed to duck being targeted.

So if you want your Casters to duck being targeted, remember you always have two non MP using skills to balance against, thus you will never have a max Silence/Caster factor of 4.

Can I simply have a Summon Magic secondary on my Male Lancer, learn as many Summons as feasible and then never get targeted by Blind ever?
Not exactly. Remember that the AI kicks out any skill from it's usable pool if it has an MP cost exceeding it's Max MP. But if you have enough MP to cast any of them even once, then yes, you can grab that cheap caster aggro and be a taunt tank...exactly once before the AI casts a spell, and then you're completely out of MP and the game yanks your aggro license.



That's about everything for today. It's not a major revelation today, sorry, but I'm a little overdue. I made a few edits to the original post to fix some mistakes in my original analysis. I don't have too many complaints about how the AI calculates the factors, except the caster value. It should compensate for Attack/Frog Attack.
Internet Cool
Dokurider [Posts: 2806]
  • View Profile
  • http://steamcommunity.com/profiles/76561198023738783/
  • share
  • [January 21, 2017, 08:05:36 AM]
Re: How the AI Works - An ongoing project researching the AI's code
« Reply #4 on: January 21, 2017, 08:05:36 AM »
Hey folks, got another section for you guys.

AI Ability Use (19e5d8) has been known about for a while, but only lightly documented until now. This routine doesn't really so much decide what abilities to use, so much as says what abilities to not use. Nevertheless what you're about to read will enlighten you.


Comments and Observations

How Wall was supposed to be used - Part 1


So far, this routine prevents the AI from targeting Enemies with Ally Only spells (and vice versa), targeting itself if the spell can't target caster, targeting units with Reflect if spell is reflectable (there is a bypass option, more on this later), targeting Innocent units if a Faith spell, Petrified units unless the ability cures it, and Jumping units. Don't target enemy units that null/absorb your element or are undead and will absorb your damage. Don't revive units with Reraise. They can even tell when it's too late to revive a unit and their spell won't go off in time. Most of this is expected and surprises no one. What might though is that Wall actually has code here.

This is about what you'd expect: Don't target units with Wall, duh. That is, unless you can cancel the status. It's interesting that Wall was far enough along in development that it has it's own processing in this routine. I wasn't really expecting the AI to know how to handle Wall at all. Wall must have been removed from the game rather late in the game's development then. Maybe they realized that becoming invincible on command for 32 CT and still being able to act was kinda broken even for FFT? Even if you could dispel it?


How the AI breaks Charm/Confuse/Sleep with damage


This is how the AI is allowed to target it's allies with damage abilities to break Charm/Confuse/Sleep. The AI is finnicky in removing Charm somewhat. It won't remove Charm if it can't get the spell off before the unit acts. It shouldn't matter for Throw Stone, but it might for everything else with a charge.

Speaking of Charge, the AI won't use Charge to break these statuses. Of course that leaves Jump on the table. This can be fixed to check for Charge and Jump, but it requires extra space to do so because of all the load delays. But since Arena doesn't use Charge, you could just have the game check for Jump instead. Then you should have no more Jumping on sleeping units.

There is also Elemental Healing here as well. It works the same way normal healing does (more on that later). What's really odd about it, is that if an ability has an Element, but doesn't deal HP damage, the AI thinks it's blocked by Absorption and won't use it! That is absolutely not the case for any non damage formula, most of which can't even accept/don't check for Elements in their spells, and there are no non damage spells in Vanilla that even have Elements. I actually think this might just be an oversight because it could have just branched to the very next section and it would have been very relevant for it to do so.

Also in theory, the AI, if you made a unit Always: Confused, should constantly attempt to break a unit's Confusion because it doesn't check if it's an innate like it does Sleep and Charm.


How the AI deals with Blood Suck units (and Confusion as well)


Another way that the AI deals with Blood Suck and Confused units (besides curing it), is to disable them with statuses. The AI will only use Sleep, Don't Move, Don't Act, Slow and Stop on Blood Suck and Confused units.

I have to disagree with having Confusion here at all. It's easy enough to cure, so a Confused Unit shouldn't be getting disabled by it's own units. Meanwhile, Blood Suck need harsher statuses to be dealt with. I used to just straight up kill Blood Sucked units when I couldn't heal them because it was easier to just remove BS that way and I think the AI should think this as well.


HP and MP Damage and Death Sentence

AI will not deal HP damage to Death Sentence. They will also use MP Damage until the unit can't cast anymore spells. This is not a surprise. What might be a surprise is that the AI won't use Ally Spells that don't add Reraise on them either...even if the spell in question would heal Death Sentence.
Quote
But the AI cures Death Sentence all the time with Refute
That's actually because Refute is not an Ally or an Enemy spell. Ignoring Death Sentence units only applies when the spell in question is either an Ally or Enemy spell. Not being either bypasses this behavior, allowing for curing or attacking.


Healing HP and MP


The AI will only heal HP and MP if the unit is under 50% of their respective stat. This is fine for HP, but it's very noticeable when attempting to heal MP. It's a hard 50% too.


How the AI adds statuses - Adding Blind and Silence


First off, the routine checks if the status in question is already present or the target is immune to it, no surprises there.

The AI will only consider adding Blind and Silence if the respective modifiers are high enough. Recall that the AI keeps track of how many Silenceable and Blindable moves you know and it saves this value as 0-4, with 4 being 100% and 0 being less than 25%.

The AI will not even entertain adding Silence to a unit that has no silenceable statuses learned. Reasonable. However, the AI will not consider adding Blind if you have less than 50% P-Ev skills learned. This includes Attack and Frog Attack. This could probably be lowered to 25%.


How the AI adds statuses - Adding Reraise, Frog and Float


The AI will not add Reraise on a unit unless they are under 50% HP. They also will not try to turn their allies into frogs. Finally, the AI will never use Float on itself unless it's in critical. Yes, you read that correctly. In critical. More on this in the next section.


]How the AI adds statuses - Adding Regen, Protect, Shell, Haste, Slow, and Wall (Part 2)
Alternate Title: How to Train Your AI to Preemptively Buff

Here you go. So why won't the AI preemptively buff themselves with any positive statuses besides Haste? Because it's not so much Haste is special or anything, but because Haste is the only positive status that doesn't have a restriction. Yeah don't use Haste/Slow on Stop/Sleeping units, but that's besides the point.

Protect, Shell, (and Wall) will not be used unless the unit in question is in Critical. Why Critical instead of 50% HP like Regen is beyond me but it makes it kinda useless for the AI. It makes sense that these status aren't usable at full HP in Vanilla because you don't have any skill restrictions and the developers probably got pissed at the AI constantly buffing itself instead of fighting.

At the very least, Protect and Shell should be used like Haste. In fact, make it so that the AI will only use Protect/Shell/Haste if they are above 50% HP. That way, they aren't using these statuses when they just got revived.

The AI adds Regen when it's Poisoned. I think why this is, is because the AI isn't adding Regen in it's mind, it's canceling Poison.

Interesting that Wall also got this treatment as well. This means that the developers really played around with Wall long enough to try to curb it's usage.


How the AI adds statuses - Faith and Reflect

More usage nerfs to positive statuses. This is why sometimes you see the AI use Faith and Reflect on itself when it's in critical, recalling that Faith and Reflect have slightly positive priorities and are kinda seen as gaining HP. Making the AI add Faith in a smart way is going to require some space to do, but it can be done. Same goes for Reflect. Death Sentence could probably be restricted to use on units with 50% or greater as well.


How the AI Removes Status - Charm, Don't Act and Don't Move


The AI checks to see if the unit doesn't have the status or it's innate. No surprises there.

The AI will only remove Charm, Don't Act and Don't Move before a unit's turn. If the Ability CT is too high to do this, then it won't remove them.


How the AI Removes Status - Blind/Silence and Frog



The only difference from adding Blind/Silence is that the AI will cure Blind as long as you have any Evadable abilities. Since all units have Attack, that should be all the time, right? Also don't remove Frog from your enemies, k thanks.


The AI uses Stat Abilities randomly.


This is a bit of a shocker. If it's not Praise, Accumulate, or Yell, the AI's gotta roll the dice. This is why the AI doesn't use Stat abilities that much. There's probably a better way of doing this, perhaps only use on <50% HP units? Actually fucking look at their stats?


How the AI uses Break/Steal
Code: [Select]
<Unequip>
0019eee0: 8fc2000c lw r2,0x000c(r30)             
0019eee4: 00000000 nop
0019eee8: 30420004 andi r2,r2,0x0004              Check if ability is Unequip
0019eeec: 0002102b sltu r2,r0,r2                  Use Ability if true

Okay then.



So there you guys have it. This routine doesn't so much tell the AI what to select, so much as it tells the AI what not to select. There is some for improvement, so go ahead and leave some thoughts on how to improve this routine.
Mediator
Eternal [Posts: 3013]
  • View Profile
  • share
  • [January 21, 2017, 12:07:03 PM]
Re: How the AI Works - An ongoing project researching the AI's code
« Reply #5 on: January 21, 2017, 12:07:03 PM »
Great work as always. This topic is really fascinating. Thoughts on Float though: I know I've seen it use Float outside of Critical after seeing an Earth spell. Heck, I think I've seen it used before an Earth spell was used, but the AI still "saw" it in the party's skillset.

"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!"
Internet Cool
Dokurider [Posts: 2806]
  • View Profile
  • http://steamcommunity.com/profiles/76561198023738783/
  • share
  • [January 21, 2017, 04:26:50 PM]
Re: How the AI Works - An ongoing project researching the AI's code
« Reply #6 on: January 21, 2017, 04:26:50 PM »
Great work as always. This topic is really fascinating. Thoughts on Float though: I know I've seen it use Float outside of Critical after seeing an Earth spell. Heck, I think I've seen it used before an Earth spell was used, but the AI still "saw" it in the party's skillset.
You're certainly right. I'm positive there's an auxiliary usage routine that enables usage to mitigate spells/the midcharge behavior. Adding Reflect, Innocent, interrupting a unit's spell, all very well documented behaviors. I'll certainly keep an eye out for them.

EDIT: Oh wait, duh, it's right there in my face. I'll explain in a minute, I forgot to talk about the Reflect Bypass anyways.
Internet Cool
Dokurider [Posts: 2806]
  • View Profile
  • http://steamcommunity.com/profiles/76561198023738783/
  • share
  • [January 21, 2017, 05:28:58 PM]
Re: How the AI Works - An ongoing project researching the AI's code
« Reply #7 on: January 21, 2017, 05:28:58 PM »
Targeting Reflect Units


I forgot to finish talking about this.

Apparently, the AI sets if it wants to bypass targeting Reflect units with Reflect or not. So why the hell would it try to target Reflectunits with a Reflectable spell? To use that unit to bounce Reflect off of course. This is merely the start of how the AI banks spells off of Reflect units.


How the AI mitigates Spells


So how does the AI attempt to mitigate spells? If the unit can't midcharge the spell directly, it will then ask this question: "Hypothetically, if I had Innocent, Reflect, Jump, Wall or Float, would this ability I have null the spell being targeted on me?" And if this routine returns 0, "Yes, it will mitigate the spell." then it enables usage. It's a theory I have however. I have to actually see if the governing routines do this, but I think it's pretty likely it does.
Raijinili [Posts: 58]
  • View Profile
  • share
  • [March 21, 2017, 08:52:40 PM]
Re: How the AI Works - An ongoing project researching the AI's code
« Reply #8 on: March 21, 2017, 08:52:40 PM »
I wanted to work on externalizing the AI, when I came across this topic. "Externalizing" meaning, when a character on a particular team is to take a turn, the emulator pauses, calls an external script (one per team) to decide what to do, writes the choices into memory, jumps to the FFT code, and resumes. The eventual goal is to have custom AI tournaments.

I ignore the problem of finding an emulator that can do this, and want to figure out:
- Where to stop. (Entry point of turn-decider.)
- What data to expose to the script.
- Where to write to.
- Where to resume. (Exit point of decider.)

I know you're looking into the part of the code that I want to bypass, but did you happen to stumble upon anything that would help me?

(For complete automation, there needs to be a hack to make "Crystal" automatically pick "Heal HP/MP", but I'm also ignoring that for now.)
Gaignun [Posts: 526]
  • View Profile
  • share
  • [March 23, 2017, 02:11:11 AM]
Re: How the AI Works - An ongoing project researching the AI's code
« Reply #9 on: March 23, 2017, 02:11:11 AM »
I think that would be very interesting, and also educational.

For accessibility, it might be best to have the scripts written in a custom, higher level language, then have them parsed and compiled into ASM. If the scripts must be written in ASM, then I do not believe there will be enough people that know ASM (and can write the scripts without bugs) to even run a tournament.
Internet Cool
Dokurider [Posts: 2806]
  • View Profile
  • http://steamcommunity.com/profiles/76561198023738783/
  • share
  • [March 23, 2017, 10:44:40 PM]
Re: How the AI Works - An ongoing project researching the AI's code
« Reply #10 on: March 23, 2017, 10:44:40 PM »
Oops sorry about the delayed response, Raijinili.

Unfortunately, the complete work flow of the AI is still somewhat of a mystery to me. I've been focusing more on individual decision mechanics rather than the overall flow. It's something I'll get to eventually, but right now, I wouldn't know exactly where the AI decision hierarchy begins in earnest, and where a good entry would need to go. If you come to the arena discord or PM me though, I could give you a more detailed run down of what I do currently know.
Raijinili [Posts: 58]
  • View Profile
  • share
  • [March 27, 2017, 01:44:57 AM]
Re: How the AI Works - An ongoing project researching the AI's code
« Reply #11 on: March 27, 2017, 01:44:57 AM »
Oh well.

I think that would be very interesting, and also educational.

For accessibility, it might be best to have the scripts written in a custom, higher level language, then have them parsed and compiled into ASM. If the scripts must be written in ASM, then I do not believe there will be enough people that know ASM (and can write the scripts without bugs) to even run a tournament.

Edit: To keep this from distracting too much away from Dokurider's work, I made a new topic.
http://ffhacktics.com/smf/index.php?topic=11674.0
« Last Edit: March 27, 2017, 03:56:18 AM by Raijinili »
    • Modding version: Other/Unknown
  • Internet Cool
    Dokurider [Posts: 2806]
    • View Profile
    • http://steamcommunity.com/profiles/76561198023738783/
    • share
    • [May 01, 2017, 03:10:05 AM]
    Re: How the AI Works - An ongoing project researching the AI's code
    « Reply #12 on: May 01, 2017, 03:10:05 AM »
    In case you guys still want to follow my progress into the AI's workings, I post my hacks on my hacking topic in the hacking section on a hacking website. I'm pretty close to have something big to post here, but not being able to record anymore is kind of a bummer.
    Internet Cool
    Dokurider [Posts: 2806]
    • View Profile
    • http://steamcommunity.com/profiles/76561198023738783/
    • share
    • [May 09, 2017, 11:01:54 PM]
    Re: How the AI Works - An ongoing project researching the AI's code
    « Reply #13 on: May 09, 2017, 11:01:54 PM »
    Okay kids, huddle 'round. You have another lecture to listen to.

    The AI's idea of normal movement is to move as close to a target unit as close as possible or to move away from the enemy team as much as possible. To accomplish this, it gives each panel three metrics to determine the best panel to move to.



    (19f778) is the Distance from Target or Target Distance. This is the most straight forward of the Movement Metrics. It's simply how far away is this panel away from the target, with 0 being the panel that the target unit is standing on.

    (19f9b8) is the Panel Priority. This is usually the Priority Value gained from just merely stopping on a panel. This is usually the "Do Nothing" value and is usually the same value for all panels in movement range. This should only change if moving onto a panel that has a spell being charged on it. The AI does not see traps. This value can be ignored for the most part.

    (19f538) is the Distance from all Enemy Units or Enemy Distance. This metric basically boils down to, "Which panel is the most isolated, most farthest away, from all non-disabled enemies?" Every panel in movement range takes every single enemy within 10 range, gets how far away it is, subtracts the range from 10, then totals it into it's correlating space.
    What all this means is that the AI will move away from as many enemies as possible within 10 distance.



    Furthermore, the AI has two main movement routines. (19693c) is the main movement routine aka the Post Action Movement Routine. It relies on the metrics described above to find the best panel to move to. The Post Action Movement Routine is usually tasked to flee from the enemy team, rather than to advance onto it's target. This is very notable when the AI is in Critical. Instead of running towards a healing teammate, it runs away from the enemy team, often isolating itself from any kind of support.

    (19af18) contains several subroutines responsible for Pre-Action Movement, among many other important routines. It contains the movement routines responsible for positioning the AI to make an attack. It ranges from simply moving as close as possible, to advancing positioning for restricted and special ranges and AoEs like Linear and Direct. In addition, this routine ends up changing what target the AI will attack, usually because of Priority.



    In vanilla, many of the AI's movement routines are told to emphasize Enemy Distance over Target Distance, meaning they frequently run away. And they will always run away unless they are in Pre-Action.

    In addition, the Post-Action Movement routine processes tiles in a different way than the other movement routines. In particular, Post-Action Movement does not kick out equal results, meaning it ends up saving the Last Panel Processed. Meanwhile, the Pre-Action routine does kick out equal results, meaning it ends up saving the First Panel Processed.

    What this ends up doing is that the AI will constantly move back and forth between the two different results that the two routines produced. Both panels are equal, but are the first and last panels processed. The AI will attempt to satisfy them both, depending on whether the unit is in Pre or Post Action.

    In practice, this behavior is masked by the AI's constant movement, so the AI is rarely in a Post-Action state. It can be seen if the AI is already right besides a disabled enemy. They will constantly move between attacking and moving away as long as the target doesn't move.



    These are just about the only factors the AI considers during Movement Decision. Aside from the Cowardly/Critical AI, there is no real self preservation or moderation logic in play besides the CT checking for charging spells and even that gets ignored in certain circumstances in Vanilla. If they can move the entire distance to make a play, they will. They will run right into the heart of the enemy team without even the slightest hesitation. That is the simple reality of Pre-Action Movement. Post-Action Movement is not much better either.

    The only reason why the AI doesn't always move as far as it can when it's closing the distance between targets or running away, is that it must also satisfy the other Distance Metric, often using it as a tiebreaker between equal results. So you'll see the AI only move 3 panels instead of 4 panels when running away because it also has orders to stay close to it's healing unit, so it ends up moving slightly closer to it's healing ally while running away.

    EDIT: 2800 Post GET.
    Pages: [1]