Basic Computer Games - Small Basic Edition: Amazing

Small BasicSmall Basic BooksBasic Computer Games Small Basic Edition** **> Amazing

This program will print out a different maze every time it is run and guarantees only one path through. You can choose the dimensions of the maze - i.e., the number of squares wide and long.

The original program author was Jack Hauber of Windsor, Connecticut.

Code Listing (Small Basic File: amazing.sb):

TextWindow.CursorLeft = 28
TextWindow.WriteLine("AMAZING PROGRAM")
TextWindow.CursorLeft = 15
TextWindow.WriteLine("BIBLEBYTE BOOKS, 
MAPLE VALLEY, WASHINGTON")
TextWindow.WriteLine("")
TextWindow.WriteLine("")
TextWindow.WriteLine("")
TextWindow.WriteLine("")
LN100:
TextWindow.Write("WHAT IS YOUR WIDTH? ")
H = TextWindow.ReadNumber()
TextWindow.Write("WHAT IS YOUR LENGTH? ")
V = TextWindow.ReadNumber()
If H<>1 AND V<>1 Then 
  Goto LN110
EndIf
TextWindow.WriteLine("MEANINGLESS DIMENSIONS. 
TRY AGAIN.")
Goto LN100
LN110:
For I=1 To H
  For j=1 To V
    WArray[I][J] = 0
    VArray[I][J] = 0
  EndFor
EndFor
TextWindow.WriteLine("")
TextWindow.WriteLine("")
TextWindow.WriteLine("")
TextWindow.WriteLine("")
Q=0
Z=0
X=Math.Floor(Math.GetRandomNumber(999)/1000*H+1)
For I=1 To H
If I=X Then 
  Goto LN173
EndIf
TextWindow.Write(".--")
Goto LN180
LN173:
TextWindow.Write(".  ")
LN180:
EndFor
TextWindow.WriteLine(".")
C=1
WArray[X][1]=C
C=C+1
R=X
S=1
Goto LN260
LN210:
If R<>H Then 
  Goto LN240
EndIf
If S<>V Then 
  Goto LN230
EndIf
R=1
S=1
Goto LN250
LN230:
R=1
S=S+1
Goto LN250
LN240:
R=R+1
LN250:
If WArray[R][S]=0 Then 
  Goto LN210
EndIf
LN260:
If R-1=0 Then 
  Goto LN530
EndIf
If WArray[R-1][S]<>0 Then 
  Goto LN530
EndIf
If S-1=0 Then 
  Goto LN390
EndIf
If WArray[R][S-1]<>0 Then 
  Goto LN390
EndIf
If R=H Then 
  Goto LN330
EndIf
If WArray[R+1][S]<>0 Then 
  Goto LN330
EndIf
X=Math.Floor(Math.GetRandomNumber(999)/1000*3+1)
If (X = 1) Then
  Goto LN790
ElseIf (X = 2) Then
  Goto LN820
ElseIf (X = 3) Then
  Goto LN860
EndIf
LN330:
If S<>V Then 
  Goto LN340
EndIf
If Z=1 Then 
  Goto LN370
EndIf
Q=1
Goto LN350
LN340:
If WArray[R][S+1]<>0 Then 
  Goto LN370
EndIf
LN350:
X=Math.Floor(Math.GetRandomNumber(999)/1000*3+1)
If (X = 1) Then
  Goto LN790
ElseIf (X = 2) Then
  Goto LN820
ElseIf (X = 3) Then
  Goto LN910
EndIf
LN370:
X=Math.Floor(Math.GetRandomNumber(999)/1000*2+1)
If (X = 1) Then
  Goto LN790
ElseIf (X = 2) Then
  Goto LN820
EndIf
LN390:
If R=H Then 
  Goto LN470
EndIf
If WArray[R+1][S]<>0 Then 
  Goto LN470
EndIf
If S<>V Then 
  Goto LN420
EndIf
If Z=1 Then 
  Goto LN450
EndIf
Q=1
Goto LN430
LN420:
If WArray[R][S+1]<>0 Then 
  Goto LN450
EndIf
LN430:
X=Math.Floor(Math.GetRandomNumber(999)/1000*3+1)
If (X = 1) Then
  Goto LN790
ElseIf (X = 2) Then
  Goto LN860
ElseIf (X = 3) Then
  Goto LN910
EndIf
LN450:
X=Math.Floor(Math.GetRandomNumber(999)/1000*2+1)
If (X = 1) Then
  Goto LN790
ElseIf (X = 2) Then
  Goto LN860
EndIf
LN470:
If S<>V Then 
  Goto LN490
EndIf
If Z=1 Then 
  Goto LN520
EndIf
Q=1
Goto LN500
LN490:
If WArray[R][S+1]<>0 Then 
  Goto LN520
EndIf
LN500:
X=Math.Floor(Math.GetRandomNumber(999)/1000*2+1)
If (X = 1) Then
  Goto LN790
ElseIf (X = 2) Then
  Goto LN910
EndIf
LN520:
Goto LN790
LN530:
If S-1=0 Then 
  Goto LN670
EndIf
If WArray[R][S-1]<>0 Then 
  Goto LN670
EndIf
If R=H Then 
  Goto LN610
EndIf
If WArray[R+1][S]<>0 Then 
  Goto LN610
EndIf
If S<>V Then 
  Goto LN560
EndIf
If Z=1 Then 
  Goto LN590
EndIf
Q=1
Goto LN570
LN560:
If WArray[R][S+1]<>0 Then 
  Goto LN590
EndIf
LN570:
X=Math.Floor(Math.GetRandomNumber(999)/1000*3+1)
If (X = 1) Then
  Goto LN820
ElseIf (X = 2) Then
  Goto LN860
ElseIf (X = 3) Then
  Goto LN910
EndIf
LN590:
X=Math.Floor(Math.GetRandomNumber(999)/1000*2+1)
If (X = 1) Then
  Goto LN820
ElseIf (X = 2) Then
  Goto LN860
EndIf
LN610:
If S<>V Then 
  Goto LN630
EndIf
If Z=1 Then 
  Goto LN660
EndIf
Q=1
Goto LN640
LN630:
If WArray[R][S+1]<>0 Then 
  Goto LN660
EndIf
LN640:
X=Math.Floor(Math.GetRandomNumber(999)/1000*2+1)
If (X = 1) Then
  Goto LN820
ElseIf (X = 2) Then
  Goto LN910
EndIf
LN660:
Goto LN820
LN670:
If R=H Then 
  Goto LN740
EndIf
If WArray[R+1][S]<>0 Then 
  Goto LN740
EndIf
If S<>V Then 
  Goto LN700
EndIf
If Z=1 Then 
  Goto LN730
EndIf
Q=1
Goto LN830
LN700:
If WArray[R][S+1]<>0 Then 
  Goto LN730
EndIf
X=Math.Floor(Math.GetRandomNumber(999)/1000*2+1)
If (X = 1) Then
  Goto LN860
ElseIf (X = 2) Then
  Goto LN910
EndIf
LN730:
Goto LN860
LN740:
If S<>V Then 
  Goto LN760
EndIf
If Z=1 Then 
  Goto LN780
EndIf
Q=1
Goto LN770
LN760:
If WArray[R][S+1]<>0 Then 
  Goto LN780
EndIf
LN770:
Goto LN910
LN780:
Goto LN1000
LN790:
WArray[R-1][S]=C
C=C+1
VArray[R-1][S]=2
R=R-1
If C=H*V+1 Then 
  Goto LN1010
EndIf
Q=0
Goto LN260
LN820:
WArray[R][S-1]=C
LN830:
C=C+1
VArray[R][S-1]=1
S=S-1
If C=H*V+1 Then 
  Goto LN1010
EndIf
Q=0
Goto LN260
LN860:
WArray[R+1][S]=C
C=C+1
If VArray[R][S]=0 Then 
  Goto LN880
EndIf
VArray[R][S]=3
Goto LN890
LN880:
VArray[R][S]=2
LN890:
R=R+1
If C=H*V+1 Then 
  Goto LN1010
EndIf
Goto LN530
LN910:
If Q=1 Then 
  Goto LN960
EndIf
WArray[R][S+1]=C
C=C+1
If VArray[R][S]=0 Then 
  Goto LN940
EndIf
VArray[R][S]=3
Goto LN950
LN940:
VArray[R][S]=1
LN950:
S=S+1
If C=H*V+1 Then 
  Goto LN1010
EndIf
Goto LN260
LN960:
Z=1
If VArray[R][S]=0 Then 
  Goto LN980
EndIf
VArray[R][S]=3
Q=0
Goto LN1000
LN980:
VArray[R][S]=1
Q=0
R=1
S=1
Goto LN250
LN1000:
Goto LN210
LN1010:
For J=1 To V
TextWindow.Write("I")
For I=1 To H
If VArray[I][J]<2 Then 
  Goto LN1030
EndIf
TextWindow.Write("   ")
Goto LN1040
LN1030:
TextWindow.Write("  I")
LN1040:
EndFor
TextWindow.WriteLine("")
For I=1 To H
If VArray[I][J]=0 Then 
  Goto LN1060
EndIf
If VArray[I][J]=2 Then 
  Goto LN1060
EndIf
TextWindow.Write(":  ")
Goto LN1070
LN1060:
TextWindow.Write(":--")
LN1070:
EndFor
TextWindow.WriteLine(".")
EndFor

This chapter is adapted from the book Basic Computer Games Small Basic Edition published by Kidware Software.

To purchase this book in its entirety, please see the Computer Science For Kids web site.

Sample Run:

Next Chapter > >

Excerpt © Copyright 2010-2013 By Kidware Software LLC All Rights Reserved. Computer Science For Kids, the Computer Science For Kids logo, and related trade dress are trademarks or registered trademarks of Kidware Software LLC. Philip Conrod & Lou Tylee have co-authored dozens of books and tutorials for beginning Microsoft Basic, Small Basic, Visual Basic, and Visual C# developers of all ages for over 25 years.