Share via


Basic Computer Games - Small Basic Edition: Animal

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

Unlike other computer games in which the computer picks a number or letter and you must guess what it is, in this game you think of an animal and the computer asks you questions and tries to guess the name of your animal. If the computer guesses incorrectly, it will ask you for a question that differentiates the animal it guessed from the one you were thinking of. In this way the computer "learns" new animals. Questions to differentiate new animals should be input without a question mark.

This version of the game does not have a SAVE feature. If your system allows, you may modify the program to save array A, then reload the array when you want to play the game again. This way you can save what the computer learns over a series of games.

At any time, if you reply "LIST" to the question "ARE YOU THINKING OF AN ANIMAL," the computer will tell you all the animals it knows so far.

The program starts originally by knowing only FISH and BIRD. As you build up a file of animals you should use broad, general questions first and then narrow down to more specific ones with later animals. For example, if an elephant was to be your first animal, the computer would ask for a question to distinguish an elephant from a bird. Naturally there are hundreds of possibilities; however, if you plan to build a large file of animals a good question would be "IS IT A MAMMAL."

This program can be easily modified to deal with categories of things other than animals by simply modifying the initial data in the A array and the dialogue references to animals in other program lines. In an educational environment, this would be a valuable program to teach the distinguishing characteristics of many classes of objects - rock formations, geography, marine life, cell structures, etc.

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.

Originally developed by Arthur Luehrmann at Dartmouth College, Animal was subsequently shortened and modified by Nathan Teichholtz at DEC and Steve North at Creative Computing.

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

TextWindow.CursorLeft = 32 
TextWindow.WriteLine("ANIMAL") TextWindow.CursorLeft = 15 
TextWindow.WriteLine("BIBLEBYTE BOOKS, MAPLE VALLEY, WASHINGTON") 
TextWindow.WriteLine("") TextWindow.WriteLine("") TextWindow.WriteLine("") 
TextWindow.WriteLine("PLAY 'GUESS THE ANIMAL'") TextWindow.WriteLine("") 
TextWindow.WriteLine("THINK OF AN ANIMAL AND THE COMPUTER WILL TRY TO GUESS IT.") 
TextWindow.WriteLine("") 
A[0] = "4" A[1] = "\QDOES IT SWIM\Y2\N3\" A[2] = "\AFISH" A[3] = "\ABIRD" N=A[0] 
LN120: ' MAIN CONTROL SECTION 
TextWindow.Write("ARE YOU THINKING OF AN ANIMAL ") 
AD = TextWindow.Read() If AD="LIST" Then Goto LN600 EndIf 
If Text.GetSubText(AD,1,1)<>"Y" Then Goto LN120 EndIf K=1 LN170: Sub390() 
If Text.GetLength(A[K])=0 Then Goto LN999 EndIf 
If Text.GetSubText(A[K], 1, 2)="\Q" 
Then Goto LN170 EndIf 
TextWindow.Write("IS IT A "+Text.GetSubTextToEnd(A[K],3)+" ") 
AD = TextWindow.Read() AD=Text.GetSubText(AD, 1, 1) 
If Text.GetSubText(AD,1,1)="Y" 
THEN TextWindow.WriteLine("WHY NOT TRY ANOTHER ANIMAL?" ) 
Goto LN120 EndIf TextWindow.Write("THE ANIMAL YOU WERE THINKING OF WAS A ") 
VD = TextWindow.Read() 
TextWindow.WriteLine("PLEASE TYPE IN A QUESTION THAT WOULD DISTINGUISH A") 
TextWindow.WriteLine(VD+" FROM A "+Text.GetSubTextToEnd(A[K],3)) 
XD = TextWindow.Read() 
LN280: TextWindow.Write("FOR A "+VD+" THE ANSWER WOULD BE ") 
AD = TextWindow.Read() AD=Text.GetSubText(AD, 1, 1) 
If AD<>"Y" AND AD<>"N" Then Goto LN280 EndIf If AD="Y" 
Then BD="N" EndIf If AD="N" Then BD="Y" EndIf 
Z1=A[0] A[0]= Z1+2 A[Z1]=A[K] A[Z1+1]="\A"+VD 
A[K]="\Q"+XD+"\"+AD+(Z1+1)+"\"+BD+Z1+"\" 
Goto LN120 Sub Sub390 'SUBROUTINE TO PRINT QUESTIONS QD=A[K] LN410: 
For Z=3 To Text.GetLength(QD) 
If Text.GetSubText(QD,Z,1)<>"\" Then TextWindow.Write(Text.GetSubText(QD,Z,1)) 
else Goto LN411 EndIf EndFor LN411: TextWindow.Write(" ") 
CD = TextWindow.Read() CD=Text.GetSubText(CD, 1, 1) 
If CD<>"Y" AND CD<>"N" Then Goto LN410 EndIf TD="\"+CD 
For X=3 To Text.GetLength(QD)-1 If Text.GetSubText(QD,X,2)=TD 
Then Goto LN480 EndIf EndFor Program.End() 
LN480: For Y=X+1 To Text.GetLength(QD) If Text.GetSubText(QD,Y,1)="\" 
Then Goto LN510 EndIf EndFor Program.End() 
LN510: K=Text.GetSubText(QD,X+2,Y-X-2) 
EndSub LN600: TextWindow.WriteLine("") 
TextWindow.WriteLine("ANIMALS I ALREADY KNOW ARE:") X=0 
For I=1 To 200 If Text.GetSubText(A[I],1,2)<>"\A" Then Goto LN650 EndIf 
TextWindow.CursorLeft = 12*X For Z=3 To Text.GetLength(A[I]) 
If Text.GetSubText(A[I],Z,1)<>"\" 
THEN textwindow.Write(Text.GetSubText(A[I],Z,1)) 
Else Goto LN645 EndIf EndFor LN645: X=X+1 
If X=4 Then X=0 TextWindow.WriteLine("") EndIf 
LN650: EndFor TextWindow.WriteLine("") 
TextWindow.WriteLine("") Goto LN120 LN999:

 

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.