Course Home | Assignments | Computing Resources | Lab Hours/Tutoring | Questionnaire | Schedule | Submit

Saint Louis University

Computer Science 146
Object-Oriented Practicum

Michael Goldwasser

Summer 2014

Dept. of Math & Computer Science

Assignment 08

Moving Forward

Overview

Topic: Moving Forward
Due: 11:59pm Tuesday, April 22
Related Reading: none

Please make sure you adhere to the policies on academic integrity.


Table of Contents


Your task

For this assignment, we return back to the original version of the code for partII, available here, or on turing at /Public/goldwasser/146/partII

The goal is to modify the fish class to provide the following change in semantics to the Move method: a fish should have a directional orientation based on its most recent move, and it should be more likely to move forward than it is to move to either side, and it should only move backward when no other move is possible.

More specifically, you should define a constant within the fish class such as

const int BIAS = 4;
In that case, if all directions are viable, the forward one should get selected with relative weight 4, while the two side directions are selected with relative wieght 1 each (and backward is never selected); that is forward would have a 4/6 chance of being selected, left a 1/6 chance, and right a 1/6 chance. As another example, if forward and left are viable, but right is blocked, then it should select forward 4/5 of the time and left 1/5 of the time. If forward is blocked, but both sides are available, they are selected with equal weight. In the special case when a fish remained still in the previous time step, all neighboring directions should be equally likely.

Although we use 4 as the bias in the above examples, you should make sure to treat this as a general positive integer, so that we could recompile the program to test out the simulation with a stronger or weaker bias value.

To implement this new behavior, you will need to maintain additional state to be able to determine what direction is considered "forward." We recommend that you always store the last position it was at, in addition to its current position.

One of the other challenges in implementing the new behavior is in figuring out how to succintly describe the case analysis for making a random choice with the appropriate distribution. To this end, we recommend that you first define new position variables to represent concepts such as "forward", "sideA", "sideB", "backward" so that you can abstract away from having separate cases for traveling north/south/east/west. Then you must determine how to use the random number generator to produce the desired probabilities.


Submitting your project

Your assignment should be submitted electronically (details on the submission process).

For this assignments, you should only be modifying (and thus submitting) files fish.h and fish.cpp. Please also submit a "readme" text file that describes the changes you have made.


Michael Goldwasser
CSCI 146, Summer 2014
Last modified: Tuesday, 12 November 2013
Course Home | Assignments | Computing Resources | Lab Hours/Tutoring | Questionnaire | Schedule | Submit