Page 1 of 1

Programming AI

Posted: Sun Apr 01, 2007 8:35 pm
by roxaz
This might be very useful for you :)

Link removed by moderator

examples from the book (sources abd binaries):
www.wordware.com/files/ai




**Moderator Edit**
Unless you have permission from Wordware Publishing, Inc you can't distribute the entire book.

Posted: Sun Apr 01, 2007 10:36 pm
by franklyn
isnt that illegal ?

Posted: Mon Apr 02, 2007 5:23 am
by jam
A few sample chapters are available over on the author's website.

http://www.ai-junkie.com/books/toc_pgaibe.html

Posted: Mon Apr 02, 2007 8:55 am
by roxaz
i just wanted to help :roll:

Posted: Mon Apr 02, 2007 7:58 pm
by franklyn
hehe. well we definitely appreciate it.
are you working on ai atm ?

Posted: Tue Jun 26, 2007 11:21 am
by dejai
Hmm, where could I "purchase" this novel...

JJ But really were is or what is this thread about??

Posted: Tue Jun 26, 2007 11:15 pm
by Dances
dejai wrote:Hmm, where could I "purchase" this novel...

JJ But really were is or what is this thread about??
You can buy it with the link in the first post. Its right at the bottom of the page.

Posted: Fri Jun 29, 2007 4:41 pm
by Frodenius
hey roxaz if you wouldnt mind you could knowingly commit a crime and pm me your link, im a poor student and interested in ai game programming... i could eventually accept this crucial lapse with a heavy heart.. ;)

Posted: Fri Jun 29, 2007 5:24 pm
by BlindSide
You don't need the book Frodenius. Come on AI is just common sense in my opinion. Besides there are millions of articles for you on gamedev.net about A*, etc etc.

Posted: Fri Jun 29, 2007 6:41 pm
by Dances
Yes there are even A* libraries such as this one http://www.grinninglizard.com/MicroPather/index.htm to help you along as well.

AI is really a bunch of decision making if statements.

For example if you want a monster that runs at your character and explodes your AI is something like this:

Code: Select all

if(monster->isAlive())
   if(moster->canSeePlayer())
   {
      if(player->getPosition.X() < monster->getPosition.X())
         monster->moveXNegative();
     else
        monster->moveXPositive();
     if(player->getPosition.Z() < monster->getPosition.Z())
         monster->moveZNegative();
     else
        monster->moveZPositive();
     if(monster->getPosition.X() - player->getPosition.X() < 10 || 
          monster->getPosition.X() - player->getPosition.X()  > -10)
          if(monster->getPosition.Z() - player->getPosition.Z() < 10 || 
             monster->getPosition.Z() - player->getPosition.Z()  > -10)
             if(monster->getPosition.Y() - player->getPosition.Y() < 10 || 
                monster->getPosition.Y() - player->getPosition.Y()  > -10)
                monster->explode();
   }
Its simple, like writing out a thought process.

Posted: Sun Jul 01, 2007 6:50 pm
by Katsankat
The word terrorist would fit well, instead of monster.

Posted: Thu Aug 30, 2007 7:25 pm
by arras
I would recommend you to leave it monster ...else somebody may come with idea of spreading war against terrorism to your code. You dont want to se Toronto be bombed by F15s and Tomahawks, do you? :wink:

Posted: Tue Nov 13, 2007 8:44 am
by kornwaretm
sorry i'm indonesian
this code rotate each actor to face their closest target, but stil got some trouble, may be because i haven't read all about matrixes

Code: Select all

void runAi(actor* head){		
			float jarak,dX,dZ,sudutTarget,sudutSekarang;
			core::vector3df pos1,pos2,rot;
			int attack;
			float tambahan;	
			bool attackAble =false ;

			if(Live>0){
				if((target==NULL)||(target->Live<1)){
					pickTarget(head);
					resetControl();
					//printf("id : %d cari musuh %d\n",id,&target);
				}else{
					pos1	= node->getPosition();
					pos2	= target->node->getPosition();
					dX		= pos2.X-pos1.X;
					dZ		= pos2.Z-pos1.Z;
					if(pos2.Z>pos1.Z){
						dZ	*= -1;
						dX	*= -1;
						tambahan = 180;
					}else{
						tambahan = 0;
					}
					jarak			= sqrt(dX*dX+dZ*dZ);					
					rot				= node->getRotation();
					sudutSekarang	= rot.Y;
					sudutTarget		= atan(dX/dZ);
					sudutTarget		= sudutTarget*180/3.14;	
					
					if(sudutSekarang+10 < sudutTarget+tambahan){
						input->turn = 3;
						attackAble=false;
					}else if(sudutSekarang-10 > sudutTarget+tambahan){
						input->turn = -3;
						attackAble=false;
					}else{
						attackAble=true;

					}

					if(jarak>20){
						input->accelerate=2;
					}else if((jarak<=20)&&(jarak>10)){
						input->accelerate = 1;					
					}else{
						input->accelerate=0;
						if(attackAble){
							input->turn = 0;
							if(target->Live>0){
								input->speedAttack = true;							
							}else{
								input->speedAttack = false;								
							}
						}
					}
				}
			}
		}
i assume even if the ai to control the it self it throug a class thal i call the input class.