Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A* Algorithim and Path Finding

Status
Not open for further replies.

vcherubini

Programmer
May 29, 2000
527
US
Hello:

I am fairly new to C++, so please bear with me.

For school, I am working on a science fair project that tests which language is better for artificial intelligence. Since modern games are the biggest users of AI, I figured that I should investigate that area (plus I get to play a lot of cool games).

I was reading a copy of Game Developer a couple of month's ago and it said that the algorithim most used in pathfinding in games is called the A* algorithim. Has anyone heard of this?

Second, what do you recommend as the language for simple pathfinding. I am not writing a program like Unreal or something like that, just something that can find a path and avoid obstacles.

I have checked gamedev.net and found nothing on the A* algorithim, although many good articles on path finding, but most of them are too complicated for me, right now.

Finally, if anyone has heard of this algorithim (A*), can you point me in the direction (prefereably the website) of where I can find the source code or pieces or the logic behind the A* algorithim.


Thanks a lot to whoever can help,

-Vic

vic cherubini
malice365@hotmail.com
====

Knows: Perl, HTML, JavScript, C/C++, PHP, Flash, Director

Wants to Know: Java, Cold Fusion, Tcl/TK

====
 
Here are some Path Examples out of the C++ Help File:

/* getcwd example */

#include <stdio.h>
#include <dir.h>

int main(void)
{
char buffer[MAXPATH];

getcwd(buffer, MAXPATH);
printf(&quot;The current directory is: %s\n&quot;, buffer);
return 0;
}

*********************************

/* _fullpath example */

#include <stdio.h>
#include <stdlib.h>

char buf[_MAX_PATH];

void main(int argc, char *argv[])
{
for ( ; argc; argv++, argc--)
{
if (_fullpath(buf, argv[0], _MAX_PATH) == NULL)
printf(&quot;Unable to obtain full path of %s\n&quot;,argv[0]);
else
printf(&quot;Full path of %s is %s\n&quot;,argv[0],buf);
}
}

**********************************

/* _getdcwd example */

#include <direct.h>
#include <stdio.h>

char buf[65];

void main()
{
if (_getdcwd(3, buf, sizeof(buf)) == NULL)
perror(&quot;Unable to get current directory of drive C&quot;);
else
printf(&quot;Current directory of drive C is %s\n&quot;,buf);
}

***********************************

/* getcurdir example */

#include <dir.h>
#include <stdio.h>
#include <string.h>

char *current_directory(char *path)
{
strcpy(path, &quot;X:\\&quot;); /* fill string with form of response: X:\ */
path[0] = 'A' + getdisk(); /* replace X with current drive letter */
getcurdir(0, path+3); /* fill rest of string with current directory */
return(path);
}

int main(void)
{
char curdir[MAXPATH];

current_directory(curdir);
printf(&quot;The current directory is %s\n&quot;, curdir);


return 0;
}

**********************************

/* getdisk example */

#include <stdio.h>
#include <dir.h>

int main(void)
{
int disk, maxdrives = setdisk(2);
disk = getdisk() + 'A';
printf(&quot;\nThe number of logical drives is:%d\n&quot;, maxdrives);
printf(&quot;The current drive is: %c\n&quot;, disk);
return 0;
}

***********************************

/* fnsplit example */

#include <stdlib.h>
#include <stdio.h>
#include <dir.h>

int main(void)
{
char *s;
char drive[MAXDRIVE];
char dir[MAXDIR];
char file[MAXFILE];
char ext[MAXEXT];
int flags;

s=getenv(&quot;COMSPEC&quot;); /* get the comspec environment parameter */
flags=fnsplit(s,drive,dir,file,ext);

printf(&quot;Command processor info:\n&quot;);
if(flags &amp; DRIVE)
printf(&quot;\tdrive: %s\n&quot;,drive);
if(flags &amp; DIRECTORY)
printf(&quot;\tdirectory: %s\n&quot;,dir);

if(flags &amp; FILENAME)
printf(&quot;\tfile: %s\n&quot;,file);
if(flags &amp; EXTENSION)
printf(&quot;\textension: %s\n&quot;,ext);

return 0;
}

***********************************

/* fnmerge example */

#include <string.h>
#include <stdio.h>
#include <dir.h>

int main(void)
{
char s[MAXPATH];
char drive[MAXDRIVE];
char dir[MAXDIR];
char file[MAXFILE];
char ext[MAXEXT];

getcwd(s,MAXPATH); /* get the current working directory */
strcat(s,&quot;\\&quot;); /* append on a trailing character */
fnsplit(s,drive,dir,file,ext); /* split the string to separate elems */
strcpy(file,&quot;DATA&quot;);
strcpy(ext,&quot;.TXT&quot;);
fnmerge(s,drive,dir,file,ext); /* merge everything into one string */

puts(s); /* display resulting string */

return 0;
}

Hope it helps you.
Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top