Smud
Member
Thanks to these guys - http://people.uncw.edu/tagliarinig/...ce, Neill, and Nobles/The Amazing Maze(1).pdf
was able to decipher an interpretation of the sidewinder algorithm;
anybody else tried a different maze algorithm? This one has an interesting name (how could you not have a go at that?) but others might be more useful for keeping kids small and big amused.
was able to decipher an interpretation of the sidewinder algorithm;
Code:
/* --------------------------------------------------------------------
An interpretation of the Sidewinder algorithm for maze generation.
-------------------------------------------------------------------- */
/* -------------------------------------------------------------------
1. Initial settings
-------------------------------------------------------------------- */
DEFINE VARIABLE lv-Width AS INTEGER NO-UNDO INITIAL 25.
DEFINE VARIABLE lv-Height AS INTEGER NO-UNDO INITIAL 15.
DEFINE VARIABLE lv-Weight AS DECIMAL NO-UNDO INITIAL 0.5.
DEFINE VARIABLE lv-Seed AS INTEGER NO-UNDO INITIAL 5.
DEFINE VARIABLE lv-i AS INTEGER NO-UNDO.
DEFINE VARIABLE lv-x AS INTEGER NO-UNDO.
DEFINE VARIABLE lv-y AS INTEGER NO-UNDO.
DEFINE VARIABLE lv-runstart AS INTEGER NO-UNDO.
DEFINE VARIABLE lv-runstop AS INTEGER NO-UNDO.
DEFINE VARIABLE lv-cell AS INTEGER NO-UNDO.
DEFINE VARIABLE lv-oddy AS LOGICAL NO-UNDO.
DEFINE VARIABLE lv-oddx AS LOGICAL NO-UNDO.
DEFINE VARIABLE lv-test AS LOGICAL NO-UNDO.
/* pseudo seed by altering the start random */
DO lv-i = 1 TO lv-Seed:
lv-x = RANDOM(0,lv-Weight).
END.
/* --------------------------------------------------------------------
2. Setup Grid
-------------------------------------------------------------------- */
DEFINE VARIABLE lv-Grid AS CHARACTER NO-UNDO FORMAT "x(1)" EXTENT 4096. /* max (2 * height + 1) * (2 * width + 1) */
/* inialise grid */
DO lv-y = 1 TO (lv-Height * 2 + 1):
DO lv-x = 1 TO (lv-Width * 2 + 1):
lv-i = lv-x + (lv-y - 1) * (2 * lv-Width + 1).
lv-oddy = (INTEGER(lv-y / 2) * 2 <> lv-y).
lv-oddx = (INTEGER(lv-x / 2) * 2 <> lv-x).
IF lv-oddy THEN DO:
IF lv-oddx THEN DO:
lv-Grid[lv-i] = "+".
END.
ELSE DO:
lv-Grid[lv-i] = "-".
END.
END.
ELSE DO:
IF lv-oddx THEN DO:
lv-Grid[lv-i] = "|".
END.
ELSE DO:
lv-Grid[lv-i] = " ".
END.
END.
END.
END.
/* --------------------------------------------------------------------
3. Sidewinders Pseudocode
First row;
Remove east wall
For second row to the last row:
Set the start-passage to 1
For each column:
Randomly set a boolean
If boolean equals true:
Set a random cell from start-passage to current cell
Remove north wall of chosen cell
Set the start-passage to the chosen cell + 1
Else if not the last column:
Remove east wall of cell
-------------------------------------------------------------------- */
lv-y = 1.
DO lv-x = 1 TO lv-Width - 1:
lv-i = (lv-y * 2 - 1) * (2 * lv-Width + 1) + (lv-x * 2).
lv-grid[lv-i + 1] = " ". /* punch a hole east */
END.
DO lv-y = 2 TO lv-Height:
lv-runstart = 1.
DO lv-x = 1 TO lv-Width:
lv-i = (lv-y * 2 - 1) * (2 * lv-Width + 1) + (lv-x * 2).
lv-test = (RANDOM(0,lv-weight) = 0).
IF lv-test THEN DO:
lv-runstop = (IF (lv-x - lv-runstart) > 0 THEN RANDOM(0,lv-x - lv-runstart) ELSE 0).
lv-cell = lv-runstart + (IF lv-runstop > 0 THEN RANDOM(0,lv-runstop) ELSE 0).
lv-grid[(lv-cell * 2) + ((lv-y - 1) * 2) * (2 * lv-Width + 1)] = " ". /* puch a hole north */
lv-runstart = lv-cell + 1.
END.
ELSE DO:
IF lv-x < lv-width THEN lv-grid[lv-i + 1] = " ". /* punch a hole east */
END.
END.
END.
/*--------------------------------------------------------------------
4. Output ASCII row by row
-------------------------------------------------------------------- */
OUTPUT TO c:\temp\maze.txt.
DO lv-y = 1 TO (lv-Height * 2 + 1):
DO lv-x = 1 TO (lv-Width * 2 + 1):
lv-i = lv-x + (lv-y - 1) * (2 * lv-Width + 1).
PUT lv-Grid[lv-i].
END.
PUT SKIP.
END.
anybody else tried a different maze algorithm? This one has an interesting name (how could you not have a go at that?) but others might be more useful for keeping kids small and big amused.
Code:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ + + +-+ + +-+ +-+-+ + +-+ +-+-+ +-+ +-+-+ +-+ +-+
| | | | | | | | | | | | | | |
+ + + +-+ + +-+ +-+ +-+-+ +-+-+ + + +-+ +-+-+-+-+-+
| | | | | | | | | | | | |
+ + +-+-+-+ + +-+-+-+-+-+ + + + +-+ + + + + + + +-+
| | | | | | | | | | | | | | | |
+ + + + +-+ + +-+ + + + + +-+-+-+-+ + +-+-+-+-+ +-+
| | | | | | | | | | | | | | |
+ + + + + +-+-+ + + +-+ +-+-+-+ +-+ + +-+-+ +-+-+-+
| | | | | | | | | | | | | | |
+ + + + + + +-+-+ + +-+ +-+-+ +-+-+-+-+ +-+-+ +-+ +
| | | | | | | | | | | | | |
+ +-+ + +-+ + + +-+ +-+-+-+-+ + + +-+-+ + +-+-+ +-+
| | | | | | | | | | | | | |
+ + + +-+-+-+-+-+ + + + +-+-+ + +-+-+ + + + +-+-+-+
| | | | | | | | | | | | | | |
+ + + + + + +-+-+-+-+ + + +-+ +-+ +-+-+ +-+-+-+-+-+
| | | | | | | | | | | | |
+ + + + + + + + + +-+-+-+ + + + +-+ + +-+ +-+-+-+-+
| | | | | | | | | | | | | | | | |
+ + + + +-+ + + + + + +-+-+ +-+ +-+ + + + + + +-+-+
| | | | | | | | | | | | | | | | | | |
+ +-+ + +-+ +-+ +-+ + +-+-+-+-+-+ + + + +-+-+-+-+-+
| | | | | | | | | | | | |
+ + + + + + +-+ +-+-+-+ +-+ +-+-+-+-+-+ + +-+-+-+-+
| | | | | | | | | | | | |
+ + + +-+ + +-+ +-+-+ + +-+ + +-+-+-+ + + +-+ + + +
| | | | | | | | | | | | | | | | |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+