

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CSE 231 Summer 2009
Assignment Overview This project focuses on programming with loops and conditionals, as well as our first project working extensively with strings. It is worth 60 points (6% of your overall grade). It is due Monday, June 1st^ before midnight. The Problem We are going to play the classic game Mastermind. If you don’t know the rules, you can look at: http://www.cut-the-knot.org/ctk/Mastermind.shtml We are going to play the game with a slight variation, using numbers instead of colors. Thus each guess will be a 4 digit number, and the key (the number being decoded) will be a 4 digit number. We will also stipulate that no number will repeat in the key. Thus 1234 is a legal key but 1123 is not legal and should not be used in our game. (To play the game on the web site then, you need 10 colors and 4 pegs.) In our game, you provide the key to be guessed at the start of the program, and then your program allows a player to try and guess the entered key. The program does not generate a random key so you can more easily test your program. Your program does not try to play mastermind, it simply enforces the rules and provides feedback to the player. On each guess, your program provides two numbers. How many of the 4 numbers in the guess are exactly correct (the correct number in the correct position of the key) and how many of the guess numbers are in the key but not in the correct position. Note that those two values cannot sum to more than 4, or put another way, each digit in the guess produces at most one value. The player gets twelve guesses and if they do not get the key in 12 guesses, they lose. Program Specifications Your program will play the mastermind game as follows:
1. Prompt for the 4 digit key we will play with. No error checking here. 2. Prompt the user for a guess. a. we check to see if the guess isf exactly length 4 b. we check to see if the guess contains all numbers c. we check to see if the guess has no repeats any violation of these rules prints an error message and prompts for a guess again. Bad input does not count as a guess. 3. End the game if: a. the guess is correct. Print out a winner message b. it was the last guess (the twelth) and the guess is incorrect. Print out a loser message and the value of the key 4. If no end condition occurs, print out how many of the guess numbers are exactly right (correct number in the correct position) and how many of the guess numbers are correct but not in the correct position. Example. The key is 1234 and the guess is 4256. The feedback
would be 1 number exactly correct (2) and 1 number in the wrong position (4). That is, each digit in the guess produces at most one result (exact or wrong position).
5. You should keep a history of guesses so that the user can see how they are progressing. 6. Continue the game until an end condition occurs As an example, two programs are provided in the proj03 directory. One is called test.py and the other master.pyc. The pyc file is a compiled solution to the problem. You can’t read it, but you can run it using the test.py file. Move both files to your directory and then double click the test.py file. It should play the game for you. Remember , move both files and place them in the same location! Deliverables proj03.py -- your source code solution (remember to include your section, the date, project number and comments).