Maze generation

Scott Bolte scott at craycos.com
Mon Dec 17 05:14:59 AEST 1990


In article <1990Dec15.093542.2725 at pegasus.com> tleylan at pegasus.com (Tom Leylan) writes:
>		... I'm using Microsoft C and it returns a random
>value between 1 and 32767.  Does this appear to conflict with anything ?

	I do not see how that would cause a problem. Why don't you try
	the following unrolled code... It is not nearly as obscure as
	the original code, which several people have confirmed came
	from the obfuscated code contest.

#define	HALF_LINE	40
char           M[3], A, even, E = HALF_LINE, J[HALF_LINE], T[HALF_LINE];

main(argc,argv)
 char *argv[];
{
	int	lines;
	char	wall;

	srand(getpid());

	if( argc > 1)
		lines = atoi(argv[1]);
	else
		(void) scanf("%d" , &lines);

	A = 1;

	/*
	 * Top line
	 */
	for (*J = A ; --E; J[E] = T[E] = E)
		printf("._");

	while( 1) {
		/*
		 * even	toggles between 0 and 1.
		 */
		even = !even;
		A -= even;
		if ( A == 0 ){
			printf("\n|");
			A = HALF_LINE - 1 ;
			if( lines-- == 0)
				exit(0);
		}
		E = A[J - even];

		/*
		 * default settings.
		 */
		if( even )
			M[1] = '|';
		else
			M[0] = ' ';

		if( A != E ) {
			if( lines != 0)
				/*
				 * rule for the middle lines.
				 */
				wall = (0x30000000 < rand());
			else
				/*
				 * rule for the bottom line.
				 */
				wall = (A== T[A] | (0x30000000 < rand()))
				      || !even;

			if( wall ) {
				T[E]	= T[A];
				J[T[E]]	= E;
				T[A]	= A - even;
				J[T[A]]	= A;

				if( even )
					M[1] = '.';
				else
					M[0] = '_';
			}
		} else
			/*
			 * Very last printout.
			 */
			if ( !lines && !even )
				M[0] = '_';
		if( !even )
			printf(M);
	}
}

		Scott
-- 
___________________________________________________________________________
Scott Bolte                 scott at craycos.com               +1 719 540 4186
Cray Computer Corporation, 1110 Bayfield Drive, Colorado Springs, CO  80906



More information about the Alt.sources.d mailing list