Maze generation: Difference between revisions

→‎{{header|PureBasic}}: changed some code constants
(→‎{{header|D}}: Not a dept first search)
(→‎{{header|PureBasic}}: changed some code constants)
Line 707:
=={{header|PureBasic}}==
<lang PureBasic>Enumeration
;indexes for types of offsets from maze coordinates (x,y)
#visited ;used to index visited(x,y) in a given direction from current maze cell
#visited
#maze ;used to index maze() in a given direction from current maze cell
#maze
#wall ;used to index walls in maze() in a given direction from current maze cell
#wall
#numOffsets = #wall
;direction indexes
#dir_ID = 0 ;identity value, produces no changes
#dir_N = 0
#firstDir
#dir_N = 0#firstDir
#dir_E
#dir_S
#dir_W
#numDirs = #dir_W
#dir_ID ;identity value, produces no changes
#dirMax
EndEnumeration
 
DataSection
;maze(x,y) offsets for visited, maze, & walls for each direction
Data.i 1, 1, 0, 0, 0, 0 ;ID
Data.i 1, 0, 0, -1, 0, 0 ;N
Data.i 2, 1, 1, 0, 1, 0 ;E
Data.i 1, 2, 0, 1, 0, 1 ;S
Data.i 0, 1, -1, 0, 0, 0 ;W
Data.i 1%00, 1%01, %10, 0%01, %10 0;wall values for ID, 0N, 0E, ;IDS, W
Data.i %01, %10, %01, %10, %00 ;wall values for N, E, S, W, ID
EndDataSection
 
;setup reference values indexed by direction from current map cell
Global Dim offset.POINT(2#numOffsets, #dirMaxnumDirs)
Define i, j
For i = #dir_N0 To #dir_IDnumDirs
For j = 0 To 2#numOffsets
Read.i offset(j, i)\x: Read.i offset(j, i)\y
Next
Next
 
Global Dim wallvalue(#dirMaxnumDirs)
For i = #dir_N0 To #dir_IDnumDirs: Read.i wallvalue(i): Next
 
Procedure displayMaze(Array maze(2))
Line 776 ⟶ 778:
NewList stack.POINT()
Dim unvisited(#dirMaxnumDirs - 1#firstDir)
Repeat
cellCount = 0
For i = #dir_NfirstDir To #dir_WnumDirs
If Not visited(x + offset(#visited, i)\x, y + offset(#visited, i)\y)
unvisited(cellCount) = i: cellCount + 1
Line 814 ⟶ 816:
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
CloseConsole()
EndIf</lang>
</lang>
Sample output:
<pre>Started generation at 9 x 3
Anonymous user