Lecture notes for the Introduction to computers by James Tam Return to the course web page

A3: Programming and problem solving

Data files

 

New concepts to be applied for this assignment

The Rock-Paper-Scissors game

This is a simple two player game where each player is allowed one of three possible hand gestures: rock, paper or scissors. In the actual game players are supposed to select their gesture at the same time and the gesture selected determines the outcome. (You won't be responsible for writing a game that works in real-time however, with the program that you write each player will make their selection one at a time).

Player 1 Player 2 Outcome of the game
Rock Rock Tie
Rock Paper Paper covers rock (player 2 wins)
Rock Scissors Rock blunts the scissors (player 1 wins)
Paper Rock Paper covers rock (player 1 wins)
Paper Paper Tie
Paper Scissors Scissors cuts paper (player 2 wins)
Scissors Rock Rock blunts the scissors (player 2 wins)
Scissors Paper Scissors cuts paper (player 1 wins)
Scissors Scissors Tie

Much like the real world game if a player tries to cheat (e.g., selects an invalid gesture) then that player has committed a foul and for the game that you will write the player is given a "forced rock" for their gesture.  You can go the following url to try a web based version of the game if you want to get a feel for how the game works: http://www.playrps.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):

Version with two people playing the game
 
  1. A splash screen appears as the program loads. The splash screen consists of an image and text that is added using the ‘addText’ function in JES
 
  1. Prompts and reads from the player the number of people who will play the game.
 
  1. Repeatedly prompts the player, if the number of players is not a valid amount (0 – 2), until the player enters a valid number.
 
  1. Allows the player to select the default for the number of players. If the player enters a negative value then the game will assume that there’s zero players. If the previous feature (#3#) has been implemented this means that you must modify the looping condition, the repetitive prompting only occurs if the player enters a value larger than 2, if the player enters a negative number then the game will set the number of human players to zero and stop the prompting loop.
 
  1. Displays a menu of allowable gestures 'r(ock)', '(p)aper' or '(s)cissors'. The menu should be displayed using the “raw_input” function rather than using  “print” because the latter won't properly appear until after the game is finished.
 
  1. Reads each player's selected gesture in the form of a single lower case character: 'r', 'p' or 's'.
 
  1. Can determine if an invalid gesture has been selected (foul) and if so gives the player a forced rock as their gesture.
 
  1. Compares the gestures for the players and can correctly determine and display onscreen the outcome of the game (who wins, who loses or if there's a tie).
 
  1. Instead of displaying the status message via print statements (Feature #8) an image is displayed for each of the three cases:  tie, player one wins, player two wins.
 
  1. The game plays a different sound for each of the three game outcomes.

Versions that include a computer-controlled opponent:
 
  1. The game allows for one computer-controlled opponent which has an equal probability of selecting each gesture.
 
  1. The game allows for two computer-controlled opponents that play each other.

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 a 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 program 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):
       print 'i=',
       i = i + 1

 

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

 

Be sure that your assignment fulfills the requirements of the [general submission requirements].

[Marking of this assignment]