[futurebasic] Re: [FB] aMAZEing

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : October 2001 : Group Archive : Group : All Groups

From: Jay Reeve <jktr@...>
Date: Mon, 29 Oct 01 21:57:06 -0600
>I'm sure that someone has seen the Maze screensaver. It draws a varied (very
>complex) maze on the screen and then proceeds to solve it by trial and
>error, marking the live paths in one color and the dead paths in another.
>
>I was wondering if anyone knew where to find the algorithm for this type of
>thing. I suppose source code would be a lesser alternative but I would
>really hope for a document that explains it. Can anyone help?
>
Charlie,

I've not seen it, but I wrote a program that does about what you describe 
back in my Commodore-64 days. It doesn't amount to much more than a grid 
of cells, with data for each cell indicating in which direction(s) motion 
is allowed. Another array records the sequence of creation, to allow 
backtracking.

Here is some pseudocode that represents my best recollection of how I did 
it.

local fn markCell(cell)
fn AddCellToSequenceArray(cell)
FN CheckForExitCell(cell)
fn RecordAndDrawPathFromPrevCellToCurrCell
gOpenCellCount --
end fn

local fn CreateMaze
fn markAllEdgeCells
firstCell = fn randomEdgeCell
currCell = firstCell
do
while FN countOpenAdjacentCells(currCell) = 0
currCell = fn previousCell(currCell)
wend
direction = rnd(FN countOpenAdjacentCells(currCell))
currCell = fn adjacentCell(direction)
fn markCell(currCell)
until gOpenCellCount = 0
end fn

Running the completed maze is very similar:
Choose from available directions at random.
Keep track of what paths you've already tried.
When you hit a dead end, backtrack until you get to a path you haven't 
tried yet.

Have fun,
 0"0
 =J= a  y
  "