Maze Automata

Post Reply
User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Maze Automata

Post by Mr. Kibernetik »

I took maze algorithm from this forum thread and adapted it to smart BASIC.
It is a growing labyrinth:

Code: Select all

'Maze Automata
'mod by Mr.K
is=5! bs=10
xs=int(screen_width()/bs)
ys=int(screen_height()/bs)
dim p(xs,ys)
graphics
shadow on

FOR x=xs/2-is TO xs/2+is
  FOR y=ys/2-is TO ys/2+is
    p(x,y)=rnd(2)
    NEXT y
  NEXT x

loop:change=0
FOR x=1 TO xs-2
  FOR y=1 TO ys-2
    n=p(x-1,y-1) + p(x,y-1) + p(x+1,y-1) + p(x-1,y) + p(x+1,y) + p(x-1,y+1) + p(x,y+1) + p(x+1,y+1)
    IF p(x,y)=1 AND (n<1 OR n>4) THEN
      p(x,y)=0
      change=1
      continue y
    END IF
    IF p(x,y)=0 AND n=3 THEN
      p(x,y)=1
      change=1
    END IF
    NEXT y
  NEXT x

graphics lock
graphics clear
for x=1 to xs-2
  for y=1 to ys-2
    x1=x*bs! y1=y*bs! x2=x1+bs! y2=y1+bs
    if p(x,y) then fill rect x1,y1 to x2,y2
    next y
  next x
graphics unlock

IF change THEN loop
Image

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: Maze Automata

Post by Henko »

Interesting forum! A lot of "smart" guys there. All kinds of Basic interpeters/(semi)compilers on Windows/Linux platforms. iOS platform is a niche there.

Post Reply