Herman the Cube Crawler

Objectives: Gain experience modularizing your programs. 

Description: This program is intended to provide you with experience using subroutines, functions, and parameter passing, as well as the randomize function provided by Visual Basic.  It is also the first analytically challenging program.

Simulations are very important for the development of business applications. They are used to locate bottlenecks in factory operations, used to evaluate pricing policy given consumer reactions, and the College of Business uses simulations as a teaching tool in a number of advanced and graduate courses.

This simulation is designed to provide you with more experience using functions and subs, looping, random numbers, and invoking procedures from other procedures.  You will be simulating the life of Herman the Fly, who can only exist on the edges of a cube. At the start of a trial, Herman is randomly placed on one of the eight corners of a cube and poison is placed on one of the eight corners. Herman starts moving along the edges. When he comes to a corner, he chooses one of the directions and continues. How many edges will Herman visit until he hits the poison? Note that Herman may visit zero to an infinite number of edges in a given trial.

Develop a simulation of Herman’s travels around the cube. The visual basic form for your Herman simulation should include two buttons, three labels, and two list boxes:

The program uses listboxes because they can hold multiple values, and thus can be used to record or trace Herman's movements during a single trial, or to record the number of edges visited for all the trials.  

The most recent addition to a list box should be highlighted and displayed.

Use a delay routine to slow Herman's movements so that they can be observed.  The interface that you should use is shown in the following figure.


The use of labels in a form, instead of textboxes, will speed up larger programs because they have fewer properties. However, you may need to refresh the label before the new value will be displayed.

Use two integers declared as static variables, to track the running average. Name the variables "totalEdges" and "totalTrials." (Add the code for the running average after the rest of the project is operational – doing things a little bit at a time is key to rapidly generating bug free code.)

Use the modularization approach in  developing a solution to Herman.  Four or more procedures will help make the code tractable.  Implement and test the procedures individually, before developing the rest of the code (it's called incremental testing).  Do not use any global variables to pass variables into or out of functions or subroutines.  The procedures should include:

            * If you wish, you can replace these two functions with a single procedure (perhaps a function) called  
               initializePositions that can be called both to initialize the poison position as well as Herman's initial position.

Numbering your corners as they are numbered in the figure below may help.

Insufficiently commented code, poorly chosen variable or function names, not using functions, or not passing the correct information into a function will be graded harshly. Each function (as well as the program itself) requires a block comment at its top stating your name and one (or more if necessary) sentence(s) stating the exact purpose of that function.

Include a flowchart or pseudocode detailing your solution.  It can be a hand-drawn, rough draft and does not have to be fancy.



Extra Credit: Using graphics techniques, write a subroutine, drawCube, to draw a blue cube in a picture box below the output specified above.  Create a subroutine, drawCircle, that accepts the coordinates of one of the cube corners and a color, and draws a colored circle around that corner.  Then modify your Herman solution from above to show a simulation of Herman going around the cube.  Use the drawCircle routine to draw a red circle around the corner where the poison is located.  Track Herman's movements around the cube by using the drawCircle to draw a green circle at the node that he visits.  Only the current node should be so indicated.  When Herman hits the poison draw a black circle around that point.  See the extra-credit demo for an example.  A sample interface is shown in the following figure.