Computer Science I for majors by James Tam

Return to the course web page

CPSC 231: Assignment 5

New concepts to be applied for the assignment

  1. Writing an Object-Oriented program

(Note: new design principles, e.g., Object-Orientation, as well design/style requirements from previous assignments such as good naming conventions must be applied in your work).

 

Overview

You are to write a dating simulator for fictional life forms called the "Tims" (Tam's simulated life forms) 1. There are two types of Tims in this simulation: a 'pursuer' and a 'target'. The target is the object of the pursuer's desire. In the full version of the program, the goal of the pursuer is to have a successful date with the target. The target's behavior is purely random. The date consists of a number of social interactions. If by the end of the date the proportion of successful interactions is 50% or greater then the date is considered successful otherwise it's deemed a failure. Two types of reports will show statistics on various aspects of the date.

Detailed description

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
  Minimum attributes (you probably will define more)
    Tally of the number of X-interactions generated by the pursuer
    Tally of the number of Y-interactions generated by the pursuer
    Probability of an X-interaction occurring (0 - 100%)
    Probability of a Y-interaction occurring (0 - 100%)
    Tally of the number of successful interactions with the Target (needed so that Pursuer can 'match' its behavior with that of the Target, even if you don't implement the intelligent matching behavior the information should be tracked here and not elsewhere).
  Minimum number of methods (you will probably define more)
    An "init()" constructor
    A method that will display a report at the end of each interaction between the pursuer and target
    A method that will display a report at the end of the simulation (when all interactions between the Pursuer and Target have finished)
    One or more methods that will determine the type of behavior that will occur for a particular interaction with the target (among other things the random numbers must be generated).
     
Class Target
  Minimum attributes (you probably will define more)
    Tally of the number of X-interactions generated by the target
    Tally of the number of Y-interactions generated by the target
    Probability of an X-interaction occurring (0 - 100%)
    Probability of a Y-interaction occurring (0 - 100%)
  Minimum number of methods (you will probably define more)
    An "init()" constructor
    One or more methods that will determine the type of behavior that will occur during an interaction (among other things the random numbers must be generated).

In addition you will define a 'Manager' module that contains the starting execution point for the your program (the start() or the main() function). The capabilities of this module can be written purely in a procedural manner (functions instead of classes and methods). At a minimum the functions in this module should be able to: 1) prompt the user for the number of interactions to occur when the program runs, 2) prompt the user for the probability of x-type interactions for the target 3) instantiate instances of the Pursuer and Target class inside of one of the Manager's functions. Finally the 'main loop' (that executes a number of times equal to the specified number of interactions) will be inside a function of the Manager. The appropriate methods of the pursuer and the target should be called within the body of this loop.

For an animated overview of the assignment see the following [presentation]

The total number of interactions for the date: it can be any integer >= 1. Your program should be able recover if the type of information entered by user is invalid (i.e., a non-numeric string) or if the range of information entered is invalid (zero or less). You can count floating point values as an invalid 'type' in this case. Whether the type or range of information is incorrect an appropriate error message should be displayed for each case and the program will prompt the user again for the number of interactions.

Examples of determining the number of interactions that the simulation will run (program prompt and user input in blue, program response in red)
Enter the number of interactions (1 or greater): ab
Do not enter non-numeric values
Enter the number of interactions (1 or greater): 1.2
Do not enter non-numeric values
Enter the number of interactions (1 or greater): 1

...
(Input is OK, program continues)

The probability of the Target object exhibiting type 'X' interactions: It will be an integer value 0 <= (value) <= 100. Similar to the total number of interactions your program should check the validity in the type and range of data entered and display appropriate error messages as necessary for each case.

Examples (program prompt and user input in blue, program response in red)
Enter the percentage # of 'X' interactions for target (whole numbers from 0 - 100): xyz
Do not enter non-numeric values
Enter the percentage # of 'X' interactions for target (whole numbers from 0 - 100): 1.5
Do not enter non-numeric values
Enter the percentage # of 'X' interactions for target (whole numbers from 0 - 100): 100

...
(Input is OK, program continues)

The program will then automatically determine the probability of type 'Y' interactions for the target object from the probability of X interactions. (The sum total of the two percentages must equal 100).

The probability of each type of interaction exhibited by the pursuer will depend upon the version of program that you implement. The simplistic approach will allow for an equal probability of type-X and type-Y behaviors (the "hope for the best" approach to relationships)1.

