I just show it interestingly. in order to build a key-gate system into the maze, I need to know the path of passage because of the arrangement of the gates. I experimented in 2d to understand and see.

`RANDOMIZE TIMER`

maze_x = 140 'maze size X

maze_y = 40 'maze size Y

'preparation -------------------------------------------------------------------------------------------------------------------------------------------

IF maze_x / 2 = INT(maze_x / 2) THEN maze_x = maze_x + 1

IF maze_y / 2 = INT(maze_y / 2) THEN maze_y = maze_y + 1

monx = (maze_x + 10) * 8: mony = (maze_y + 5) * 16: kep = _NEWIMAGE(monx, mony, 32): SCREEN kep: _SCREENMOVE 0, 0

d(0, 0) = 0: d(0, 1) = -1: d(1, 0) = 0: d(1, 1) = 1: d(2, 0) = -1: d(2, 1) = 0: d(3, 0) = 1: d(3, 1) = 0

k$(0) = "±" 'fal / adjustable wall

k$(1) = " " 'nem bejart ureg / non walked road

k$(2) = "W" 'lehetoseg / possible way

k$(3) = "Ű" 'szilard fal / standard wall

k$(4) = "." 'bejart ureg / walked road

k$(5) = "." 'belepesi pont / entry point

DIM maze(maze_x - 1, maze_y - 1) AS _BYTE '0-fal 1-ureg 2-lehetoseg

'create empty maze --------------------------------------------------------------------------------------------------------------------------------------

FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: k = 0

IF tx = 0 OR ty = 0 OR tx = maze_x - 1 OR ty = maze_y - 1 THEN k = 3

IF tx AND 1 AND ty AND 1 THEN k = 1

maze(tx, ty) = k: NEXT ty, tx

'start position -----------------------------------------------------------------------------------------------------------------------------------------

DO: sx = INT(maze_x * RND(1)): sy = INT(maze_y * RND(1)): LOOP WHILE maze(sx, sy) <> 1: maze(sx, sy) = 4

'way searching ------------------------------------------------------------------------------------------------------------------------------------------

DO: REDIM way(9999, 2): wdb = 0

FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1

IF maze(tx, ty) = 4 THEN

van = 0

FOR t = 0 TO 3

vpx1 = tx + d(t, 0): vpy1 = ty + d(t, 1): vpx2 = tx + d(t, 0) * 2: vpy2 = ty + d(t, 1) * 2

f = (vpx2 > maze_x - 1 OR vpx2 < 0) OR (vpy2 > maze_y - 1 OR vpy2 < 0)

IF NOT f THEN

IF maze(vpx1, vpy1) = 0 AND maze(vpx2, vpy2) = 1 THEN

FOR t2 = 0 TO 3: vpx3 = vpx2 + d(t2, 0): vpy3 = vpy2 + d(t2, 1): IF maze(vpx3, vpy3) = 4 THEN GOTO kovi

NEXT t2

maze(vpx1, vpy1) = 2: way(wdb, 0) = tx: way(wdb, 1) = ty: way(wdb, 2) = t: wdb = wdb + 1

kovi:

END IF

END IF

NEXT t

END IF

NEXT ty, tx

IF wdb THEN

aw = INT(wdb * RND(1))

FOR t = 0 TO 2

hovax = way(aw, 0) + d(way(aw, 2), 0) * t: hovay = way(aw, 1) + d(way(aw, 2), 1) * t

IF (maze(hovax, hovay) = 2) OR (maze(hovax, hovay) = 1) THEN maze(hovax, hovay) = 4

NEXT t

FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: IF maze(tx, ty) = 2 THEN maze(tx, ty) = 0

NEXT ty, tx

END IF

LOOP WHILE wdb

'entry point 1

sx = 0: sy = 3: IF maze(sx + 1, sy) <> 4 THEN sy = sy + 1

maze(sx, sy) = 4: start_x = sx: start_y = sy

'entry point 2

sx = maze_x - 1: sy = maze_y - 3: IF maze(sx - 1, sy) <> 4 THEN sy = sy - 1

maze(sx, sy) = 4

exit_x = sx: exit_y = sy

' it has taken so far to build the maze. contained in the maze array ------------------------------------------------------------------------------------------------

FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1

IF maze(tx, ty) <> 4 THEN maze(tx, ty) = 0

NEXT ty, tx

'drawing

sy = INT((mony / 16 - maze_y) / 2) + 1: sx = INT((monx / 8 - maze_x) / 2) + 1

FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: LOCATE sy + ty, sx + tx: PRINT k$(maze(tx, ty)): NEXT ty, tx

DIM dj1(tx - 1, ty - 1), dj2(tx - 1, ty - 1): dj1(start_x, start_y) = 1

FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: sum_way = sum_way + ABS(maze(tx, ty) = 4): NEXT ty, tx

actual = 1

DO:

FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1

IF maze(tx, ty) = 4 AND dj1(tx, ty) = 0 THEN

FOR t = 0 TO 3

noway = 0

IF tx + d(t, 0) < 0 OR tx + d(t, 0) > maze_x - 1 THEN noway = 1

IF ty + d(t, 1) < 0 OR ty + d(t, 1) > maze_y - 1 THEN noway = 1

IF noway = 0 THEN

nei = dj1(tx + d(t, 0), ty + d(t, 1))

hel = maze(tx + d(t, 0), ty + d(t, 1))

IF nei = actual AND hel = 4 THEN dj1(tx, ty) = actual + 1: find_way = find_way + 1

END IF

NEXT t

END IF

NEXT ty, tx

actual = actual + 1

sy = INT((mony / 16 - maze_y) / 2) + 1: sx = INT((monx / 8 - maze_x) / 2) + 1

FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: LOCATE sy + ty, sx + tx: PRINT k$(maze(tx, ty)): NEXT ty, tx

sy = INT((mony / 16 - maze_y) / 2) + 1: sx = INT((monx / 8 - maze_x) / 2) + 1

FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: LOCATE sy + ty, sx + tx

ert = dj1(tx, ty)

' IF ert > 0 THEN PRINT CHR$(97 + ert)

NEXT ty, tx

LOCATE 1, 1: PRINT find_way, sum_way

LOOP UNTIL find_way = sum_way - 1

'atlagolas

ave = 1

FOR tx = 0 TO maze_x - 1: FOR ty = 0 TO maze_y - 1: sum = 0: c = 0

FOR q0 = -ave TO ave: FOR q1 = -ave TO ave

IF tx + q0 < 0 OR tx + q0 > maze_x - 1 OR ty + q1 < 0 OR ty + q1 > maze_y - 1 THEN _CONTINUE

IF maze(tx + q0, ty + q1) = 4 THEN c = c + 1: sum = sum + dj1(tx + q0, ty + q1)

NEXT q1, q0

dj2(tx, ty) = sum / c

NEXT ty, tx

'celrajz

actx = exit_x: acty = exit_y

DO

LOCATE sy + acty, sx + actx: PRINT "Ű"

max = 999999

FOR t = 0 TO 3

IF actx + d(t, 0) < 0 OR actx + d(t, 0) > maze_x - 1 OR acty + d(t, 1) < 0 OR acty + d(t, 1) > maze_y - 1 THEN _CONTINUE

IF dj2(actx + d(t, 0), acty + d(t, 1)) < max AND maze(actx + d(t, 0), acty + d(t, 1)) = 4 THEN max = dj2(actx + d(t, 0), acty + d(t, 1)): need = t

NEXT t

actx = actx + d(need, 0): acty = acty + d(need, 1)

LOOP UNTIL start_x = actx AND start_y = acty