Re: To: Evan Marshall (Maze Maker)
- Posted by Evan Marshall <evan at net-link.net> Jun 06, 2002
- 541 views
I'm glad you found it interesting. I was thinking about making a 3D maze and decided a 2D one would be easier to start with. I found an algorithm very similar to yours somewhere on the net (I can't remember where :( ) and decided to go for simplicity(?) over speed for the first draft. I plan on going back to increase the speed later, as right now I have more time to wait for a program to run than I do to develop it! I am also going to make the maze printable and am working on a print preview routine. (That should take me quite awhile!) Don Phillips wrote: > > Very interesting way to create a maze. I cant think of any reason to > need one at the moment, but I thought just for fun I would take a stab > at improving its speed. This is what I came up with. > > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- > > without warning > include Win32Lib.ew > > -- register controls with win32lib > constant > MainWin = create( Window, "Maze", NULL, 0.1, 0.1, 0.8, 0.8, 0 ), > Canvas = create( Window, "", MainWin, 0, 0, 1, 1, > {WS_CHILD,WS_VISIBLE,WS_DLGFRAME} ), > MaxXLbl = createEx( EditText, "", Canvas, 14, 7, 50, 15, > {WS_CHILD,WS_VISIBLE,WS_DISABLED}, {0} ), > MaxYLbl = createEx( EditText, "", Canvas, 74, 7, 50, 15, > {WS_CHILD,WS_VISIBLE,WS_DISABLED}, {0} ), > EditX = create( EditText, "20", Canvas, 10, 22, 50, 20, ES_NUMBER ), > EditY = create( EditText, "20", Canvas, 70, 22, 50, 20, ES_NUMBER ), > RunMaze = create( DefPushButton, "Make Maze", Canvas, 131, 18, 140, > 29, 0 ), > Status = create( ProgressBar, "", Canvas, 0, 0, 1, 1, 0 ) > > -- define variables > integer RoomsX > integer RoomsY > integer UsedRooms > sequence Grid > sequence Path > sequence Slice > sequence NewPos > sequence Mask Mask = { 0, 1, 0, 2, 0, 3, 0, 4, 0} > sequence Move Move = { {0,-1}, {-1,0}, {1,0}, {0,1} } > > -- remove a wall in specified direction > procedure RemoveWall( integer Direction ) > if Direction = 1 then > drawLine( MainWin, (NewPos[1]-1)*10+1, (NewPos[2]-1)*10, > (NewPos[1]-1)*10+10, (NewPos[2]-1)*10 ) > elsif Direction = 2 then > drawLine( MainWin, (NewPos[1]-1)*10, (NewPos[2]-1)*10+1, > (NewPos[1]-1)*10, (NewPos[2]-1)*10+10 ) > elsif Direction = 3 then > drawLine( MainWin, (NewPos[1]-1)*10+10, (NewPos[2]-1)*10+1, > (NewPos[1]-1)*10+10, (NewPos[2]-1)*10+10 ) > else > drawLine( MainWin, (NewPos[1]-1)*10+1, (NewPos[2]-1)*10+10, > (NewPos[1]-1)*10+10, (NewPos[2]-1)*10+10 ) > end if > end procedure > > -- make the maze > function makeMaze() > integer PosX > integer PosY > integer Direction > integer NewMove > integer Index > sequence Size > > -- clear screen > repaintWindow( MainWin ) > > -- get size of grid > Size = value( getText(EditX) ) > if Size[1] = GET_SUCCESS then > RoomsX = Size[ 2 ] > else > return( -1 ) > end if > > Size = value( getText(EditY) ) > if Size[1] = GET_SUCCESS then > RoomsY = Size[ 2 ] > else > return( -1 ) > end if > > -- enforce maximums > Size = getClientRect( MainWin ) > if RoomsX > floor((Size[3] - 20) / 10) then > setText( EditX, sprintf( "%d", {floor((Size[3] - 20) / 10)} )) > RoomsX = floor((Size[3] - 20) / 10) > end if > if RoomsY > floor((Size[4] - 80) / 10) then > RoomsY = floor((Size[4] - 80) / 10) > setText( EditY, sprintf( "%d", {floor((Size[4] - 80) / 10)} )) > end if > > -- set status indicator range to maximum > UsedRooms = 0 > setScrollRange( Status, 0, RoomsX * RoomsY ) > > -- initialize grid > Grid = {} > Grid &= { repeat( 0, RoomsX+2 ) } > Grid &= repeat( 0 & repeat( 1, RoomsX ) & 0, RoomsY ) > Grid &= { repeat( 0, RoomsX+2 ) } <snip> > > >