Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -23,7 +23,7 @@ proc m_maze pos . .
show_maze
d[] = [ 1 2 3 4 ]
for i = 4 downto 1
d = randint i
d = random i
dir = offs[d[d]]
d[d] = d[i]
if m[pos + dir] = 1 and m[pos + 2 * dir] = 1
@ -43,7 +43,7 @@ proc make_maze . .
m[n * i - n + 1] = 2
m[n * n - n + i] = 2
.
h = 2 * randint 15 - n + n * 2 * randint 15
h = 2 * random 15 - n + n * 2 * random 15
m_maze h
m[endpos] = 0
.
@ -68,7 +68,7 @@ proc solve dir0 pos . .
found = 1
return
.
of = randint 4 - 1
of = random 4 - 1
for h = 1 to 4
dir = (h + of) mod1 4
posn = pos + offs[dir]

View file

@ -0,0 +1,95 @@
Const MazeWidth = 11
Const MazeHeight = 9
Const MazeCell = 50
Dim Shared dstx As Integer = MazeWidth - 1
Dim Shared dsty As Integer = 0
Screenres MazeWidth * MazeCell, MazeHeight * MazeCell, 32
Windowtitle "Maze solving"
Sub Cell(Maze() As Integer, Byval x As Integer, Byval y As Integer, Byval w As Integer, Byval h As Integer, Byval s As Integer)
Dim As Integer i, p, q, r
Maze(x, y) Or= &H40
r = Rnd * 4
For i = r To r + 3
Select Case i Mod 4
Case 0: p = x - 1 : q = y
Case 1: p = x + 1 : q = y
Case 2: p = x : q = y - 1
Case 3: p = x : q = y + 1
End Select
If p >= 0 And p < w And q >= 0 And q < h And Maze(p, q) < &H40 Then
If p > x Then Maze(p, q) Or= 1 : Line (p * s, y * s + 4) - (p * s, (y + 1) * s - 4), Rgb(0, 0, 0)
If q > y Then Maze(p, q) Or= 2 : Line (x * s + 4, q * s) - ((x + 1) * s - 4, q * s), Rgb(0, 0, 0)
If x > p Then Maze(x, y) Or= 1 : Line (x * s, y * s + 4) - (x * s, (y + 1) * s - 4), Rgb(0, 0, 0)
If y > q Then Maze(x, y) Or= 2 : Line (x * s + 4, y * s) - ((x + 1) * s - 4, y * s), Rgb(0, 0, 0)
Cell Maze(), p, q, w, h, s
End If
Next
End Sub
Sub GenerateMaze(Maze() As Integer, Byval w As Integer, Byval h As Integer, Byval s As Integer)
Dim As Integer x, y
Redim Maze(w, h)
For y = 0 To h - 1
Line (0, y * s) - (w * s, y * s), Rgb(255, 255, 255)
Next
For x = 0 To w - 1
Line (x * s, 0) - (x * s, h * s), Rgb(255, 255, 255)
Next
Cell Maze(), Rnd * w, Rnd * h, w, h, s
End Sub
Sub SolveMaze(Path() As Integer, Maze() As Integer, Byval x As Integer, Byval y As Integer, Byval dstx As Integer, Byval dsty As Integer, Byval s As Integer)
Dim As Integer h, i, n, p, q, w
w = Ubound(Maze, 1)
h = Ubound(Maze, 2)
Redim Path(w * h, 1)
Maze(x, y) Or= &H80
Do
For i = 0 To 3
Select Case i
Case 0: p = x - 1 : q = y
Case 1: p = x + 1 : q = y
Case 2: p = x : q = y - 1
Case 3: p = x : q = y + 1
End Select
If p >= 0 And p < w And q >= 0 And q < h And Maze(p, q) < &H80 Then
If p > x And Maze(p, q) And 1 Then Exit For
If q > y And Maze(p, q) And 2 Then Exit For
If x > p And Maze(x, y) And 1 Then Exit For
If y > q And Maze(x, y) And 2 Then Exit For
End If
Next
If i < 4 Then
Maze(p, q) Or= &H80
Path(n, 0) = x
Path(n, 1) = y
Line ((x + 0.5) * s, (y + 0.5) * s) - ((p + 0.5) * s, (q + 0.5) * s), Rgb(255, 0, 0), , &b0001111111111100
n += 1
Else
If n > 0 Then
n -= 1
p = Path(n, 0)
q = Path(n, 1)
Line ((x + 0.5) * s, (y + 0.5) * s) - ((p + 0.5) * s, (q + 0.5) * s), Rgb(0, 0, 0)
End If
End If
x = p
y = q
Sleep 200
Loop Until x = dstx And y = dsty Or Inkey <> ""
Path(n, 0) = x
Path(n, 1) = y
End Sub
Dim Maze() As Integer
Dim Path() As Integer
Randomize Timer
GenerateMaze(Maze(), MazeWidth, MazeHeight, MazeCell)
SolveMaze(Path(), Maze(), 0, MazeHeight - 1, MazeWidth - 1, 0, MazeCell)
Windowtitle "Maze solving ** RESOLVED **"
Sleep