Classic Computer Magazine Archive ANTIC VOL. 4, NO. 12 / APRIL 1986




This is an Atari BASIC adaptation of a well-known artificial intelligence simulation game. The program tries to guess what animal you are thinking of-and it "learns" by remembering your answers. Animal Intelligence will work on all 8-bit Atari computers of any memory size, with disk or cassette.

Animal Intelligence is a BASIC version of the classic text-oriented artificial intelligence game. Put your Atari's barnyard brainpower to the test by answering its questions about an animal. Armed with simulated intelligence, the program will try to guess the animal you're thinking of. By learning from its mistakes and the data you give it, the program amasses a large database of knowledge. The longer you play the game, the smarter the database gets. After you've been at it a while, you may be surprised at the apparent "intelligence" of your computer.
   However, at the start of the game, while your computer is less educated, the conversations can be unintentionally hilarious.

COMPUTER: Is it a mammal?

YOU: No.

COMPUTER: Does it swim?

YOU: No way.

COMPUTER: Is it extremely stupid?

YOU: Yes.

COMPUTER: Is it a computer?

YOU: Boy are you dumb!

COMPUTER: Come on, yes or no?

YOU: Yes!

COMPUTER: That was fun! Want to try again?

Text-based games like Animal Intelligence are among the earliest examples of artificial intelligence programs.
The first successful attempt at simulating a verbal exchange between computers and human beings was Eliza, programmed by Joseph Weizenbaum in the mid-'60s. Considered the first computer "therapist," Eliza interacted with her patients by simply rephrasing and reflecting what they said.
   Animal Intelligence is actually more advanced than Eliza. It has the ability to store and call upon a substantial database of information and learn from its mistakes.
   Programs like Animal Intelligence and Eliza are most easily written in word-oriented languages such as LISP or Logo. These languages support list processing, a method of processing data in long, chained lists. I wanted a version in good old BASIC, a more universal but number-oriented language. Unable to find a BASIC version, I set about writing one of my own.

Type in Listing 1, ANIMAL.BAS, check it with TYPO II and SAVE a copy before you RUN it.
   The computer will ask you, "Think of an animal. I will try to guess it by asking questions about it. Is it a mammal?" After you answer YES or NO, you can respond with any word that begins with Y or N or simply the letters Y or N. The computer considers your response and asks another question. This process continues until the computer runs out of questions and makes an "educated" guess.
   If the computer guesses correctly, it will ask whether you want to play again. If it guesses incorrectly, it will give up and ask you what kind of animal you were thinking of. Then it asks you to type a question that would be answered YES for the correct animal and NO for the wrong animal it guessed.
   For example, suppose you were thinking "zebra" but the computer guessed "horse." The computer adds the new animal to its knowledge base, but still needs a way to distinguish the two. Now suppose you typed the question, "Does it have stripes?" in response to the computer's request. The program now knows that zebras have stripes and horses don't. It will use that information later to discriminate between the two.
   It's vital to save your computer's knowledge base to disk or tape-this knowledge is what makes the game fun. To save, type [CONTROL] [S] and you'll be prompted for a device to save the file to, and a filename. Cassette users should simply type C: at the prompt. Disk drive owners type D: and then the filename. To LOAD a previously saved knowledge base, press [CONTROL] [L] and respond to the prompt as explained just above.

You don't need to know how Animal Intelligence works in order to use it. But for those interested, here is a brief description of the theory behind the game:
   The game's intelligence is rooted in a tree-like knowledge structure. Each point where the tree has "branches" (or nodes) consists of three bits of information-a question to ask, a YES branch, and a NO branch. The terminations (tips) of the branches consist of a single bit of information-in this case, an animal.
   During play, the program branches through the tree from the bottom to the top, stopping at each node to ask a question and branching according to the user's response. When it reaches a termination, its guess is the animal it finds there.
   When the computer guesses incorrectly, the tree "grows" by creating a new node at the termination. Remember that a node is formed of a question, a YES branch, and a NO branch. To create the new node, the program uses the question you provide. It then places the new animal you have given it at the termination of the YES branch. The animal that was at the old termination gets pushed up the NO branch. Thus, what was previously a single termination becomes a node with two terminations, and the tree grows a little taller.
   To get Animal Intelligence to work properly in BASIC, a language which lacks list processing ability, I had to divide the knowledge base into three parts. The first and second are simulated string arrays-AX$ holds the animals, and QX$ holds the questions. The third part, TREE$, is the knowledge tree.
   Though it is an ordinary string, TREE$ functions as a matrix of pointers. Every three bytes comprise a node or termination. The first byte of a node is a pointer to a question held in QX$. The second and third bytes point to the YES branch and NO branch respectively The first byte of a termination is a pointer to an animal held in AX$, while the second and third bytes are just dummies at the start. Later they will be used as pointers when the termination grows into a node.
   Animal Intelligence isn't limited to animals, however. With some simple modifications, I've created knowledge bases of plants, rocks and minerals, even famous people. Kids seem to especially enjoy the program. And as an educator, I can attest to its value as a tool for learning.

Randy Deardorff is a former science teacher currently employed in laboratory information management by the U.S. Environmental Protection Agency. He has been programming the Atari since 1982.

Listing 1    ANIMAL.BAS Download