The biggest problem with move AI in E16 (Patreon)
Content
mostly.
ok so back when i was asking for questions to take up time during story stuff HachiKenHachirio asked this:
I would like to know how the AI works. Also, very curious how you'll trick out the AI to deal with field effects.
so i'll go over this very briefly and explain how it works with the changes we've made.
first, the looks at the battlers and learns some things about them like what type they are, how much health they have, what moves they have (for their own) and what moves the player has used (if it's a high skill trainer) and also how effective those moves were against their current pokemon
then it's going to look at their own moves one by one and figure out about how much damage each one would do. this is done by a rough-damage method that is basically a theoretical recreation of the actual damage method used in calculation. it thinks about all of those things (including field effect damage, but only if it's the best skill level) and then converts it to value of how much % health it will do to an enemy and keeps that value as a baseline for how good the move is. the second biggest problem with E16 AI is that this theoretical method was incomplete and did not account for many things. it's been completed now.
then for moves that do not do damage it's going to pull an arbitrary value that we've assigned to it based on the utility of the move. for moves like growl, helping hand, etc, it's ~10. for moves like spore, recover, it's more like 50-70. this becomes the base value instead.
so now it has a basic understanding of how good its moves are. next it'll check each of their function codes and score them based on other things. function codes are the things that make moves do Things, such as there's one for burning, one for flinching, one for burning and flinching both, one for swords dance, one for tail glow, one for rototiller, one for fucking quash why does this garbage move exist get out of my game tbh
anyway.
each function code has specific AI that tells it when to aim for that effect. it checks the codes for its 4 moves and then tallies up how good an idea it is as a new score. it modifies that based on some other things like accuracy and if this move will kill a partner pokemon too.
finally it thinks about switching. i've posted our shouldswitch and switchto methods here already but basically it's checking various things like the match up, expected incoming attack, stat conditions etc and tallying up a score comparable to the moves' score to decide if we need to get outta dodge. then depending on if the switch score is much higher than a move's score, it'll do so and decide who to switch to.
...so that's it in sum.
so the biggest problem with move AI in E16? well, let's go back to the function code section. because that's what's left to do for 17. just that. the function code section, like the rough damage section, is incomplete in essentials base AI. it was never finished. i'll finish it next episode. i'll take a good bite out of it this time.
but that's not the reason E16 ai makes dumbass moves like preferring resisted thunderpunch over a STAB move.
that's the biggest problem-- the code that already exists from essentials for the function codes, is bad. i'll redo all of it but i fixed the bad part in one sweeping motion a couple days ago.
basically, we've got our baseline score as a % of remaining health, right? so that score is going to be in the like, 5-110 range, at most.
let's take our function code for paralysis, with the thunder punch example above.
the code is something like, for example (im making this up),
if the opponent can be paralyzed, +10, and if we're slower than it and would be faster after it being paralyzed, + another 20
...there's a lot more factors etc but that's the roughest state.
okay so say our enemy pokemon has two moves, thunder punch which would do about 5% of the player's HP cuz it's resisted, and some neutral hitting move that would do around 30%. the AI should totally use the neutral hitting move because there's no counting on the 10% paralysis chance to go through. but the 5% will get +30 total from the function scoring meaning the score is 35 to 30 and the enemy will prefer thunderpunch.
...that is an extreme example of what is happening. usually when opponents use a dumb move it's a move with a secondary effect like paralysis or flinch and the AI is greatly over-valuing the use of those secondary effects.
so how to fix this in under half an hour? multiplicative instead of additive scoring. notepad++ ctrl+f replace "score+=10" with "score*=1.1" for instance. instead of +30 our 5% thunder punch gets *1.3 which is like, 7. 7 vs 30 score? better use the 30. meanwhile say our thunderpunch is 25% instead of 5. 25 * 1.3 = 33. turns out thunderpunch is better after all! this was quick to do for all currently-existing function codes.
anyway that's still very rough and doesn't help with things that are Very Good like Nuzzle so all of it is still going to be done over this episode or next-- but this carries us over during E17 to improve the things we don't get to.
and also i've been wanting to do this for ages. god damn. why was it not this way in the first place : |