Data update
This commit is contained in:
parent
796d366b97
commit
35bcdeebf8
504 changed files with 7045 additions and 610 deletions
96
Task/Maze-generation/FutureBasic/maze-generation.basic
Normal file
96
Task/Maze-generation/FutureBasic/maze-generation.basic
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
_rows = 9
|
||||
_cols = 11
|
||||
_size = 32
|
||||
_mgn = 32
|
||||
|
||||
_t = ( 1 << 0 )
|
||||
_l = ( 1 << 1 )
|
||||
_b = ( 1 << 2 )
|
||||
_r = ( 1 << 3 )
|
||||
_a = _t + _l + _b + _r
|
||||
|
||||
_window = 1
|
||||
|
||||
void local fn BuildWindow
|
||||
window _window, @"FutureBasic - Maze generation", (0,0,_cols*_size+_mgn*2,_rows*_size+_mgn*2), NSWindowStyleMaskTitled
|
||||
end fn
|
||||
|
||||
|
||||
local fn CellAvailable( r as long, c as long ) as BOOL
|
||||
if ( r < 0 || c < 0 || r >= _rows || c >= _cols ) then exit fn
|
||||
if ( mda_integer(r,c) == _a ) then exit fn = YES
|
||||
end fn = NO
|
||||
|
||||
|
||||
void local fn ProcessCell( r as long, c as long )
|
||||
long r1 = r, c1 = c, d(3), count, dir, opp
|
||||
|
||||
while ( 1 )
|
||||
BlockZero( @d(0), sizeof(long) * 4 )
|
||||
count = 0
|
||||
if ( fn CellAvailable( r - 1, c ) ) then d(count) = _t : count++
|
||||
if ( fn CellAvailable( r, c - 1 ) ) then d(count) = _l : count++
|
||||
if ( fn CellAvailable( r + 1, c ) ) then d(count) = _b : count++
|
||||
if ( fn CellAvailable( r, c + 1 ) ) then d(count) = _r : count++
|
||||
if ( count == 0 ) then break
|
||||
|
||||
dir = d(rnd(count)-1)
|
||||
mda(r,c) = @(mda_integer(r,c) - dir)
|
||||
|
||||
select ( dir )
|
||||
case _t
|
||||
r1 = r-1 : opp = _b
|
||||
case _l
|
||||
c1 = c-1 : opp = _r
|
||||
case _b
|
||||
r1 = r+1 : opp = _t
|
||||
case _r
|
||||
c1 = c+1 : opp = _l
|
||||
end select
|
||||
|
||||
mda(r1,c1) = @(mda_integer(r1,c1) - opp)
|
||||
fn ProcessCell( r1, c1 )
|
||||
wend
|
||||
end fn
|
||||
|
||||
|
||||
void local fn DrawMaze
|
||||
long r, c, x = _mgn, y = _mgn, value
|
||||
|
||||
pen 2,, NSLineCapStyleRound
|
||||
|
||||
for r = 0 to _rows - 1
|
||||
for c = 0 to _cols - 1
|
||||
value = mda(r,c)
|
||||
if ( value & _t ) then line x, y to x + _size, y
|
||||
if ( value & _l ) then line x, y to x, y + _size
|
||||
if ( value & _b ) then line x, y + _size to x + _size, y + _size
|
||||
if ( value & _r ) then line x + _size, y to x + _size, y + _size
|
||||
x += _size
|
||||
next
|
||||
x = _mgn
|
||||
y += _size
|
||||
next
|
||||
end fn
|
||||
|
||||
|
||||
void local fn BuildMaze
|
||||
long r, c
|
||||
|
||||
for r = 0 to _rows - 1
|
||||
for c = 0 to _cols - 1
|
||||
mda(r,c) = _a
|
||||
next
|
||||
next
|
||||
|
||||
random
|
||||
r = rnd(_rows) - 1
|
||||
c = rnd(_cols) - 1
|
||||
fn ProcessCell( r, c )
|
||||
fn DrawMaze
|
||||
end fn
|
||||
|
||||
fn BuildWindow
|
||||
fn BuildMaze
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue