Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
writing basic AI
#5
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.

    C-Code:
bool is_object(int i){
   return ( loadTarget(i) != -1 ) ? true : false;
}
This function loads the object slot i, and if the loadTarget function returns a real object type and not -1 it returns true as the slot i contains an object.

    C-Code:
bool is_opponent(int i){
   return ( loadTarget(i) == 0 && target.team != self.team ) ? true : false;
}
This function is very similar to is_object. It returns true if object number i contains a character (type 0) that is on another team.

    C-Code:
bool is_item(int i){
   return ( is_object(i) && ( target.state == 1004 || target.state == 2004 ) ) ? true : false;
}
Another simple function. If i contains an object that is inside a pickable state it returns true. This isn't perfect for the sake of selecting an item as falling items that are about to be pickable (but not yet) will be ignored until they stay still. I should probably rename this function into is_pickable.

    C-Code:
bool closer_than(int i, int j){
   return ( ( square_distance(self.num,i) < square_distance(self.num,j) && is_object(i) ) || !is_object(j) ) ? true : false;
}
This function simply compares the distance of object i to the character with the distance of j to the character. If i is closer or j does not exist it returns true.

    C-Code:
bool hits_sooner_than(int i, int j){
   return ( is_attacking(i) && hit_time(i) != -1 && ( hit_time(i) < hit_time(j) || hit_time(j) == -1 ) ) ? true : false;
}
Now things become a little more complex. This function compares the times it will take i and j to reach our character. If i is attacking and reaching the character sooner it will return true.


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)
Reply
Thanks given by: John Fighterli


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)