RosettaCodeData/Task/Maze-generation/M2000-Interpreter/maze-generation-1.m2000
2023-07-01 13:44:08 -04:00

56 lines
1.6 KiB
Text

Module Maze {
width% = 40
height% = 20
\\ we can use DIM maze$(0 to width%,0 to height%)="#"
\\ so we can delete the two For loops
DIM maze$(0 to width%,0 to height%)
FOR x% = 0 TO width%
FOR y% = 0 TO height%
maze$(x%, y%) = "#"
NEXT y%
NEXT x%
currentx% = INT(RND * (width% - 1))
currenty% = INT(RND * (height% - 1))
IF currentx% MOD 2 = 0 THEN currentx%++
IF currenty% MOD 2 = 0 THEN currenty%++
maze$(currentx%, currenty%) = " "
done% = 0
WHILE done% = 0 {
FOR i% = 0 TO 99
oldx% = currentx%
oldy% = currenty%
SELECT CASE INT(RND * 4)
CASE 0
IF currentx% + 2 < width% THEN currentx%+=2
CASE 1
IF currenty% + 2 < height% THEN currenty%+=2
CASE 2
IF currentx% - 2 > 0 THEN currentx%-=2
CASE 3
IF currenty% - 2 > 0 THEN currenty%-=2
END SELECT
IF maze$(currentx%, currenty%) = "#" Then {
maze$(currentx%, currenty%) = " "
maze$(INT((currentx% + oldx%) / 2), ((currenty% + oldy%) / 2)) = " "
}
NEXT i%
done% = 1
FOR x% = 1 TO width% - 1 STEP 2
FOR y% = 1 TO height% - 1 STEP 2
IF maze$(x%, y%) = "#" THEN done% = 0
NEXT y%
NEXT x%
}
FOR y% = 0 TO height%
FOR x% = 0 TO width%
PRINT maze$(x%, y%);
NEXT x%
PRINT
NEXT y%
}
Maze