Blitz Basic was created by Mark Sibley, originally for the Amiga Computers.  In 2000, a version was made for Windows PC.  Later, 3D commands were added to the language, creating Blitz3D.  In 2003, a new version called Blitz Plus was created. It only had 2d rendering, but included GUI commands and render engines that would allow programs to run on older systems. 


Creating the maze generator for Blitz3D was a bit of a challenge.  Blitz3D lacks anything like a true list or stack.  There is one list in which all objects are automatically added to.  Making a stack with the built in list would be difficult as there was no way to distinguish cells added from the grid and those "pushed" onto the list as part of the recursive-backtracking algorithm.  Eventually, I chose to box the cells in a separate object and then I could filter out for those.


This code was tested on Blitz3D v 1.108 and Blitz Plus v 1.47

maze.bb


;Holds information for each cell
Type TCell
	Field row, column
	Field north, south, east, west
	Field visited
End Type

;Used to 'box' a cell to create a type of stack
Type Tbox
	Field cell.TCell
End Type

;input maze dimentions
Global width = 20
Global height = 15

Dim Maze.TCell(height,width)
Dim Directions(4)

;This function takes a cell and returns all possible directions
Function getDirections(cell.TCell)
	top = 0
	If cell\row > 0
		If Maze(cell\row-1,cell\column)\visited = False
			directions(top) = 0
			top = top+1
		EndIf
	EndIf
	If cell\column < width-1
		If Maze(cell\row,cell\column+1)\visited = False
			directions(top) = 1
			top = top+1
		EndIf
	EndIf
	If cell\row < height-1
		If Maze(cell\row+1,cell\column)\visited = False
			directions(top) = 2
			top = top + 1
		EndIf
	EndIf
	If cell\column > 0
		If Maze(cell\row,cell\column-1)\visited = False
			directions(top) = 3
			top = top + 1
		EndIf
	EndIf
	Return top
End Function

;initialize the maze grid
For row = 0 To height-1
	For column = 0 To width-1
		Maze(row,column) = New TCell
		Maze(row,column)\row = row
		Maze(row,column)\column = column
	Next
Next

;pick the first cell at random
SeedRnd(MilliSecs())
row = Rand(0,height-1)
column = Rand(0,width-1)
cell.TCell = Maze(row,column)
;set it to visited and add to the stack
cell\visited = True
box.TBox = New TBox
box\cell = cell

;repeat until there are no more cells on the stack
currentBox.TBox = Last TBox
While currentBox <> Null
	cell = currentBox\cell
	count = getDirections(cell)
	If count > 0
		box.TBox = New TBox
		direction = directions(Rand(0,count-1))
		Select direction
		Case 0
			cell\north = True
			box\cell = Maze(cell\row-1,cell\column)
			box\cell\south = True
			box\cell\visited = True
		Case 1
			cell\east = True
			box\cell = Maze(cell\row,cell\column+1)
			box\cell\west = True
			box\cell\visited = True
		Case 2
			cell\south = True
			box\cell = Maze(cell\row+1,cell\column)
			box\cell\north = True
			box\cell\visited = True
		Case 3
			cell\west = True
			box\cell = Maze(cell\row,cell\column-1)
			box\cell\east = True
			box\cell\visited = True
		End Select
		currentBox = box
	Else
		Delete currentBox
		currentBox = Last TBox
	EndIf
Wend

Graphics 800,600
SetBuffer BackBuffer()
lineWidth = 800/width
lineHeight = 600/height
For row = 0 To height-1
	For column = 0 To width-1
		cell.TCell = Maze(row,column)
		If cell\north = False 
			Line column*lineWidth,row*LineHeight,(column+1)*lineWidth,row*LineHeight
		EndIf
		If cell\east = False
			Line (column+1)*linewidth-1,row*lineHeight,(column+1)*lineWidth-1,(row+1)*lineHeight
		EndIf
		If cell\south = False
			Line column*lineWidth,(row+1)*lineHeight-1,(column+1)*lineWidth,(row+1)*lineHeight-1
		EndIf
		If cell\west = False
			Line column*lineWidth,row*lineHeight,column*lineWidth,(row+1)*lineHeight
		EndIf
	Next
Next
Flip

WaitKey()