The date will then run one interaction at a time. During each interaction the pursuer and the target will exhibit one of two behaviors: 'X' or 'Y'. If both the pursuer and target exhibit the same behavior during a particular interaction (i.e. both were 'X' or both were 'Y') then that particular interaction is deemed as successful (and is counted in a tally). Otherwise the interaction is deemed as unsuccessful. Next the pursuer will display a report describing the results of the interaction between the pursuer and target:

Format of report generated at the end of interaction round
<Behavior exhibited by the target> <Behavior exhibited by the pursuer> <Result of the interaction>

Example of report generated at the end of interaction round
Target behavior: x    Pursuer behavior: x     Matched behavior  

Finally when the specified number of interactions have occurred, the final analysis of the date will be displayed by a method of the Pursuer. The report should include the total number of X-type interactions and Y-type interactions generated by the target and the pursuer. (Note: because the number of X's and Y's is already tracked by the target, the pursuer need not track this information again, it can simply get that information from the target). Next the program should show the number of and percentage proportion of successful interactions. (The percentage is equal to the number of successful interactions divided by the total number of interactions multiplied by 100).  Finally the report should determine if the date was successful or if it failed (the former if the proportion of successful interactions was 50% or greater, the latter otherwise).

Examples end of date report
(10 rounds of interactions in this example):
ANALYSIS OF ALL THE INTERACTIONS (THE DATE)
Target: No. of X's=4     No. of Y's=6
Purser: No. of X's=8     No. of Y's=2
Number of successful matches: 4
Proportion of successful matches: 40.0%
Date was a dud :'(

(20 rounds of interactions in this example):
ANALYSIS OF ALL THE INTERACTIONS (THE DATE)
Target: No. of X's=20    No. of Y's=0
Purser: No. of X's=14    No. of Y's=6
Number of successful matches: 14
Proportion of successful matches: 70.0%
Date was successful <3

 

"Intelligent Pursuer"1
The 'intelligent' version of the pursuer will analyze the patterns of behaviors of the target and try to match that object's behavior (i.e., if many type-X behaviors were exhibited by the target then the pursuer would then have an increased probability of only exhibiting type-X behaviors).

Example of the pursuer adapting to the target (adapting after interaction #10)
Target behavior: x    Pursuer behavior: y    Mis-Matched behavior
Target behavior: x    Pursuer behavior: y    Mis-Matched behavior
Target behavior: x    Pursuer behavior: y    Mis-Matched behavior
Target behavior: x    Pursuer behavior: x    Matched behavior
Target behavior: x    Pursuer behavior: x    Matched behavior
Target behavior: x    Pursuer behavior: y    Mis-Matched behavior
Target behavior: x    Pursuer behavior: y    Mis-Matched behavior
Target behavior: x    Pursuer behavior: x    Matched behavior
Target behavior: x    Pursuer behavior: y    Mis-Matched behavior
Target behavior: x    Pursuer behavior: x    Matched behavior <== JT's annotation: the pursuer begins adapting to the target's behavior
Target behavior: x    Pursuer behavior: x    Matched behavior
Target behavior: x    Pursuer behavior: x    Matched behavior
Target behavior: x    Pursuer behavior: x    Matched behavior
Target behavior: x    Pursuer behavior: x    Matched behavior
Target behavior: x    Pursuer behavior: x    Matched behavior

Exactly what constitutes 'intelligent' for this assignment? Because this isn't a formal class in Artificial Intelligence the definition is fairly broad. The pursuer demonstrates the ability to adapt to the pattern exhibited by the target and the marker can clearly see the pattern as the program executes (the display of statistics each round will be very useful). You can choose how many interactions will pass before the pursuer begins to adapt to the pattern (but it must be greater than zero interactions otherwise there is no 'pattern'). You can either come up with your own algorithm for the intelligent pursuer or you can freely research algorithms online. In the latter case make sure you clearly cite all your sources. (Failing to list a source may be regarded as academic misconduct).

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.

 

Using pre-written Python code

You will need to use the built in random number generator in the ‘random’ module/library. In addition you are free to use whatever Python code libraries that you find useful.

 

Submitting your work:

  1. Assignments (the source code/'dot-py' file) must be electronically submitted according to the assignment submission requirements using D2L.
  2. As a reminder, you are not allowed to work in groups for this class. Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the notes on misconduct for this course.
  3. Before you submit your assignment here is a [checklist] of items to be used in marking.

 

Complete sample output:

[Attached file]

1 The 'theories' espoused in the assignment description are specific only to the Tims (actually just tongue in cheek). You are not guaranteed any success at dating or other social interactions if you apply any of the techniques specified in this document!