Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
|
|
@ -1,56 +1,52 @@
|
|||
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%
|
||||
MODULE Maze {
|
||||
INTEGER W = 40, H = 20, X, Y, CX, CY, OX, OY, I
|
||||
BOOLEAN DONE
|
||||
DIM MAZE(0 TO W, 0 TO H) AS STRING
|
||||
FOR X = 0 TO W
|
||||
FOR Y = 0 TO H
|
||||
MAZE(X, Y) = "#"
|
||||
NEXT Y
|
||||
NEXT X
|
||||
|
||||
currentx% = INT(RND * (width% - 1))
|
||||
currenty% = INT(RND * (height% - 1))
|
||||
CX = RND * (W - 1)
|
||||
CY = RND * (H - 1)
|
||||
|
||||
IF currentx% MOD 2 = 0 THEN currentx%++
|
||||
IF currenty% MOD 2 = 0 THEN currenty%++
|
||||
maze$(currentx%, currenty%) = " "
|
||||
IF CX MOD 2 = 0 THEN CX++
|
||||
IF CY MOD 2 = 0 THEN CY++
|
||||
MAZE(CX, CY) = " "
|
||||
|
||||
done% = 0
|
||||
WHILE done% = 0 {
|
||||
FOR i% = 0 TO 99
|
||||
oldx% = currentx%
|
||||
oldy% = currenty%
|
||||
SELECT CASE INT(RND * 4)
|
||||
WHILE NOT DONE
|
||||
FOR I = 0 TO 99
|
||||
OX = CX
|
||||
OY = CY
|
||||
SELECT CASE RANDOM(0, 3)
|
||||
CASE 0
|
||||
IF currentx% + 2 < width% THEN currentx%+=2
|
||||
IF CX + 2 < W THEN CX+=2
|
||||
CASE 1
|
||||
IF currenty% + 2 < height% THEN currenty%+=2
|
||||
IF CY + 2 < H THEN CY+=2
|
||||
CASE 2
|
||||
IF currentx% - 2 > 0 THEN currentx%-=2
|
||||
IF CX - 2 > 0 THEN CX-=2
|
||||
CASE 3
|
||||
IF currenty% - 2 > 0 THEN currenty%-=2
|
||||
IF CY - 2 > 0 THEN CY-=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%
|
||||
}
|
||||
IF MAZE(CX, CY) = "#" THEN
|
||||
MAZE(CX, CY) = " "
|
||||
MAZE((CX + OX) DIV 2, (CY + OY) DIV 2) = " "
|
||||
END IF
|
||||
NEXT I
|
||||
DONE = TRUE
|
||||
FOR X = 1 TO W - 1 STEP 2
|
||||
FOR Y = 1 TO H - 1 STEP 2
|
||||
IF MAZE(X, Y) = "#" THEN DONE = FALSE
|
||||
NEXT Y
|
||||
NEXT X
|
||||
END WHILE
|
||||
|
||||
|
||||
FOR y% = 0 TO height%
|
||||
FOR x% = 0 TO width%
|
||||
PRINT maze$(x%, y%);
|
||||
NEXT x%
|
||||
FOR Y = 0 TO H
|
||||
FOR X = 0 TO W
|
||||
PRINT MAZE(X, Y);
|
||||
NEXT X
|
||||
PRINT
|
||||
NEXT y%
|
||||
NEXT Y
|
||||
}
|
||||
Maze
|
||||
|
|
|
|||
|
|
@ -1,43 +1,67 @@
|
|||
Module Maze2 {
|
||||
\\ depth-first search
|
||||
Profiler
|
||||
While Inkey$<>"" {} ' drop keys
|
||||
Const View as boolean=True
|
||||
Double tcc
|
||||
|
||||
Form 80,50
|
||||
let w=60, h=40
|
||||
again:
|
||||
Gradient 5,6
|
||||
Cursor 0,0
|
||||
let w=random(2,6)*10, h=random(1,4)*10, slice=w*h div 30
|
||||
let slice=if(slice=0->1, slice) : counter =1
|
||||
Double
|
||||
\\center proportional text double size
|
||||
Report 2, Format$("Maze {0}x{1}",w,h)
|
||||
Normal
|
||||
Hold
|
||||
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))
|
||||
stack new {
|
||||
Profiler
|
||||
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))
|
||||
end if
|
||||
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)
|
||||
if view then counter=if(counter=0->slice, counter-1) : if counter=0 then ShowMaze()
|
||||
else
|
||||
exit
|
||||
end if
|
||||
entry=forchoose
|
||||
Always
|
||||
if empty then exit
|
||||
Read entry
|
||||
Always
|
||||
tc= timecount/1000
|
||||
}
|
||||
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
|
||||
Cursor 0,Height-1
|
||||
Print Part $(6,width), ~(15,0,0),"Press a key or mouse button after any drawing of the maze to exit - "+format$("{0:3}",tc)
|
||||
Refresh
|
||||
counter=10
|
||||
every 200 {
|
||||
counter--
|
||||
if inkey$<>"" or mouse<>0 then counter=-1 : exit
|
||||
if counter<1 then exit
|
||||
}
|
||||
if counter=0 then Release : goto again
|
||||
End
|
||||
Sub NewForChoose(x,y)
|
||||
Local x1=x-2, x2=x+2, y1=y-2, y2=y+2, arr=(,)
|
||||
Stack New {
|
||||
|
|
@ -50,19 +74,21 @@ Module Maze2 {
|
|||
End Sub
|
||||
Sub OpenDoor(x1,y1, x2,y2)
|
||||
Local i
|
||||
if x1=x2 then {
|
||||
if x1=x2 then
|
||||
y1+=y2<=>y1
|
||||
for i=y1 to y2 {maze$(x1, i)=" " }
|
||||
} Else {
|
||||
for i=y1 to y2 step sgn(y2-y1) {maze$(x1, i)=" " }
|
||||
Else
|
||||
x1+=x2<=>x1
|
||||
for i=x1 to x2 {maze$(i, y1)=" "}
|
||||
}
|
||||
for i=x1 to x2 step sgn(x2-x1) {maze$(i, y1)=" "}
|
||||
End if
|
||||
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}
|
||||
Rem cls ,4 ' split screen - preserve lines form 0 to 3
|
||||
Release
|
||||
cursor 0,(height-h) div 2
|
||||
Local i, j, t=40-w div 2
|
||||
For j=1 to h+1 { Print @(t) : for i=1 to w+1 {Print maze$(i,j);}:Print}
|
||||
Print
|
||||
Refresh 100
|
||||
End Sub
|
||||
|
|
|
|||
29
Task/Maze-generation/PascalABC.NET/maze-generation.pas
Normal file
29
Task/Maze-generation/PascalABC.NET/maze-generation.pas
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
const
|
||||
w = 14;
|
||||
h = 10;
|
||||
|
||||
var
|
||||
vis := (0..h - 1).Select(x -> [false] * w).ToArray;
|
||||
hor := (0..h).select(x -> ['+---'] * w + [string('+')]).ToArray;
|
||||
ver := (0..h - 1).select(x -> ['| '] * w + [string('|')]).ToArray;
|
||||
|
||||
procedure walk(x, y: integer);
|
||||
begin
|
||||
vis[y][x] := true;
|
||||
foreach var p in ||x - 1, y|, |x, y + 1|, |x + 1, y|, |x, y - 1||.Shuffle do
|
||||
begin
|
||||
if (p[0] not in (0..w - 1)) or (p[1] not in (0..h - 1)) or vis[p[1]][p[0]] then continue;
|
||||
if p[0] = x then hor[max(y, p[1])][x] := '+ ';
|
||||
if p[1] = y then ver[y][max(x, p[0])] := ' ';
|
||||
walk(p[0], p[1]);
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
walk(random(w), random(h));
|
||||
foreach var (a, b) in hor.zip(ver + [''], (x, y) -> (x, y)) do
|
||||
begin
|
||||
a.println('');
|
||||
b.println('');
|
||||
end;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue