Computer Science I for majors by James Tam |
Due Friday Dec 9 at 4 PM
(Note: new design principles (e.g., Object-Orientated design) as well design/style requirements from previous assignments such as good naming conventions, maximum lengths for each method must be applied in your work.
Write a dating simulator for fictional life forms called "The Tims" (Tam's simulated life forms). There are two types of Tims in this simulation: a 'Pursuer' and a 'Target'. The target is the object of the pursuer's desire. The behaviour of both types of Tims is purely random. The date consists of a number of social interactions between two Tims broken down into discrete time units. Each type of Tim will engage in one of two types of interactions: type X-behaviour and type Y-behaviour. If the two Tims engage in the same type of interaction then that interaction is deemed as successful (in this simulation opposites do not attract) otherwise the interaction is deemed as a failure. A summary report will be generated after each interaction briefly showing the result of the interaction for that time unit. At the end of the simulation a more detailed report will show overall results. |
The program will consist of two classes: the Pursuer class and the Target class. Each class should be defined in its own module file.
Class Pursuer: The purpose of this type of Tim is to win the affections of the Target (not necessarily in the most effective manner because it's behaviours are purely random). | ||||
Minimum attributes (you may find the need to define more especially constant attributes) | ||||
Tally of the number of X-interactions generated by the pursuer | ||||
Tally of the number of Y-interactions generated by the pursuer | ||||
Probability of a X-interaction occurring for the pursuer (0 - 100%) | ||||
Probability of a Y-interaction occurring for the pursuer (0 - 100%) | ||||
Minimum number of methods (you will probably define many) | ||||
An "init()" constructor | ||||
A method that will display a report when the simulation ends. Likely you will implement this method as a 'helper' for a method of the Manager. (Part of the report e.g. percentage occurrences of each behaviour will be directly handled by a method of the Manager whereas the parts of the report that relate to attributes of the Pursuer (# occurrences of each behaviour) will be implemented in a Pursuer class method but called by a Manager's method thus the Pursuer's method is a helper of the Manager's method). | ||||
Class Target:
The object of pursuit by the Pursuer. It's behaviour is entirely random.
(No wonder that the Pursuer just "doesn't get" the behaviour of the
Target).
|
||||
Tally of the number of X-interactions generated by the target | ||||
Tally of the number of Y-interactions generated by the target | ||||
Probability of a X-interaction occurring for the target (0 - 100%) | ||||
Probability of a Y-interaction occurring for the target (0 - 100%) | ||||
Minimum number of methods (you will probably define many) | ||||
An "init()" constructor | ||||
One or more methods that will determine the type of behaviour that will occur during an interaction (among other things the random numbers must be generated). | ||||
A method that will display a report when the simulation ends. Likely you will implement this method as a 'helper' for a method of the Manager. (Part of the report e.g. percentage occurrences will be directly handled by a method of the Manager whereas the parts of the report that relate to attributes of the Target will be implemented in a Target class method but called by a Manager's method thus the Target's method is a helper of the Manager's method). | ||||
One or more methods that generates a report at the end of the simulation that shows the number of each type of interaction generated by the Target during the entire simulation. |
Class Manager:
The intermediary between the two types of Tims. Tracks statistics about
the simulation and it's the starting execution point for the program.
|
||||
The total number of time units that the simulation will run. | ||||
The number of successful interactions (tallied when the Pursuer and Target exhibit the same type of behaviour during a particular time unit). | ||||
The number of failed interactions (tallied Pursuer and Target exhibit different types of behaviour during a particular time unit). | ||||
A reference to a Pursuer object. | ||||
A reference to a Target object. | ||||
Minimum number of methods (you will probably define more) | ||||
An "init()" constructor | ||||
Several methods to actually run the simulation. Example actions needed: get and verify the number of time units, call methods in each of the Target and the Pursuer to randomly determine their behaviour for a time unit, determine the result of a particular interaction, tally the successes vs. failures etc. There will be two reports generated by the Manager: one that shows the result of an interaction between the Pursuer and the Target during a particular time unit, the other will show the results of all the interactions for the entire simulation (the latter report only appears at the end). The first report can likely be implemented by a method(s) that are just a part of the Manager class. The second report will involve a method(s) of the Manager class along with method calls to the other two classes to offload some of the work. That's because only the Pursuer tracks the number of occurrences of each type of its behaviour (and the Target does the same for each of its behaviours). That means that the method of the Manager class that displays the end of simulation report will likely call on the display report methods of each of the Pursuer and Target in order to show the number of interactions exhibited by each type of object. |
If the need arises you can employ a fourth module called "Globals.py" which contains the definitions for global constants (these are globals that are used in multiple modules - constants that are used in only one classes' methods can be defined in the same file module as the definition of the class). Global variables should not be employed in this assignment (unless you want to define/employ) another debugging tool.
When the simulation first runs the program will poll the user for the probability (0 - 100%) for the occurrence of each type of interaction. The program will check the sum of the two probabilities for each type of Tim equals 100%. If not the program will employ recursion (you will get no marks if you use a loop) to repeatedly prompt the user for the two probabilities until they sum to 100%. The program does not have to type check (string vs. numeric) the input of the probabilities.
Entering probabilities for the 'Pursuer' type of Tim. The sum of the two probabilities must equal 100%.
Enter the probability that X-type of behaviours will occur during an interaction during the date: 100%
Enter the probability that Y-type of behaviours will occur during an interaction during the date: 20%
Error: the two probabilities equals 120% (must sum to 100%). Please re-enter the values.
...
The probability for each type of behaviour can differ for the Pursuer vs. the Target so the program will prompt for the values separately. (Thus there will be 4 prompts: two for each type of Tim for the probability of each type of behaviour).
During each time unit the program will then use the probabilities entered by the user to determine which type of behaviour actually occurs that turn. The program will employ the use of the 'random' module to randomly generate values. For instance if the Pursuer had a 100% probability of X-type behaviours occurring then no Y-type behaviours should occur. If the Pursuer had a 90% probability for X-type behaviours and there's a 10% probability for a Y-type behaviours to occur then most (on average 9 out 10 times) a type-X behaviour should come up for the Pursuer.
When the simulation starts the user will be prompted for a number of pieces of information: the probability that X-type behaviours and Y-type behaviours occurs for the Pursuer and Target (4 pieces of information). Refer to the previous section (randomly generated interactions) for details of how the prompting occurs and how this information is used. Next the user will be prompted for the number of interactions that the simulation will run (each interaction generates a random behaviour from both the Tims). The number of interactions needs to be in the range from 1 - 100. Similar to getting the probabilities your program does have to type check this input but it must use recursion (not marks for employing a loop) to check that the range is correct. After a valid has been entered the program will proceed to the next phase which is running the simulation.
The program will run the simulation for the number of time units specified by the user. During each time unit the Manager will randomly generate a behaviour for the Pursuer and the Target using their specified probabilities. It will determine if the interaction was a success (same behaviour for both) or failure (different behaviours), add a tally to the appropriate attribute and then display information about the interaction that occurred during that time unit:
<Turn #> <Success/failure> : <Behaviour of target>, <Behaviour of pursuer>
Enter the number of turns to run simulation
(1-100):100
Turn # 1 Match: Target y, Pursuer y.
Turn # 2 No match: Target y, Pursuer x.
Turn # 3 No match: Target y, Pursuer x.
Turn # 4 No match: Target y, Pursuer x.
...
After the simulation has run for the specified number of time units, the Manager class will display the final overall statistics (with help from the Target and the Pursuer objects):
Pursuer statistics (the information about the Pursuer object's attributes will be tracked by the Pursuer so the Manager will have to call a method of the Pursuer to display the following information):
<# of X-type interactions> <# of Y-type interactions>
However the Manager tracks the number of interactions that occur for a particular run of a simulation. And it tracks the number of successful vs. failed interactions so this class can display the proportion of successes vs. failures.
...
Turn # 99 Match: Target y, Pursuer y.
<== Time unit by time unit information
Turn # 100 No match: Target y, Pursuer x.
END OF SIMULATION,
FINAL RESULTS
Pursuer statistics
<== Information displayed by a method of the
Pursuer
Number of Xs: 66 Number of Ys: 34
Target statistics
<== Information displayed by a method of the Target
Number of Xs: 44 Number of Ys: 56
Overall statistics
<== Information displayed by a method of the Manager
No. matches: 34 No. mis-matches: 66 Total attempts: 100
Proportions of matches: 34.0% Proportion of mis-matches: 66.0%
[TA Marking spreadsheet]