n ander atomatise doolhof

Algemene discussies en vragen omtrent Liberty BASIC programma's. Stuur zoveel mogelijk delen van listings (snippets) in als je hulp wilt.

Moderators: anthonio, Abcott

n ander atomatise doolhof

Berichtdoor bluatigro » do nov 10, 2011 11:12 am

ik heb dit algoritme van de stanfort site

er zijn daar in het totaal 11 doolhoven te vinden
en diverse andere dingen

er zit een fout in deze vertaling
Code: Selecteer alles
global maxx , maxy
maxx = 10
maxy = 10
dim maze( maxx * 2 + 1 , maxy * 2 + 1 ) , ax( maxx * maxy ) , ay( maxx * maxy )
global muur , naast , gat
naast = 1
gat = 2
x = int( rnd( 0 ) * maxx )
y = int( rnd( 0 ) * maxy )
maze( x * 2 + 1 , y * 2 + 1 ) = gat
done = 0
while not( done )
  ''find al cels next to any empty one
  for i = 0 to maxx
    for j = 0 to maxy
      if i * 2 + 2 < maxx * 2 then
        if maze( i * 2 + 2 , j * 2 ) = muur then
          maze( i * 2 + 2 , j * 2 ) = naast
        end if
      end if
      if i * 2 - 2 > 0 then
        if maze( i * 2 - 2 , j * 2 ) = muur then
          maze( i * 2 - 2 , j * 2 ) = naast
        end if
      end if
      if j * 2 + 2 < maxy * 2 then
        if maze( i * 2 , j * 2 + 2 ) = muur then
          maze( i * 2 , j * 2 + 2 ) = naast
        end if
      end if
      if j * 2 - 2 > 0 then
        if maze( i * 2 , j * 2 - 2 ) = muur then
          maze( i * 2 , j * 2 - 2 ) = naast
        end if
      end if
    next j
  next i
  tel = 0
  ''find al coordinates of the fond next to empty cels
  for i = 0 to maxx
    for j = 0 to maxy
      if maze( i ^ 2 + 1 , j * 2 + 1 ) = naast then
        ax( tel ) = i
        ay( tel ) = j
        tel = tel + 1
      end if
    next j
  next i
  ''pic a next to empty cel at random
  dice = int( rnd( 0 ) * tel )
  x = ax( dice )
  y = ay( dice )
  tel = 0
  done2 = 0
  while not( done2 )
    ''pic a random cel next to the next to empty cel
    while abs( dx ) = abs( dy )
      dx = int( rnd( 0 ) * 2 - 1 )
      dy = int( rnd( 0 ) * 2 - 1 )
    wend
    ''look if this cel is empty
    if x + dx <= maxx _
    and x + dx >= 0 _
    and y + dy <= maxy _
    and y + dy >= 0 then
      if maze( x * 2 + 1 + dx * 2 , y * 2 + 1 + dx * 2 ) = gat then
      ''if this one is empty conect them
        maze( x * 2 + 1 + dx , y * 2 + 1 + dy ) = gat
        maze( x * 2 + 1 , y * 2 + 1 ) = gat
        done2 = not( 0 )
      end if
    end if
  wend
  done = not( 0 )
  ''look if there are any not empty cels
  for i = 0 to maxx - 1
    for j = 0 to maxy - 1
      if maze( i * 2 + 1 , j * 2 + 1 ) <> gat then done = 0
    next j
  next i
wend
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
nomainwin
open "maze" for graphics as #m
  #m "trapclose [quit]"
  for i = 0 to maxx * 2
    for j = 0 to maxy * 2
      q = maze( i , j )
      if q = muur then
        #m "goto " ; i * winx / maxx / 2 ; " " ; j * winy / maxy / 2
        #m "down"
        #m "boxfilled " ; (i+1)*winx/maxx/2 ;" "; (j+1)*winy/maxy/2
      end if
    next j
  next i
wait
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Keer terug naar Liberty BASIC Code

Wie is er online

Gebruikers op dit forum: Bing [Bot] en 1 gast

cron