AI Tutorial
Making the Bot Think Faster

 

     The Reaper reacts quickly. The FrogBot reacts quickly. But the Tutor Bot, he's a bit slow in the head.
     I always wondered how most bot, ranging from the Omicron to the CTF Bots, thought so darn fast. Once I even started a new bot from scratch just to try to build him to think faster.
     About a year and 500 lines of programming later, I discovered that all I needed to make the bot react more swiftly was one line of code.
     Yeah, I know, life is cruel.
     The least I can do now is show you that magic line of code. In fact, here it is now:


	self.nextthink = time + 0.05;

     You see, monsters and some bots think every 0.1 seconds, or every tenth of a second. In other words, they think ten times a second.
     This is acceptable, of course. But perhaps you want your Tutor Bot to kick a little more butt.
     This 0.1 seconds is most always regulated in the bot's animation sequences. But we can override this.
     We can just paste the above line of code into both bot_walk(), his navigation routine, and bot_strafe(), his evasion routine.
     For instance, here is what we do with bot_walk():

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void() bot_walk =
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
	
	self.nextthink = time + 0.05;

// this is his main AI routine, where he will look for items and enemies

	if (!(self.flags & FL_ONGROUND))
		return;

	bot_look_for_bots();
	bot_look_for_players();
	bot_search_for_items();
	bot_grab_items();

     You can't get any simpler than one line of code.
     What that new line will do is to force the bot to think every 0.05 seconds, which is twice as fast as he normally thinks. He'll really move and groove now.
     A few notes. One, don't forget to add that line to bot_strafe() as well, at the beginning.
     Secondly, 0.05 is very fast, and he may look jerky. If you don't like this, try changing it to 0.08 or 0.7. Have some fun.
     Lastly, I choose these two routines because he thinks them during each frame. If you selected a different subroutine to put this new line into that he didn't think each frame, he would obviously not see it and therefore not set his nextthink to 0.05.
     Time to compile. The Tutor Bot will really scoot now.
 


What We Learned

1. Normal animation sequences happen every 0.1 seconds
2. We can override that if we find a routine he calls every frame
3. Sometimes big problems have small solutions
3. Put another way, never overthink AI
 


     Author: Coffee
     Questions: coffee@planetquake.com
     AI chat on ICQ: 2716002