Lecture notes for the Introduction to Computer Science I by James Tam Return to the course web page

CPSC 231: Assignment 6

New concepts to be applied for the assignment

  1. Two-dimensional arrays
  2. Solving a challenging problem.

 

Implementing a computer game: Mr. Bean's Holiday © Universal

Mr. Bean wins a vacation to France where he meets Emil the son of a Russian director. You must bring Mr. Bean and Emil to the south of France in time for the Cannes Film festival. Obstacles such as mountains and the border stand in your way. The deadly waterways must be avoided. You can catch the French rail system to shorten your harrowing journey. Finally you must deal with the most difficult challenge of them all...Mr. Bean and his tendency to wander off on numerous zany side adventures.

The game world will be implemented in the form of a two-dimensional character array:

  • Space '  ': an open field (Mr. Bean can move here)
  • '~': water (Mr. Bean will drown here)
  • '#': Marks the borders of France (Mr. Bean can't leave France)
  • '^': Mountains
  • 'X': The railroad
  • 'C': The Cannes film festival (get here in time and you win the game)
  • 'B': Mr. Bean!

The game is turn based and each turn the game world be shown to the player who has the option of moving Mr. Bean or keeping him on the current square. He can't be moved into the mountains or onto the border. Mr. Bean drowns if he is moved into the ocean and the player loses the game. After the player has an opportunity to move Mr. Bean the game will determine if he goes off a side trip and wanders around on his own. Each time that the player moves or Mr. Bean wanders off a turn will elapse. This is important because the player only has a limited amount of time to get Mr. Bean to the bottom right side of the array (the Cannes film festival in the south of France). If time runs out then the player loses the game. If the player gets Mr. Bean to Cannes in time then he or she wins the game. The player can take a train part way to Cannes which will help shorten the travel time.

                

 

Features to be implemented (you will also be graded on other criteria such as coding style and providing program documentation as listed in the marking guide): 

 
  1. Displays an introduction to the game (with instructions) each time that it's run.
 
  1. Displays a conclusion when the game ends. The conclusion should indicate the game status (as applicable): game won, out of time, drowned, quit.
 
  1. Display a directional movement menu (see the sample executable) and gets the user input for the direction. When you implement feature #7 the numbers shown in this directional menu correspond to the cardinal compass directions (north, south, east, west) or inter-cardinal directions (north-west, north-east, south-west, south-east).
 
  1. Debug mode can be toggled on/off if the player enters a negative value at the movement menu.
 
  1. If the player enters a value larger than nine at the movement menu then the game displays an appropriate status message.
 
  1. The player can quit the game by entering zero at the movement menu. The game should display the status that the player quit the game.
 
  1. The player can move Mr. Bean onto an adjacent square.
 
  1. The game doesn't allow Mr. Bean to be moved onto a square with a mountain (an appropriate status message should be displayed).
 
  1. The game doesn't allow Mr. Bean to be moved onto the boundaries of France (an appropriate status message should be displayed).
 
  1. If Mr. Bean is moved into the water he drowns and the player loses the game. The game ends and an appropriate status message is displayed.
 
  1. After the player has had a chance to move Mr. Bean there's a 25% chance that he'll wander off on his own. During this time Mr. Bean's movement will be random - the player cannot move him until Mr. Bean has finished wandering. You can implement one of two versions of this feature but in both versions Mr. Bean will only wander into empty and adjacent squares.
   
  1. If it's determined for a particular turn that Mr. Bean goes wandering off, he will only wander once to an empty and adjacent square. A single turn passes.
   
  1. Similar to the above feature except for a particular turn that Mr. Bean goes wandering he will move one to six times. Each time that he moves another turn is used up (one to six in total).
 
  1. The player has 75 turns to bring Mr. Bean to Cannes. If the time runs out and Mr. Bean still hasn't reached Cannes then the player loses and an appropriate status message should be displayed.
 
  1. The player wins the game if Mr. Bean is brought to Cannes in time.
   
     
 
  1. (JT's hint: This feature is one of the more challenging ones so it's recommended that you don't work on it until you are nearly finished). Mr. Bean can take the train as a shortcut through the mountains. Again you can only implement one version for credit but in both cases you can assume that it's a one-way train (i.e., it only moves east, south-west, south or south-east). If any of the tracks are entered by Mr. Bean then he will be transported to the end near the bottom right of the array [as shown in this diagram]. This applies if Mr. Bean enters the rail system from any point (except for the end). Time will pass as Mr. Bean rides the train. However once Mr. Bean enters the train system he will ride it until the end. The player cannot control his movements nor will he randomly wander.
 
  1. When Mr. Bean goes onto the tracks he's transported instantly from wherever he entered the tracks to the end of the system.
 
  1. When Mr. Bean goes onto the tracks an animated sequence will begin that shows Mr. Bean traveling step-by-step to the end of the system (the game should pause at each step so that the user can actually see the sequence). Time passes for each animation but the player won't be able Mr. Bean nor will he wander off the train.

 

Submission requirements

In addition to having fulfill the generic assignment requirements, the requirements specific to this assignment include:

 
  1. Include a README file in your submission:  For this assignment you need to include a file called 'README' which includes your contact information: your name, university identification number and UNIX login name so that your marker knows whose assignment that he or she is marking.  Also it should list the features of the assignment that have been implemented in your program.

 
  1. The programming assignments require a two part submission: a) A paper submission of your README file and Pascal program into the assignment drop boxes (second floor Math Sciences) b) An electronic submission (again of your README file and your Pascal program) as an email attachment (don't cut and paste it into the email body!) to the following people (failing to include everyone listed below may result in your assignment not being marked for credit so before submitting your assignment double check!) Make sure that the subject line of the email contains the exact text (don't add or delete anything to it or you will lose marks - mail filters work by looking for specific words in the subject line): CPSC 231 Assignment X. Both parts are necessary. Electronically submitting the assignment allows your marker to compile and run the code in order to quickly determine what features were implemented.  Providing a paper printout makes it easier for your marker to read and flip through your source code.  A typescript of your execution is not needed for the programming assignments (this assignment onwards).

X = The appropriate assignment number (e.g., for Assignment 2 the subject would be titled "CPSC 231 Assignment 2")

 
  1. The course instructor at the following email address: tamj@cpsc.ucalgary.ca
 
  1. Your tutorial instructor, the email addresses for the TA's can be found on the main course web page.
 
  1. Yourself. Sending the assignment to yourself provides one last "double check" that you submitted your assignment properly (e.g., you sent it to all the right people, you attached all the important files to the submission etc...you should actually open the file attachments and check the files rather than just looking at the email). When you receive the submitted assignment you can check one last time to make sure that you fulfilled all the requirements. If you forgot something then you can resend your assignment with a note to mark only the latest submission (but try not to resubmit your assignment too many times please).
 
  1. Include a structure chart: It outlines the functions or procedures that will be implemented in your program as well as the hierarchy of calls (which module calls which). You can work on the structure chart on your own time and during tutorials when you will get some feedback about the direction of the design of your program. If students hand in their structure charts after the specified tutorial (e.g., you hand it in with your paper print outs when you submit your assignment) then you can still get a grade for this component although you obviously won't receive timely feedback to help you with your work. If you are unsure of what a structure chart looks like you can refer to the slides and your in-class notes on problem decomposition / modular design or the image included with the previous assignment. However you must hand in a structure chart along with your paper printouts in order to get credit for this component of the assignment - you can't just quickly show your TA your chart in tutorial because he won't remember it when it comes time to mark your assignment.  (You don't need to submit an electronic version of the structure chart however).

 
  1. To provide consistency between assignments you MUST use the same starting positions that I used. However you don't have to type in the values for the game world from scratch, you are welcome to use the code in the partial program 'bean.p'. Also like the previous assignments there's a sample executable in the assignment directory called 'bean' which you can employ in order to figure out the assignment requirements.
 
  To help make sure that you haven't missed anything here is a checklist of items to be used in marking.

 

Academic Misconduct and collaboration

Assignments must reflect individual work.  Each student must demonstrate that he or she can complete the assignment on their own so you cannot copy the work of other students nor can students work in groups.  Any suspected cases of cheating must be forwarded by me onto the Department Head, which may be passed on further to the Office of the Dean of Science and the Department of Student Services and result in penalties such as failing the course or even expulsion from the university.

A few questions and answers to help clarify things:

Q: What exactly constitutes cheating in this course? 
A: It is probably similar to what you have seen in other courses.  Cheating has occurred if you hand in someone else's work as if it were your own (without crediting the other person).   Furthermore if a student knowingly provides a copy of his or her assignment to another student  then both students are guilty of academic misconduct (the first student helped the second student to cheat).


Q: What happens if you include someone else's code in your assignment submission and you do credit the other person clearly and properly e.g., You use the code from the text book and you include the following citation:  The function listed below displays the list of email contacts for the user and it was taken from the book Pascal Programming & Problem Solving, 4th Edition, Leestma/Nyhoff . 
A: This will not constitute cheating but since someone else did the work for that section of your assignment you won't get credit for it e.g., if you were supposed to get a marks for writing the code to display a list but instead you copied someone else's code (and credited this person) rather than writing it yourself then you wouldn't get credit for the work.
 

Q: What is the difference between getting help from someone vs. cheating?
A: If you describe the process to someone using plain English then you should be okay because then the person still must figure out how to implement your generic ideas in a programming language (both of you are handing in separate submissions). This is because the person must understand the problem sufficiently to solve it on their own. If you simply give your code to a friend then this is not okay, even if your friend says that he or she will only use your solution as a 'guide' in order figure out the answer and 'promises' that he or she won't just copy it into their own program. This is because the person probably will not understand or the solution so he or she has learned nothing.

Okay Not okay
To write a loop that counts from one to ten the following steps must be completed. First a loop control (a variable that stores the values from one to ten) must be initialized to the starting value (in this case it's the number one). Next a check must be performed to ensure that the control includes but does not exceed the last value in the sequence (in this case it's the number ten). Within the body of the loop the current value of the loop control should be displayed onscreen so that the program actually 'counts' out the values onscreen. Finally the loop control must be updated with each pass through the body of the loop.
  i := 1;
  while (i <= 10) do
  begin 
       writeln ('i=', i);
       i := i + 1;
 end;

 

Q: The code that you gave us in lecture or tutorial would be really handy for our assignments, are we allowed to use it and get credit for the work? (You should pay especially close attention to this last point with the assignments in the later part of the term).
A: Yes, unless you are told otherwise you can make use of my sample code (I usually give the TA's the examples to cover in tutorial). Just make sure that you clearly indicate where you got it from in your program documentation as well as indicating which parts of the program come from class. Don't just include it in your code without citing the source (in this case it's me) because you will be claiming that this work is yours when it isn't so you will be guilty of academic misconduct.
 

Q: How do we credit some else's code?
A: Typically each logical block (function, procedure, loop, branch) that you did not write yourself must clearly indicate the source e.g., "The following procedure called "displayMaze" for displaying the contents of the array came from lecture notes by James Tam.

This list of questions only includes things that I thought up as I writing the assignment specifications, if you ever unsure if a particular situation constitutes cheating or not then it is up to you to ask me.