![]() |
|||||||||||
|
writing basic AI - Printable Version +- Little Fighter Empire - Forums (https://lf-empire.de/forum) +-- Forum: Little Fighter 2 Zone (https://lf-empire.de/forum/forumdisplay.php?fid=7) +--- Forum: AI Scripting (https://lf-empire.de/forum/forumdisplay.php?fid=56) +--- Thread: writing basic AI (/showthread.php?tid=8187) |
|||||||||||
writing basic AI - YinYin - 08-19-2012 I am currently trying to write a basic AI equal or better than the original. I already have quite a bit of it working and I want to lay down the path of it's creation here: function by function, explaining everything along the way. planned featrues (Click to View) Please comment on what features you would add, where you would write the script differently to make it better, or just what function you would like to see next or better explained. So I will start of with the main function, the sequence that runs once every frame the game updates it's screen. I will keep it as simple as possible for now and exclude every feature I am currently not working on.
//loading The get_objects function will mostly gather all relevant object numbers so they can later be loaded whenever they are needed. I am using an array to store them here, which is like a variable with many slots. I just called it "o" for object. Slot 0 (o[0]) will contain the object number of the attack that will first hit our character, slot 1 (o[1]) the closest opponent, slot 2 the second closest opponent and slot 3 the most desired item. The get_object function may eventually return more object numbers, but that's it for now. //reset The inputs function will simply reset all keys to stop the character from pressing them so he can perform new actions. //movement This section will decide on how the character will move, so it will only deal with how the directions keys will be pressed:
The last section will decide on how the character will act, that means defend, jump, attack and special moves:
As you can see I have not included teammates, criminals and commands yet. I do have the logic for criminals and commands already working, but I do not want to deal with testing in stage mode as long as the AI isn't good in vs mode and the commands cannot work perfectly with the current ddraw.dll yet - maybe they do, I have to try again. If you aren't interested in anything else the next post will feature the get_objects function. RE: writing basic AI - Alblaka - 08-19-2012 Important feature: Jan/John/Sorcerer actively seeking out and healing teammates with low hp, but sufficient dark hp. RE: writing basic AI - Boop - 08-19-2012 (08-19-2012, 03:34 PM)Alblaka Wrote: Important feature: Jan/John/Sorcerer actively seeking out and healing teammates with low hp, but sufficient dark hp. That is ID specific. Here is a picture of a duck in a cup: Spoiler (Click to View) RE: writing basic AI - YinYin - 08-19-2012 (08-19-2012, 03:34 PM)Alblaka Wrote: Important feature: Jan/John/Sorcerer actively seeking out and healing teammates with low hp, but sufficient dark hp.yes i am planning to include loading the teammate that requires healing most (or the group need in general) it can be used for healing moves later but as silva said this does not directly belong to writing a new basic ai i want to first use it to help out the weakest character or call the team together - i added it to the list @silva: please spoiler your cup duck thank you Moving on with the get_objects function, it will return an array of object numbers that we can later base all decisions on.
As usual with finding certain objects I have a for loop that goes through all 400 objects there are. Before that I create and fill the array that will be used to store the object numbers with -1 values, which will remain in case objects for a certain category are not found. In case the currently loaded number inside the loop belongs to an existing object that is on another team it is further checked whether it is a dangerous attack, an opponent or an item. //get attack that will hit first If the object will hit the character sooner than the previously loaded object its number will be written to o[0] (slot 0). This can be an attack, opponent or item. Anything really. //get closest opponent If the object is an opponent and closer than the previously loaded opponent (or the first opponent loaded) its number will be written to o[1] (slot 1). //get second closest opponent If the object is an opponent and not closer than the so far closest opponent but closer than the previously second closest one its number will be written to o[2]. (If I will ever load more opponents sorted by their distance I will try to combine these two into an internal for loop.) //get closest item Same as the two above except for items. I have yet to think up a way to rank items by more than just their distance (preferring a farther bottle over another weapon if it is needed). If you have a good script idea write it down. The conditions for the closest objects are a little long - maybe i can simplify them later. As you can see I have added an is_object(int i) function I will use for better readability inside the id function as well: updated id function (Click to View) RE: writing basic AI - YinYin - 08-21-2012 In this post I will show you all functions that are used inside the get_objects function as they are all pretty simple one liners.
The functions square_distance and is_attacking are quite simple. I will either post these two or the more complex hit_time function next. The previous get_objects function contained a logic error concerning items. Items can actually be on the same team as soon as they have been hit or picked up, thus items hit or thrown by the character were ignored until an opponent used them. As the other three conditions already contain team checks I just changed the != self.team to != self.num to simply omit the character itself instead of team objects: updated get_objects function (Click to View) RE: writing basic AI - YinYin - 08-25-2012
If that's not the case, in the last line I return true if the object is attacking. The easiest option is: return true if the target is on a different team and in state 3, the attacking state. But this will only recognize characters doing basic attacks because all projectiles use attacking states like 3000, 3005 and 3006. Also some character attacks use state 301. I did not want to check for all of these separately, so I simply checked whether the state begins with a 3. For that the code in between determines the length of the state and creates a 1 with trailing zeros to have the same amount of digits (1 for state 3, 100 for 301, 1000 for 3000/3001/etc). If dividing the target state by this number equals 3 then the state starts off with 3. There are also other attacking states such as the light and heavy throwing weapon states and the fire states 19 and 18 (I now notice I did not take into consideration that team mates with state 18 are attacking you too). Now this function is anything but perfect, because there was no way to truly check for itrs yet. Version 3.0 will allow me to simply check whether the target is on a different team and has a damaging itr in its current frame. That will be a lot simpler and much more efficient than this.
next: the hit time function and an updated is attacking function RE: writing basic AI - YinYin - 06-04-2013 It's been such a long time that I updated this that the is_attacking function has changed entirely from the actual update I wanted to post. So I will start off with the old hit_time function I wanted to post:
On to the new is_attacking function. This one has gotten a little ridiculous and even beyond the current dlls capabilities. But here it still is:
Then it checks whether the character itself has a bdy, is not blinking(invulnerable) and whether the given object has an itr. If that object has itrs that could hit our characters bdy it goes on to cycle through all of them to see if they are harmful and intersecting with a bdy. (yes this function will check whether it is technically already too late - but that's ok) The harmful check is by far the longest obviously. First of all there are several itr kinds that aren't harmful at all. The catching kind 1 inside walking frames is generally harmless. The picking kinds 2 and 7 are harmless. The super punch kind 6 is harmless. The healing kind 8 is harmless. The blocking kind 14 is harmless. And anything with effect 4 is also harmless. (maybe I should invert the kind part and only note down harmful kinds - but this way seemed better at first) Then there are of course some more delicate situations such as burning or thrown characters (where the team does not matter) or weapons (where the itr kind 5 is always present but only activated by the character). So I also check whether the object is either not on the same team, burning (state 18) or falling (state 12) and whether the object has a throwinjury attached (unkwn16[0]). So only burning objects, thrown falling characters or objects from another team are considered harmful. And last but not least: kind 5 itrs from weapons are only considered harmful if the holding characters (unkwn6) wpoint attacking is not 0. Yeah go figure that one line out. Once a harmful itr is found it is double checked with every bdy of our character via yet another 3 functions: intersect(rectangeA, rectangleB), sBdy_rect(bdy_number, self.frame_number) and tItr_rect(bdy_number, target.frame_number). The last two of those get an array of the bdy and itr coordinates and the first one checks whether they overlap (in all 3 dimensions). So this function truly checks whether an itr is about to hit or not. The problem currently is that multiple itrs or bdys with the same kind (mostly Henrys flute) will crash the game as they return the wrong kind after the first one. I will keep trying to fully rebuild basic AI but I am not sure whether I can keep track of it here the way I started it as I've only recently discovered the use of a lot of built in variables that can help making it less deterministic which I have yet to understand. However if you want to view the fully working basic AI I had done last year you can download LF 1over2 as the boss from stage 2 uses it. |