04-13-2024, 07:53 AM
I found a MazeGen program, written in QB64, and figured that you could probably adapt if for your purposes.
It produces a 40x40 maze (walls only - sorry...) and outputs to the screen for a few seconds then ends.
It should not be too difficult to modify the output to a file...
I know... It's rough... but, until an Editor magically pops up, it's all I could throw together. I hope it helps...
ps: I made a very-crude Editor, in another language that shall remain nameless, and could possibly be converted to N7... but do not get your hopes up... At the moment it has more bugs than a carcass...
I know... It is not very efficient, but it gets the job done... lol
J
It produces a 40x40 maze (walls only - sorry...) and outputs to the screen for a few seconds then ends.
It should not be too difficult to modify the output to a file...
I know... It's rough... but, until an Editor magically pops up, it's all I could throw together. I hope it helps...
ps: I made a very-crude Editor, in another language that shall remain nameless, and could possibly be converted to N7... but do not get your hopes up... At the moment it has more bugs than a carcass...
Code:
' Open a window and enable double buffering.
set window "MazeGen", 680, 680, false
set redraw off
randomize clock()
mWidth = 41
mHeight = 41
' Create array and fill
maze = dim(mWidth, mHeight)
for x = 0 to mWidth - 1
for y = 0 to mHeight - 1
maze[x][y] = "#"
next
next
' Initial start locations
currentX = rnd(0, mWidth - 1)
currentY = rnd(0, mHeight - 1)
' Values must be odd
if currentX % 2 = 0 currentX = currentX + 1
if currentY % 2 = 0 currentY = currentY + 1
maze[currentX][currentY] = " "
' Generate Maze
done = false
do
for i = 0 to 99
oldX = currentX
oldY = currentY
' Move in random directions
select case rnd(0, 3)
case 0
if currentX + 2 < mWidth currentX = currentX + 2
case 1
if currentY + 2 < mHeight currentY = currentY + 2
case 2
if currentX - 2 > 0 currentX = currentX - 2
case 3
if currentY - 2 > 0 currentY = currentY - 2
endsel
' If cell is unvisited then connect it
if maze[currentX][currentY] = "#"
maze[currentX][currentY] = " "
maze[int((currentX + oldX) / 2)][(currentY + oldY) / 2] = " "
endif
next
' Check if all cells are visited
done = true
for x = 1 to mWidth - 1 step 2
for y = 1 to mHeight - 1 step 2
if maze[x][y] = "#" done = false
next
next
until done = true
' Draw Maze
set color 255, 255, 255
for y = 0 to mHeight - 1
for x = 0 to mWidth - 1
set caret x * 16, y * 16
wln maze[x][y]
next
wln
next
redraw
wait 3000; end
I know... It is not very efficient, but it gets the job done... lol
J
Logic is the beginning of wisdom.