Introduction: How to Make Maze Use C++

It's just a algorithm,the file is C++ algorithm source program not include MFC files but you should port it in the MFC of VS2010

Comments

author
gtoal made it!(author)2014-03-26

OK, here's a C program to create a maze:

http://www.gtoal.com/logoforum/maze.c.html

I didn't write the maze generation algorithm; I pinched it from
http://homepages.cwi.nl/~tromp/maze.html - and I take my hat off to
the crazy genius who wrote it. Non-recursive, top-to-bottom
generation. Wow.

Here's the underlying code...

char M[3],A,Z,E=40,J[40],T[40];main(C){for(*J=A=scanf("%d",&C);
-- E; J[ E] =T
[E ]= E) printf("._"); for(;(A-=Z=!Z) || (printf("\n|"
) , A = 39 ,C --
) ; Z || printf (M ))M[Z]=Z[A-(E =A[J-Z])&&!C
& A == T[ A]
|6<<27<rand()||!C&!Z?J[T[E]=T[A]]=E,J[T[A]=A-Z]=A,"_.":" |"];}

(It might look better at http://www.gtoal.com/logoforum/tromp.c.html )

Alternatively, try this:

#define P(X)j=write(1,X,1)
#define C 39
int M[5000]={2},*u=M,N[5000],R=22,a[4],l[]={0,-1,C-1,-1},m[]={1,-C,-1,C},*b=N,
*d=N,c,e,f,g,i,j,k,s;main(){for(M[i=C*R-1]=24;f|d>=b;){c=M[g=i];i=e;for(s=f=0;
s<4;s++)if((k=m[s]+g)>=0&&k<C*R&&l[s]!=k%C&&(!M[k]||!j&&c>=16!=M[k]>=16))a[f++
]=s;if(f){f=M[e=m[s=a[rand()/(1+2147483647/f)]]+g];j=j<f?f:j;f+=c&-16*!j;M[g]=
c|1<<s;M[*d++=e]=f|1<<(s+2)%4;}else e=d>b++?b[-1]:e;}P(" ");for(s=C;--s;P("_")
)P(" ");for(;P("\n"),R--;P("|"))for(e=C;e--;P("_ "+(*u++/8)%2))P("| "+(*u/4)%2
);}

(See http://www.gtoal.com/logoforum/shapiro.c.html )

About This Instructable

3,346views

13favorites

License:

More by 513696765:ESP8266(NodeMCU) Weather StationUes Python Code Monitoring the Global EarthquakeHow to Make Laser Projection Virtual Keyboard
Add instructable to: