Advertisement

AI Pathfinding Beginner Questions!!!

Started by August 27, 2001 08:24 PM
2 comments, last by Brackus 23 years, 2 months ago
Okay, I have tried variations of questions on these boards for over a year now, and I have not had much success, mainly because of the lack of information I give, and that I already know... Okay, I like working in Turing just because its an old school language and when you run you can go right into graphics mode. So I can run AI tests right away... Okay, now in Turing, I have learned to take the coords of a player controlled player, and run them down with a cpu player, but i just took the position of both, and moved up down, left right, or diagonally towards them at all times. But in a maze, you dont know where the goal, or enemy is, or at least you shouldnt, so I can learn much more in this type of environment. But a major problem halts my learning, I still dont know how to make the cpu or human players obey the rules of walls. Like, to make a visual maze I just make a large red square, and write little blue squares represent walls. With each square being 10x10 pixels, and the players/circles being 10 in diameter. So they only move ten to each side or forward/back. Now I have this test set up that the player cannot move ouside the maze, but I am so dumb that I cannot make the player not move through the walls, how do I do this??? Or is there a better way. The only way my limited brain can think of is to have about 120 set numbers (for a 10x10 square maze) or coords, and then test the space the player wants to move, and if its one of the 48 restricted spaces, then test another spot, but this would suck, and would mess up my theory of a mouse in a maze, where I make each square the mouse has been have a +1 value, so it goes to the lowest possible spot (making sure it retraces steps as little as possible) and if 2 the same, randomly pick one... This is a lot for one post, and Im sure most people dont have time to read this, but it really bugs me that I cant learn AI (if you can even call finding an opponent of object semi smartly AI, but I will still refer to it as such...) because I dont have the proper stuff to test it with... Dustin
Mess With the Best, go down like the rest, but please visit:http://members.tripod.com/nu_bgameprogramming/
Ok, for setting up a map I create an array to place each of the tiles in. In this way I can tell any player where they are on the map based on their tile coordinate.

As you know an array is linear but you are working with 2D space so you have to make a simple conversion from the map''s tile coordinates to the array''s linear coordinate. If you want to get tile (5, 3) on a 10x10 map then you would get the array tile by multiplying the Y value (3) by the total tile width of the map (10) then add the X value (5).

(5, 3) in 2D space is equal to 35 in the linear space.

I use the base map array to draw the map as well. I just shift threw the tiles (assuming you are always drawing whole tiles, partial tiles is a little more complex) and draw them to the screen. That should help you test your AI out some.
Advertisement
Your method would work, but Invader''s would be faster. Basically his idea is to use a hash table, where a given maze coordinate corresponds to a certain byte, which is either 1 or 0. I admittedly don''t know anything about Turing, but you should be able to do that. There are two general ways. You could have an array of pointers to arrays, (which would be a two-dimensional array), or you could have a one-dimensional array, and access the linear coordinate in a manner like this: lincoord = x + y * mapwidth . You could also use bitpacking, if you wanted to, where each bit represents a maze "cell." It''s a little harder, but it saves a lot of memory. Here''s an example:

  protected:	unsigned int map_width;	unsigned int map_height;	unsigned char * map;	inline void putmap(unsigned int x, unsigned int y, bool value)	{		if(x < map_width && y < map_height)		{			unsigned long lincoord = x + y * map_width;			unsigned long lincoorddiv8 = lincoord / 8;			if(value == true)				map[lincoorddiv8] = map[lincoorddiv8] | (1 << (lincoord % 8));			else				map[lincoorddiv8] = ~((~map[lincoorddiv8]) | (1 << (lincoord % 8)));		}	}public:	inline bool getmap(unsigned int x, unsigned int y)	{		if(x < map_width && y < map_height)		{			unsigned long lincoord = x + y * map_width;			if( (map[lincoord >> 3] >> (lincoord % 8)) & 1 == 1)				return true;			else				return false;		}		else			return false;	}//...  


Note that the map array I have a pointer to is allocated in the following manner:

  map = new unsigned char[(map_width * map_height) / 8];  
quote: Original post by Brackus
Okay, I have tried variations of questions on these boards for over a year now, and I have not had much success, mainly because of the lack of information I give, and that I already know...

Okay, I like working in Turing just because its an old school language and when you run you can go right into graphics mode. So I can run AI tests right away...



Nothing wrong with that. I often recommend Quake or one of the other FPS games as ideal platforms for testing and building game AIs quickly, since the developers (usually newbies) won''t have to mess with graphics, buttons, controls, or any of the dross that gets in the way of good game AI.

quote:

Okay, now in Turing, I have learned to take the coords of a player controlled player, and run them down with a cpu player, but i just took the position of both, and moved up down, left right, or diagonally towards them at all times. But in a maze, you dont know where the goal, or enemy is, or at least you shouldnt, so I can learn much more in this type of environment. But a major problem halts my learning, I still dont know how to make the cpu or human players obey the rules of walls. Like, to make a visual maze I just make a large red square, and write little blue squares represent walls. With each square being 10x10 pixels, and the players/circles being 10 in diameter. So they only move ten to each side or forward/back. Now I have this test set up that the player cannot move ouside the maze, but I am so dumb that I cannot make the player not move through the walls, how do I do this???



Not in any way to detract from the conversation--there have been some good solutions discussed in this thread--but isn''t this really more a collision detection problem? You''re trying to avoid walking through walls the way I read the post, so that should just be a matter of testing for the intersection of the player/CPU and a wall edge, right?

Mind you, moving through the maze smart is an AI problem so this is definitely a combination of the two (in fact, I''ve worked projects where collision detection was considered part of the AI). I like the has solution proposed by TerranFury, though it might break down with large maps (though you''ll have that problem with nearly any map storage solution).






Ferretman

ferretman@gameai.com
www.gameai.com

From the High Mountains of Colorado

Ferretman
ferretman@gameai.com
From the High Mountains of Colorado
GameAI.Com

This topic is closed to new replies.

Advertisement