CS110 Introduction to Computing
Fall 2006

Lab Assignment#9

Problem: Write a program that implements the game of Mastermind!.

The program selects a random set of digits (i.e. a secret code), whose length is specified by a variable say digits, and the user has to guess them in a finite number of rounds, also specified by a variable say rounds. The program reports the number of digits selected by the user that match the hidden digits. The number of digits that are correctly placed as well as incorrectly placed are reported. For example, if the secret code is 1 2 2 5, and the user guesses 3 1 2 2, then the program reports that there is 1 digit in place (the 2 that is the third digit), and 2 digits out of place (1 and the other 2).

The game stops when the user guesses the digits selected by the program or when the maximum number of rounds allowed has been reached. If the user did not guess the secret code, print out the code as well.

Getting Started

Remember to build up your solution incrementally, add and test one function at a time.

Your program should meet the following requirements:

What you will need to do:

  1. Make sure you have read chapter 11 and understand the examples and library functions presented there.
  2. Do the design first: plan out a complete sketch prior to writing your program.
  3. Split your program into functions and make an incremental implementation plan.
  4. Make sure you do the above steps prior to entering the lab (or using your computer).
  5. Test and debug your program until it produces correct results.
  6. When done, print out the final version your your program and also a printout showing your program's sample outputs for at least two runs of a game. Demonstrate correctness on the calculation of inplace and out-of-place digits.
  7. Make a blog posting saying that you have completed the assignment and also write up any logistical or other issues/questions raised while working on this assignment. Also write about your level of confidence on the concepts learned so far.
  8. ALL work in this course should be done individually without any help from any person other than the class TA's and instructor(s).

Notes:

Add the following line to all your Python programs:

# File: <place name of your program file here>

# Date: <date created>

# Created by: <your name>

# Assignment: <place assignment number here>