[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference noted::hackers_v1

Title:-={ H A C K E R S }=-
Notice:Write locked - see NOTED::HACKERS
Moderator:DIEHRD::MORRIS
Created:Thu Feb 20 1986
Last Modified:Mon Aug 03 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:680
Total number of notes:5456

677.0. "Pathfinder Algorithm" by FOO::BHAVNANI (Must be the compiler...) Thu Jan 28 1988 20:18

	Hi,

	Can anyone refer me to an algorithm that draws a random path
	from A[1,1] to A[NROWS,NCOLS] of a matrix A[NROWS][NCOLS], a
	"path"  being  defined  as  the locus of a point moving from
	one  point  to  another  adjacent point (the usual meaning)?
	Unfortunately, non-recursive algorithms like

		do
		{
		  generate new adjacent location;
		  if (new location is within matrix boundary and not
		      already marked)
		     mark path
	          fi
		}
		while (new location <> A[NROWS][NCOLS])

	take a long time to execute (sometimes infinity) for matrices
	in the order of 20x30.  Also, algorithms that force brute-force
	advancement towards the goal produce predictable straight-line
	or diagonal paths.

	Tnx for your I/O.
	/ravi
T.RTitleUserPersonal
Name
DateLines
677.1Off the top of my head.SNDCSL::SMITHWilliam P.N. (WOOKIE::) SmithFri Jan 29 1988 09:247
    Just skew the random algorythm so that you will 'tend' towards your
    goal (pick one of 5 movements from your current position randomly,
    up/down/left/right/towards_the_goal), or alternate between random
    and goal_seeking.
    
    Willie
    
677.2Already didFOO::BHAVNANIMust be the compiler...Sat Jan 30 1988 00:242
	I already tried that - it produces very predictable paths.
	/ravi
677.3SNDCSL::SMITHWilliam P.N. (WOOKIE::) SmithSat Jan 30 1988 09:3122
    Exactly how did you do it, and how often do you use the goal_seeking
    algorythm?  Try something like:
    
    	Choose goal_seeking algorythm 1/10 of the time.  Not every 10th
    time, but randomly 1/10th of the time.  ie:
    
    Pick random integer between 1 and 10.
    	If (number is 1) then
    		{	use goal_seeking algorythm.	}
    	Else
    		{	use random path algorythm.	}
    
    
    You probably want to play with the numbers some (pick goal_seeking
    one percent of the time?) or do some other things (choose north/south/
    east/west/continue_in_previous_direction/use_goal_seeking/use_goal_
    avoidance/turn_left/turn_right) in various randomly chosen
    combinations.
    What are you using for your random number generator?
    
    Willie
    
677.4ZZZZ::MORONEY-- swapped out --Sat Jan 30 1988 14:345
You may want to try a maze-generating algorithm, then "solve" the maze, and
that's your path.  There are mazes that will have only one path between any 2
points in the maze, that may be the type you'd want.

-Mike
677.5PLDVAX::ZARLENGALost the will to compromiseSun Jan 31 1988 13:4915
.4>You may want to try a maze-generating algorithm, then "solve" the maze, and
.4>that's your path.
    
    	Beat me to it!  That's what I was just going to suggest.
    
    	These kind of maze generators are simple and relatively fast
    if coded properly. I wrote one in C for a PC version of MONSTA
    that made the maze (22*66) in a hair over 1 second.
    
    	As an aside, it appears the method mentioned by WOOKIE::SMITH
    should not be predictable. If your goal position is fixed, double
    check your code.
    
    -mike z