CS 390: 61-70 Fall 1999
Homework 5 - Logic & Virtual Pests, Part I

Due Date: Tuesday, Nov. 9 in class


The Analytical Engine, Chapter 7, Sections 7.1-7.2


This is the first part of a multiple-part assignment. The purpose of the assignment is for you to gain experience with writing conditional statements, using random numbers, and using functions. For this part, you will design an HTML FORM and describe how the form will behave under different circumstances. For the second part, you will create the form and provide it with the specified behavior.


You are required to use a word processor for all written answers.
  1. The Analytical Engine, Lab 7.1-7.2. You may find these labs on the CD that accompanies the text, or at the web site created for the text.
    As is the case in our own class labs, you are to maintain a 'lab sheet' on which you record data. If a step requires you to answer a question, record the answer on your sheet. If a step requires you to observe something, record what you observed. If a step does not require you to record anything, indicate on your sheet that you completed the step. Unlike our own class labs, you are to use a word processor to record your results.
  2. The Analytical Engine, Section 7.5 Problem 1
  3. The Analytical Engine, Section 7.5 Problem 2(b)
  4. The Analytical Engine, Section 7.5 Problem 3(b,c)
  5. The Analytical Engine, Section 7.5 Problem 6(a)
  6. Virtual Pest problem (described below)

Virtual Pests:

The most popular toy to hit the scene a few years ago was the "virtual pet" - an electronic toy that simulated pet behavior (displayed on a screen) and allowed its "owner" to respond to various types of behavior by performing actions (generally "pushing buttons"). Owners often find that these toys are more "virtual pests" than "virtual pets".

You can create your own virtual pest, using HTML and JavaScript. For this part of the assignment, you are to design the pest's attributes and describe its behavior as a finite-state machine, as explained below. You will also provide a written description of the various features of your pest and how the user interacts with it. You do not have to write any JavaScript code for this part of the assignment; that will be required in a future assignment. (In future assignments, you will create the user interface, which will consist of an HTML FORM with buttons, text boxes, and graphics, and ultimately, you will implement your virtual pest as a web page using HTML and JavaScript.)


Consider a very simple "virtual dog" that is perpetually in one of four states: happy, angry, provoked, or lonely. A virtual dog that is lonely remains lonely until its owner pats it, which makes it happy. (Here, we say the dog has changed states from lonely to happy.) A virtual dog that is happy remains happy 90% of the time, but may also become angry 10% of the time. (This means that the dog's state is evaluated periodically (say, every 30 seconds) and 10% of the time, the state will be changed. Note that in this case, the dog's state is unaffected by the owner's hand, and its mood - i.e., its state - changes randomly.) An angry dog stays angry until the owner pats it, which causes it to become provoked. A provoked dog remains in its provoked state 80% of the time, but may become lonely the other 20% of the time (because nobody goes near it).

The diagram below describes this simple behavior as a finite-state machine. The system (i.e., the dog) in this case has four states, which are signified by the circles labeled with the state's name. The system is always in exactly one of these states. The system may make a transition from one state to another as specified by the lines connecting them. The arrows signify which states are reachable from the current state. For example, there are arrows connecting the happy state to itself or to the angry state, which means a happy dog can either remain happy or become angry. A happy dog cannot directly become lonely, but a lonely dog can become happy.

The virtual pets available commercially generally have very many states and there are many ways in which their owners can interact with them. They also sometimes have terminal states, that is, states from which the pet cannot exit. Typically, the pet is said to have died if this happens. Such states are typified by nodes that have no lines pointing outward from them.

Part a: You are to design a virtual pest with at least 5 states. Your pest should have a name, and each state should have a name also. You are to design a finite-state machine that depicts which states may be reached from other states, and under what conditions, similar to the example above.

Part b: Your virtual pest will eventually take the form of a web page. Interaction will occur through an HTML form. (NOTE: for this exercise, you do not have to create the HTML form. You simply need to provide a diagram of what it will look like). At a minimum, your form will have the elements described below:

For example, a form to accompany the finite-state machine above may look like this:

Tralfaz, the Wonder Dog

Pet Sound:

Pet Action:

Part c: Finally, you need to plan your pest's behavior. That is, how does the pest tell you about its state? (For instance, when it is angry, it may growl. When it is happy, it may wag its tail. You also need to specify how the owner's actions affect its state.) This is a design exercise, not a coding exercise. You should design the behavior before you try to code it. You should use a table of the following form to describe your pest's behavior:



Possible values




text box

Woof woof

state= lonely



pat the dog

changes state to "provoked" if angry, and to "happy" if lonely.


text box

Wag Tail

state= happy

WARNING: Don't try to describe behavior that is too complicated if you don't think you will be able to accomplish the desired behavior for the second part of the assignment.



You must do this work yourself. If you need assistance with this aspect of the assignment, see a consultant during consulting hours. You are encouraged to seek any necessary help from other persons regarding how to use your computer and accompanying software, in accordance with the stated course policy.