animal.icn: Program to play "animal" guessing game

March 2, 1996; Robert J. Alexander
This file is in the public domain.
   This is the familiar ``animal game'' written in Icon.  The
program asks its human opponent a series of questions in an attempt
to guess what animal he or she is thinking of.  It is an ``expert
system'' that starts out with limited knowledge, knowing only one
question, but gets smarter as it plays and learns from its opponents.
At the conclusion of a session, the program asks permission to
remember for future sessions that which it learned.  The saved file
is an editable text file, so typos entered during the heat of battle
can be corrected.

   The game is not limited to guessing only animals.  By simply
modifying the first two lines of procedure "main" a program can be
created that will happily build a knowledge base in other categories.
For example, the lines:

        GameObject := "president"
        Tree := Question("Has he ever been known as Bonzo",
           "Reagan","Lincoln")

can be substituted, the program works reasonably well, and could even
pass as educational.  The knowledge files will automatically be kept
separate, too.

   Typing "list" at any yes/no prompt will show an inventory of
animals known, and there are some other commands too (see procedure
Confirm).

Source code | Program Library Page | Icon Home Page