Computer Science I for majors by James Tam |
Due Wednesday June 21 at 5 PM
Write a program that simulates the life of a student in CPSC 231 (as shown in Figure 1). The simulated world will be represented by a 2D Python list of single character strings. A student 'S' can either choose to maximize his/her fun times 'f' during the term or the person can choose to expend time working 'w' in order to maximize the term grade point (GPA) and letter graded awarded. In this simulation there is not only a direct but a perfect correlation between time spent working and the grade awarded.1 Like a semester in "real life" there is only a finite amount of time during a term and the simulation will run for a maximum of 13 turns (weeks). Each time that the user is prompted to move the student (or if the choice is given up) a time unit will be expended. The initial starting positions will be read in from a text file whose name is specified as the program is started. The student's 'score' (fun and grade points earned along with the term letter grade) is saved to another text file 'scores.txt'. Only one set of scores are retained, each time that the simulation runs previous scores are overwritten.
|
|
Figure 1: The simulated world |
To add a level of uncertainty and challenge to the simulation two random events may occur. "The Pavol" may manifest itself ethereally (no physical appearance) and cause time to appear to stand still for a single week (the time expended by the user's actions won't actually increment time). The Pavol will affect time in the simulation but the Pavol itself doesn't physically appear in the simulation. Also the dread "Taminator" may appear. Unlike The Pavol the Taminator will physically appear. The Taminator can sense the location of a student and it will move towards the person. At maximum speed the Taminator travels at twice the speed of a student. When the Taminator has caught a student, the passage of time will accelerate (3 time units expended instead of 1). Fortunately (and ironically) the time that a Taminator appears is limited (3 'normal' weeks which is not counting the acceleration of time that it causes). Both The Pavol and the Taminator can appear multiple times during the simulation. But only one 'event' or the other will occur: if The Pavol has already appeared then the Taminator won't appear. Or if the Taminator has appeared and hasn't yet vanished then The Pavol won't make a manifestation.
In order to get credit for some features other features must have been implemented first (e.g. to get credit for moving on top of fun and work points, the ability to move the student has to be working first). Some of the most obvious prerequisites have been listed in the description below.
Options for using the pre-written file input functions. There is no advantage to using one vs. another. One approach splits the task into two functions to make things easier to interpret by students while the other combines the task into one function. Both functions return a list that has been initialized from the data in the specified file.
1) Option I, using a single function: createListFileRead(). The function creates a new empty row with each iteration of the outer loop. The inner loop successively appends new data (read in from file) onto the new row.
2) Option II, using two functions: initialize() and readFromFile(). The first function creates the list row by row and then appends a default value for each element '!' to the end of each row. The second function performs all of the file input. Line by the line the text from the input file is read in and the along that line each character is used to set each element of the list.
The input file will specify the starting positions for most of the main elements in the simulation:
'w' represents an opportunity to work on coding a Python program.
'f' represent an opportunity for the student to have a fun experience.
'S' represents the starting position of the student.
Spaces represent empty parts of the simulation - since your life is just about school and fun everything else is just a void right? ;)
You can assume that the Taminator 'T' will never be read in from an input file it has to be randomly generated as the game runs (or manually invoked by the user). And as mentioned The Pavol doesn't actually take physical form so it also never appears in the input file.
Another requirement to get any credit for your assignment is that the display of the grid must be done using the display() function provided or you must write an equivalent function yourself. This grid is required because it makes the display of world easier to read and interpret for both you and the marker.
Prompting for movement:
The player can move to any adjacent location that is not currently occupied by the Taminator. The movement options will be represented by a 9 point directional computer keypad grid (Figure 2).
Figure 2: Movement menu Each direction matches a cardinal compass direction (N=8, W=4, E=6, S = 2) or inter-cardinal compass direction (NW=7, SW=1, NE=9, SE=3). Selecting 5 doesn't move the student but still causes a turn to pass. Unlike previous assignments: Your program should not produce a run time error if an invalid input type is entered (i.e. a string instead of a number). Instead exception handling should be employed which displays a useful error message and continues prompting until a valid value has been received. The program should also continually re-prompt if a value of less than zero or greater than nine has been entered. Entering a value from 1 - 9 (save for 5) will result in the student moving in that direction and a turn being expended. If an attempt is made to move the student outside the bounds of the simulation or onto the Taminator then another useful error message should appear. Time will not pass if an invalid value or if an attempt is made to move the student to an invalid location (outside or Taminator occupied). Entering a zero will result in the secret cheat menu appearing:
Cheat menu options
(t)oggle debug mode off
(m)ake the Taminator appear
(p)avol manifests itself
(q)uit cheat menu
The user will be repeatedly prompted for a selection so long as an option other than one of the ones above have been selected. Toggle debug mode flips the state of the global debug flag between True and False. When the flag is set to True, debugging messages will appear. Their exact content is up to you but generally the message should be visually distinct (e.g. capitals, surrounded with angled brackets, indented etc) and specify the function that where the debugging message appears e.g. <<move() Taminator original location (4,5)>>. Selecting the option to make the Taminator appear will allow the user to select a (row, column) location. A location outside the list or one that one is currently occupied by the student will result in a re-prompting until a valid location is entered. You are not required to type check the Taminator location as you did with the direction of movement (moving the student). Once a valid location has been entered, the Taminator will start moving towards the student (more information on the Taminator event). Manifesting the Pavol will result in time suspending itself. Trying to get the Taminator or Pavol to appear via the cheat menu when the Taminator has already appeared should result in an error message and the program prompting the user for a cheat menu option again. (Since the Pavol only appears for a turn and the check for the Pavol's appearance occurs after the player's turn it won't be possible to try to invoke either the Pavol or Taminator when the Pavol has appeared).
Selecting a valid cheat menu option (even the option to quit) will result in a time unit being expended as if the user had selected a valid movement option. Entering an invalid option will not cause time to advance (again as was the case with the movement menu).
Moving the student onto the special objects: as mentioned the student cannot be moved outside of the simulation nor can the student being moved onto a location occupied by the Taminator. (No one can 'grapple' the Taminator!) Moving onto the a location with an opportunity for fun 'f' will increase the "fun points" by 1. Moving onto the a location with an opportunity for work 'w' will increase the grade point by 1. In order to get credit for these features, the program must actually allow the user to move the student. The work or fun opportunity is expended by the student and doesn't reappear in the location after the student moves. The current number of fun points and grade points (but not letter grade) awarded is displayed at the start of each turn:
Figure 3: display of fun and grade points After moving the student, the simulation will check for the possible occurrence of two events in the following order:
Running The Pavol event (you will only receive credit for this feature if the appropriate option in the cheat menu has been fully and correctly implemented and time must be properly tracked in order to get credit for this feature):
There's a 10% chance of this event occurring during a particular turn. This event only last for a single turn and it won't occur if the Taminator event is already in progress. The Pavol doesn't actually physically appear but it only affects the passage of time. The student gets an additional turn (normally the game will advance by one turn but the appearance of The Pavol causes time to roll back by one. So the appearance of The Pavol and time moving forward will cancel each other out..."time appears to stand still when you are lucky enough to be in the positive presence of "The Pavol."
Before The Pavol appears (turn 1):
Figure 4: The 'turn' when The Pavol makes a manifestation After the Pavol appears (the student collected a fun point by moving NW and consuming some 'fun' but it's still turn 1)
Figure 5: The turn after The Pavol has departed The next turn The Pavol will disappear and time resumes it's normal course (unless the Pavol appears during the next turn as well). The Pavol can appear multiple times during a simulation but as mentioned it won't appear at the same time as the Taminator.
Running the Taminator event (you will only receive credit for this feature if the appropriate option in the cheat menu has been fully and correctly implemented, time must be correctly tracked in the simulation).
The Taminator will only move to an adjacent position to the student. It won't move past the student by moving 2 full units (i.e. if it's already close to the student) nor will it move onto the location that is currently occupied by the student. If the Taminator is already in "close range:" the student it will slow down to 1 movement unit. And the Taminator is 'smart' enough so it can move faster along the row or column (only) if the distance is greater along that dimension only (see Figure 8). The Taminator will appear for 3 turns (includes the turn in which the Taminator first appears) and then it will vanish. Whenever the Taminator has caught up to the student (adjacent) the program must advanced time by an additional 2 turns (plus the normal passage of 1 turn = 3 turns passing for each turn that the Taminator is adjacent). It's your choice if time stops at 13 turns or goes beyond that but the simulation must stop at 13 (or more) weeks. While the Taminator is moving it becomes mystically incorporeal like The Pavol. Consequently any work and fun opportunities in it's path the student won't be destroyed. However once it stops moving it becomes solid again and a work or fun opportunity at the destination (where it stops) is destroyed.
The Taminator is by far the most complicated program feature so a more detailed explanation is provided. In this example the Taminator is invoked during Turn 1 via the cheat menu (Figure 6). During Turn 1 the program counts off 1 time unit out of the three units that the Taminator will appear. Also notice that invoking of the cheat menu causes one time unit to pass.
Figure 6: Initial appearance of the Taminator The next turn shows the Taminator has moved 2 rows and 2 columns towards the student during the last turn. (The Taminator reacts quickly and can immediately start moving). The movement was shown to the user only after the user selected a movement option for the student. Only one time unit has passed in the game because the student has not yet been caught. The program also counts that the Taminator has appeared for 2 turns now. Finally notice that the work opportunity (1,1) that was in direct path (but not the final destination) from the Taminator to the student still remains intact (Location (1,1) in Figure 7).
Figure 7: The Taminator first appears The Taminator moves only 1 row the next turn because this is all the distance that is needed in order to enter an adjacent position to the student. (It could move right by 1 column and still be adjacent but the Taminator is efficient in its movement). Now that the student has been caught time advances by 3 time units this turn. Notice that the fun opportunity that was located at the new destination of the Taminator (3,2) is now destroyed (Figure 8).
Figure 8: The Taminator catches the student The Taminator has made it's appearance for 3 time units and will vanish during the next turn (shown after the student moves). Notice also that fun opportunity at (3,2) has not re-appeared (Figure 9).
Figure 9: The time of the Taminator has passed There can only be one Taminator appearing at a time. If the program already randomly generated a Taminator, then the cheat menu won't allow the player to invoke another. As mentioned a suitable error message should be displayed instead. (An error message should also appear if the user manually invoked the Taminator and tries to invoke it again before it has vanished). Time will pass even though the Taminator couldn't be invoked (actually it couldn't be re-invoked) because the cheat menu was summoned. In a similar fashion the program shouldn't check for a new random Taminator event if the Taminator is still making it's appearance whether it was generated randomly or by the user via the cheat menu.
When the game is over the game (all weeks have elapsed naturally or in accelerated fashion due to the appearance of the Taminator) the usual statistics will be displayed onscreen (but also the letter grade should be displayed since the final result can be determined). That information should be saved to an output file, in this case the same name 'stats.txt' will be used each time to make it consistent and easier for your marker. Exception handling should be employed to deal with any file output problems during the save. Specific formatting isn't required for the scores file but the information should be presented in a reasonably neat and legible fashion. (Use format specifiers or escape codes as needed). Mapping of grade points to a letter is largely as expected: 0 grade point = F, 1 grade point = D, 2 grade points = C, 3 grade points = B, 4 or more grade points = A.
D2L configuration:
Points to keep in mind: