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

CPSC 231: Assignment 5

New concepts to be applied for the assignment

  1. One-dimensional arrays
  2. Solving a moderately challenging problem.

 

Implementing a Scrabble ™ (Hasbro) rack

(The following was paraphrased from the official Scrabble website: www.scrabble.org) The game of Scrabble was devised to combine the vocabulary skills of crossword puzzles and anagrams, with an element of random chance thrown in. Players are given a series of "tiles" with an alphabetic letter stamped on it from which words are supposed to be formed on a board (see Figure 1).

Figure 1: A Scrabble board (from www.scrabble.org)
 

Prior to placing tiles on the board, players typically arrange them on a 'rack' in order to see how different orderings of tiles may form different words (see Figure 2). For this assignment you will implement a program that simulates a Scrabble rack as a 1D character array. The rack will hold eight tiles and players can re-arrange the tiles according to a set of specific rules. You do not have to check if a particular ordering yields a valid word nor do you have to implement the code to allow the player to place the tiles onto a board and score points. (Implementing the rack itself is sufficient to receive full credit).

Figure 2: A Scrabble rack for rearranging tiles (from www.terragame.com)

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. The first time that the game is run it displays an introduction to game with a brief description of the rules for manipulating the rack.
 
  1. When the player quits the game it displays a brief conclusion/signoff message.
 
  1. Displays a menu of allowable actions to the player (multiple letter move, single letter move, quit the program) and reads in the player's selection.
 
  1. A new type called 'Rack' has been defined as a character array with 8 elements.
 
  1. An instance of 'Rack' has been declared.
 
  1. Entering 'd' at the main menu will toggle debugging messages on and off by using a global flag (called 'debugOn'). The exact content of these debugging messages (e.g., showing module calls, showing the contents of variables at different points in your program) are left to your discretion but as the name implies they should be used to help you debug your program. (Note: the use of this debugging flag as a global variable is probably the sole exception to avoiding the use of global variables for your assignments for this semester). If you find that seeing all debugging messages appearing all at once through a single debugging flag is too overwhelming you can implement multiple debugging flags (e.g., 'displayModuleCalls', 'displayVariableContents') each of which will each only display a particular category of debugging message. (For example if displayModuleCalls was set to 'true' and displayVariableContents was set to 'false', the game would show a message each time that a function or procedure was called but it would not display the contents of variables). If your game has multiple types of debugging messages then entering 'd' at the main menu will shown a debugging menu which then allows the player to select the specific debugging message to turn on and off. (JT's hint: you should implement this feature early on so you can actually use it to help you debug your program because this is a complex assignment! You shouldn't implement it at the end merely to fulfill the assignment requirements when it's too late to help you fix the errors in your game because that defeats the whole purpose of writing a debugging tool).
 
  1. Generates a random ordering of tiles in the rack. There are two approaches that you can take (you will get credit for implementing one approach but not for both).
   
  1. A uniform random algorithm is used to initialize the rack. Every letter of the alphabet is equally likely to occur for a particular tile position on the rack.
   
  1. A frequency based algorithm is used to initialize the rack.
     
Letter A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Probability of occurring (percentage) 8 3 3 3 8 3 3 3 8 3 3 3 3 3 8 3 2 3 8 3 8 2 3 1 1 1
      (Note this is not the same algorithm that is used to determine the frequency of tiles in the actual Scrabble game).
 
  1. The rack is formatted in the same fashion as the sample executable with numbered bounding lines that match the indices of the array.
 
  1. The player can swap any pair of single tiles by entering the index of the tiles to be swapped.
 
  1. A consecutive range of tiles can be moved to the front or the back of the rack. (In both cases the game should check that the range is valid).
   
  1. Front. The player specifies the lowest index (left) and the highest index (right) of the range of tiles to be moved to the front of the rack (left-most position). All other tiles will be placed in positions that immediately follow in the order that they were arranged prior to the shift.
      For example suppose that the rack contained the following tiles and the player wanted to shift tiles 2 to 5 to the front.
     
1 2 3 4 5 6 7 8
B X X X Y F A B
      After the shift the rack would be ordered as follows.
     
1 2 3 4 5 6 7 8
X X X Y B F A B
   
  1. Back. The player specifies the lowest index (left) and the highest index (right) of the range of tiles to be moved to the back of the rack (right-most position in their current order). All other tiles will be shifted to the front of the rack in their in the order that they were arranged prior to the shift.
      For example suppose that the rack contained the following tiles and the player wanted to shift tiles 3 to 6 to the back.
     
1 2 3 4 5 6 7 8
D J Y I E L T J
      After the shift the rack would be ordered as follows.
     
1 2 3 4 5 6 7 8
D J T J Y I E L

 

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).

 
  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.