Programming Assignment 3 - Architecture and Assembly Language | CMPSCI 201, Assignments of Computer Science

Material Type: Assignment; Professor: Fu; Class: Architc&Assembly Lng; Subject: Computer Science; University: University of Massachusetts - Amherst; Term: Spring 2009;

Typology: Assignments

Pre 2010

Uploaded on 08/19/2009

koofers-user-eui
koofers-user-eui 🇺🇸

9 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
UMass Amherst Department of Computer Science Handout 12
CMPSCI 201: Architecture and Assembly Language April 23, 2009
Instructor: Prof. Kevin Fu
Programming Assignment 3
Th is p rogramming assignment has two parts:
Pre limi nary S ub mis sio n (du e Fr iday, May 1st , be gi nni ng of disc us si o n)
Final S ubmis sio n (due Thursd ay, May 7th, begi nni ng of l ectur e)
We will not accept la te preliminary submissions ( no use of freebie allowed). However, we are
grant ing a slight ex tension if you cho ose t o use your late f reebie f or th e final submission. If
you have a f reebie remai ning, you may submit your late f i na l assig n men t b y Sa turda y,
May 9th. If you al ready used your la te freebie, you are no t eligible for this extensio n. Pl ease
con tact you r TA well ahead of the deadline if you have a question about t hese procedures.
Th is is an indi vidual programming assignmen t. See Handout 1 (Course Infor mat io n) for our
policy o n collaborati on , pl agiarism, and la te polices. Plagiaris m will result in severe pen alt ies.
Please mark th e t op o f the progra mming assignment with your name, CS201, a nd the date.
Points may be deducted if your TA has pr oblems understa nding y our solution o r if your
solutio n is no t l egible.
This ass ignment is worth 10 po ints.
In this assignment, you will implement the popular game of Mastermind using the C
programming language. Mastermind is a code-breaking game on a board (see photo
below) that contains:
A 4-peg hidden code (bottom of photo),
Code pegs (from a variety of six colors for use in the four center columns), and
Key pegs (white and black, for use in the smaller rightmost columns).
We do not consider the smaller leftmost columns in this assignment.
pf3
pf4

Partial preview of the text

Download Programming Assignment 3 - Architecture and Assembly Language | CMPSCI 201 and more Assignments Computer Science in PDF only on Docsity!

UMass Amherst Department of Computer Science Handout 12 CMPSCI 201: Architecture and Assembly Language April 23, 2009 Instructor: Prof. Kevin Fu

Programming Assignment 3

This programming assignment has two parts:

  • Preliminary Submission (due Friday, May 1st, beginning of discussion)
  • Final Submission (due Thursday, May 7th, beginning of lecture) We will not accept late preliminary submissions (no use of freebie allowed). However, we are granting a slight extension if you choose to use your late freebie for the final submission. If you have a freebie remaining, you may submit your late final assignment by Saturday, May 9th. If you already used your late freebie, you are not eligible for this extension. Please contact your TA well ahead of the deadline if you have a question about these procedures. This is an individual programming assignment. See Handout 1 (Course Information) for our policy on collaboration, plagiarism, and late polices. Plagiarism will result in severe penalties. Please mark the top of the programming assignment with your name, CS201, and the date. Points may be deducted if your TA has problems understanding your solution or if your solution is not legible. This assignment is worth 10 points. In this assignment, you will implement the popular game of Mastermind using the C programming language. Mastermind is a code-breaking game on a board (see photo below) that contains:
    • A 4-peg hidden code (bottom of photo),
    • Code pegs (from a variety of six colors for use in the four center columns), and
    • Key pegs (white and black, for use in the smaller rightmost columns). We do not consider the smaller leftmost columns in this assignment.

The game is played by two players: a codemaker and a codebreaker. The codemaker sets up a hidden code, which contains 4 arbitrary pegs drawn from 6 colors (repetition is allowed). Then the codebreaker makes repeated guesses (4 pegs) of the hidden code until the guessed code matches the hidden code or the number of guesses reaches the limit. At each round, the codebreaker makes a guess (putting 4 pegs into the 4 center holes in a row). After each guess, the codemaker provides feedback regarding that guess by placing key pegs into the smaller holes at the right hand side of that row. A black key peg indicates that one guessed peg matches one hidden peg at the same position and in the same color. A white key peg indicates that one guessed peg matches one hidden peg in color but not in the same position. The key pegs have no order information (the positions of key pegs do not matter). In this assignment, you will simulate the game using a program that interacts with the user (the codebreaker) on the console. The computer acts as the codemaker. The rules are as follows:

  • There are 6 colored pegs in the game: R(Red), G(Green), B(Blue), Y(Yellow), P(Purple), O(Orange); 2 colored key pegs: black and white.
  • The codemaker inputs a 4-peg hidden code when the game starts.
  • At each round, the codebreaker attempts to guess the hidden code by typing values that represent 4 pegs (e.g., “RGBY” with no spaces allowed). The input is on a single line and followed by an “Enter” key.
  • Your program should respond appropriately to invalid inputs. Two cases will be examined by the TAs: o Invalid number of input pegs (other than 4). o Invalid input pegs that are not in the specified 6 colors. For either case, your program should output an error message with error type (e.g., “Invalid Input. The number of input pegs should be 4!”) and ask the user to make another input (e.g., “Please try again: ”).
  • After each guess, the computer should give feedback by comparing the guessed code with the hidden code. The feedback is then displayed on the screen. For example: “ black pegs, 1 white pegs”.
  • When the guessed code matches the hidden code (4 black key pegs represent the correct guess), the program should output “Code-breaking succeeded after # guesses” (# represents the actual number of guesses taken) and exit.
  • When the number of guesses reaches the maximum ( use 12 in your program ) and the guess is not correct, the program should output: “Code-breaking failed” and exit.

Preliminary Submission Due May 1st The purpose of the Preliminary Submission is to ensure you have designed correct abstractions for your functions. By May 1 st , you should submit a partial program that:

  • Contains at least three new function declarations with comments
  • Includes a main function that prints the welcome message to the screen
  • Compiles without errors and warnings Each function declaration must have comments descriptive enough for the reader to understand the purpose of the code, its assumptions, and its result. Our sample code provides an example of proper comments for function declarations. Submit your preliminary code in your Ed-lab course folder (name it Mastermind ). Please also bring a hardcopy of your program to your discussion section on May 1st^ so that TAs can provide feedback to you. We will post sample C code on the course Web page. Final Submission Due May 7 th Submit your final, well-documented code and a sample output of the game by putting them in your Ed-lab course folder. Comments should conform to the philosophy discussed in lecture. Difficult to follow code, bugs, and other undesired behavior will result in a loss of points. Make sure to comment at the top of your program the compiling command (e.g., g++ mastermind.c – lm – o mastermind). Each major piece of code/function should have comments descriptive enough for the reader to understand the purpose of the code, its assumptions, its effects, and its result. Avoid redundant single instruction comments when it’s obvious (e.g., “i++; // Increment i” has a redundant comment). We have zero tolerance for plagiarism. You may not share code with your peers, borrow code from past or present or future students, the Web, eBay, the Interwebz, etc. You may borrow code from the book if you document the borrowing. Keep in mind that your course staff specialize in fraud detection, pattern matching, and cryptanalysis. We have automated tools to encourage students to “stay honest” about avoiding plagiarism. See Handout 1 for how we handle cases of suspected plagiarism. The long process of prosecuting plagiarism is no fun for anyone—be it students or staff. We thank you for coding and playing with honor. If you have any questions or concerns about the plagiarism policy or want to know if a particular external resource could be used, please contact [email protected].