Assignment 07

Due: Wednesday, Oct. 26, 2011, at noon, 100 points

For this assignment, you will submit multiple files containing a program written in C++. Remember, to electronically submit a program for this course, first change to the directory in which the file(s) resides and then type in, at prompt, the command:

cssubmit 53 section_letter assignment_number

Be sure that only the file(s) you want to submit are in that directory - make a directory for every assignment! The submit system runs just the same with multiple files. The submit system will deliver every .cpp and every .h file in the current directory to me. Name your files meaningful names and give them proper extensions.

HERE ARE THE NEW PARAMETERS OF THE SIMULATION:

    • school size is 17 x 17

    • the symbol placed for the JANITOR is J

    • the symbol place for the windows is R, since I like R's

    • the number of simulations is 100000

    • the number of steps until he passes out is 42

Background: As some of you might know, Willie has a drinking problem. And when he falls off the wagon, it's almost always 30 days before he cleans up again. Everyday during that time he will get drunk at work and usually end up in a hedge or a closet or a basement sleeping it off. Willie wants you to write a program that will simulate his "behavior" during these times so that he can have more insight into his expected behavior. (With this information, he could just skip work for a week and roll the dice to find out if he's going to fall out a window, pass out in the hallway, or accomplish the assigned task that day. What a concept!) You will create his world (the school - an N x N gird of locations for him to be in), create Willie, place him in the middle of the school (that's the 2-D array just mentioned), randomly place a foul-smelling moldy sack lunch for him to try to find, place windows around the edge of the school, then set Willie off to try to find the sack lunch before he passes out or falls out of a window. Your program will repeat Willie's simulated journey 30 times and collect stats on the outcomes.

Specifications: You are going to write code that runs a simulation. That is, you will create "things" that "do stuff" at random, then collect statistics about the outcomes. For this particular simulation: you create a 10 x 10 2-D array, place Willie in the middle of this array, randomly place one sack lunch in the interior of the school, then repeatedly have Willie pick a random direction (up, down, left, or right) and take a step. You will use the first and last columns and top and bottom rows to be the walls of the school. In so doing, each cell will represent a section of the boundary wall. Regardless of the dimension of the school (10 x 10 in this example), you will place a window at every fourth section, not including corners. Thus, if you start in a corner spot, you will "mark" each 4th cell as a window until you get to the next corner (remember, no windows in the corners). Now, each time he takes a step, he will check to see if he found the lunch, fell out of a window (stepped into a cell marked as a window), bruised his forehead on a wall (stepped into a cell on the border that isn't a window), or just safely landed in an empty spot where he will repeat the process. [Note: if Willie's next step puts him "in" the wall, don't actually advance him into that cell. Increment his bruise count, and leave him where he was; his next step will be his chance to move again. If his next step puts him "in" a window, then take that to mean that he fell out of the window and that particular run ends.] Each run of this simulation allows Willie to take 40 steps before he passes out. So, a run can end with success (finds the sack lunch), Willie passing out, or Willie falling out of a window. At the end of 30 runs (simulating 30 days of drinking), you will report the following stats: the percentage of times he found the sack lunch, how many bruises he got from running into walls, the percentage of times he fell out of windows.

There are many ways to do this program, and you are once again going to make some design decision that will make a big difference how the coding will proceed. We suggest the following:

  • Create an appropriately sized 2-D array of characters.

  • Clear the array of garbage. Place a symbol, such as W for Willie, in the center.

  • Designate the outer rows and columns to represent the walls, and place another symbol in those cells for the windows according to the way outlined above. Remember not to put windows in the corners. And you might want to use 'F' to represent a window. That's because window in German is fenster. It is the only other language that I know the word for window.]

  • Now randomly place the moldy sack lunch.

  • You can either create the array in main and pass it to a function that will run a simulation, or create it in that function. You will, in either case, have that fuction return an indication whether or not Willie was successful. You will also have to pass information back from that function stating the stats you wish to collect. You might want to "wrap that up" in a struct (appropriately named). Think carefully what that struct should represent and what it should contain.

  • Pseudo-code for this program could look like this:

    • begin main loop on simulation create school clear away garbage place actors n'stuff // I love that word loop on steps Willie travels gather information/stats end loop on steps tally stats end loop on simulation present results end main

Here's a really cool picture that Josh created to exemplify the set up. It is clear from this picture that Josh knows a little German also. The 'B' in the non-window positions stands for "bumpinschtoppin", German for "wall".

Your output might look like this:

For 1000 runs of the simulator I got the following results: 35.8% Willie fell out the window. 40.4% Willie passed out on the floor. 23.8% Willie found the lunch. Willie sustained a total of 1673 bruises. (Average 1.67 per run)

You are to output the school with Willie and the lunch and windows and walls placed for the very first step of the very first day ONLY.

When you submit, you will have no interation with the user. The program will run according to the parameters we set1 and report the stats at the end.

As always, if you have questions, don't hesitate to ask your instructor or the LEAD guy (in the lab Mon through Wed nights).

1WE RESERVE THE RIGHT TO CHANGE THOSE PARAMETERS AT ANY TIME. WE WILL NOT CHANGE THEM ANY SOONER THAN 24 HOURS BEFORE THE DUE TIME. LESSON: CODE WELL!