Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,56 @@
|
|||
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
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
Module Maze2 {
|
||||
\\ depth-first search
|
||||
Profiler
|
||||
Form 80,50
|
||||
let w=60, h=40
|
||||
Double
|
||||
\\center proportional text double size
|
||||
Report 2, Format$("Maze {0}x{1}",w,h)
|
||||
Normal
|
||||
Refresh
|
||||
Set Fast !
|
||||
Dim maze$(1 to w+1, 1 to h+1)="#"
|
||||
Include=Lambda w,h (a,b) ->a>=1 and a<=w and b>=1 and b<=h
|
||||
Flush ' empty stack
|
||||
if random(1,2)=1 then {
|
||||
entry=(if(random(1,2)=1->2, w),Random(1, h/2)*2)
|
||||
} else {
|
||||
entry=(random(1,w/2)*2,If(Random(1,2)=1->2,h))
|
||||
}
|
||||
maze$(entry#val(0), entry#val(1))=" "
|
||||
forchoose=(,)
|
||||
Push Entry
|
||||
do {
|
||||
do {
|
||||
NewForChoose(!entry)
|
||||
status=len(forchoose)
|
||||
if status>0 then {
|
||||
status--
|
||||
forchoose=forchoose#val(random(0,status))
|
||||
Push forchoose
|
||||
OpenDoor(!Entry, !forchoose)
|
||||
Rem : ShowMaze()
|
||||
} else exit
|
||||
entry=forchoose
|
||||
} Always
|
||||
if empty then exit
|
||||
Read entry
|
||||
} Always
|
||||
ShowMaze()
|
||||
Print timecount/1000
|
||||
Sub NewForChoose(x,y)
|
||||
Local x1=x-2, x2=x+2, y1=y-2, y2=y+2, arr=(,)
|
||||
Stack New {
|
||||
if include(x1,y) then if Maze$(x1,y)<>" " Then push (x1, y)
|
||||
if include(x2,y) then if Maze$(x2,y)<>" " Then push (x2, y)
|
||||
if include(x,y1) then if Maze$(x,y1)<>" " Then push (x, y1)
|
||||
if include(x,y2) then if Maze$(x,y2)<>" " Then push (x, y2)
|
||||
forchoose= Array([])
|
||||
}
|
||||
End Sub
|
||||
Sub OpenDoor(x1,y1, x2,y2)
|
||||
Local i
|
||||
if x1=x2 then {
|
||||
y1+=y2<=>y1
|
||||
for i=y1 to y2 {maze$(x1, i)=" " }
|
||||
} Else {
|
||||
x1+=x2<=>x1
|
||||
for i=x1 to x2 {maze$(i, y1)=" "}
|
||||
}
|
||||
End Sub
|
||||
Sub ShowMaze()
|
||||
Refresh 5000
|
||||
cls ,4 ' split screen - preserve lines form 0 to 3
|
||||
Local i, j
|
||||
For j=1 to h+1 { Print @(10) : for i=1 to w+1 {Print maze$(i,j);}:Print}
|
||||
Print
|
||||
Refresh 100
|
||||
End Sub
|
||||
}
|
||||
Maze2
|
||||
Loading…
Add table
Add a link
Reference in a new issue