Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
writing basic AI
#1
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.
    C-Code:
void id(){
//loading
   array<int>o = get_objects();
//reset
   inputs();
//movement
   if( o[0] != -1 && attack_dodgeable(o) ) { dodge(o); }
   else if( armed(self.num) || closer_than(o[1],o[3]) ) { approach_opponent(o); }
   else if( !armed(self.num) && closer_than(o[3],o[1]) ) { approach_item(o); }
//action
   if( o[0]!=-1 && !attack_dodgeable(o) ){ react(o); }
   else{ act(o); }
}
As you can see I have divided the main function into four sections

//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:
  • If there is an attack (slot 0 is not -1) and it can be dodged the character will move to doge it. I'm giving the two new functions here the whole set of loaded object numbers instead of only the attacks object number so it is possible to prevent running from one danger into another.
  • If there was no attack to be dodged and the opponent is either closer than the item, or the character already holds an item he will approach his opponent.
  • If the item is closer than the opponent and the character is unarmed he will approach the item.
//action
The last section will decide on how the character will act, that means defend, jump, attack and special moves:
  • If there is an attack that was not dodgeable the character will react to it.
  • If there was no attack to react to the character will be able to act freely.

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.
Reply
Thanks given by: Silverthorn , mfc , John Fighterli , Marko


Messages In This Thread
writing basic AI - by YinYin - 08-19-2012, 12:19 PM
RE: writing basic AI - by Alblaka - 08-19-2012, 03:34 PM
RE: writing basic AI - by Boop - 08-19-2012, 04:08 PM
RE: writing basic AI - by YinYin - 08-19-2012, 09:29 PM
RE: writing basic AI - by YinYin - 08-21-2012, 03:39 PM
RE: writing basic AI - by YinYin - 08-25-2012, 07:38 AM
RE: writing basic AI - by YinYin - 06-04-2013, 07:40 PM



Users browsing this thread: 1 Guest(s)