SAINT MARY'S UNIVERSITY
Department of Mathematics and Computing Science
CSC 465.2
Object-Oriented Programming

2003 Winter Term 2003

Class Project
The Game of Mastermind

Timeline and Software Development Notes
Software Evaluation Form: Page 1 || Page 2
These are two separate MS Word documents.

The class project for this course will involve the design and implementation of a computer version of the popular board game called Mastermind. Each team will work each week on some aspect of the development. Different teams, or even all teams, may be working on the same part of the development in a given week.

Background and Introduction

The Basic Idea of the Game of Mastermind

Mastermind is a game of skill, in which two players engage in a battle of wits and logic. One of the players is called the Codemaker, and this player chooses, then hides, a secret code, which the other player, who is called the Codebreaker, must attempt to discover. A move in the game of Mastermind consists of the following two steps:

  1. The Codebreaker supplies a guess for the secret code hidden by the Codemaker.
  2. The Codemaker then scores the Codebreaker's guess against the hidden secret code, and provides the Codebreaker with this score, as feedback to the Codebreaker to be used in preparing the next guess.

The idea is that each successive score will give the Codebreaker more information about the hidden secret code, so that successive guesses become more and more "educated", until the identity of the secret code is determined. Generally, the Codebreaker is limited to a fixed number of guesses. There may be a penalty if the Codebreaker fails to guess the secret code before this fixed number of guesses is exceeded and/or a bonus if the correct guess is made within a certain (small) number of guesses. There may also be a penalty (and perhaps a forfeit of, or a replay of, the game) if the Codemaker is found to have given the wrong information by scoring incorrectly.

There are many variations of the game. A standard one is to conduct a match, in which the players agree in advance to exchange the roles of Codemaker and Codebreaker for a given (even) number of games. The winner is the player with the smaller total number of guesses, or the larger total number if each point—that is, each guess made—is "awarded" to the Codemaker, rather than "charged" to the Codebreaker. In such a match, if there is a game in which the Codebreaker fails to guess the secret code within the maximum number of guesses permitted, the number of points for that game might be counted as one more than the maximum number of guesses allowed (as one simple example of a possible penalty scheme).

Coding, Guessing and Scoring in the Original Mastermind Board Game

In the original Mastermind board game, the necessary equipment included the following:

  1. A decoding board, containing ten rows of holes for the coding pegs and scoring pegs (or key pegs, as the scoring pegs are also called). Each of these rows contains four large holes for the coding pegs, and four smaller holes, adjacent to the larger holes, for the scoring pegs. The board also has a special row at one end, which contains just four of the larger holes. The secret code is placed in this row.
  2. A shield that either sits on, or plugs into, the decoding board, in front of the special row, and thus hides the Codemaker's secret code from the Codebreaker's view.
  3. A quantity of colored coding pegs, each of which fits into any hole of the larger size. There are six different colors, excluding both black and white, and a dozen or so pegs of each of the six colors.
  4. About forty or fifty smaller scoring pegs, divided equally between black and white. Each of these pegs will fit into any hole of the smaller size.

The Codemaker sits at the end of the board containing the special row, and begins by choosing colored pegs for the secret code and placing them in the holes of the special row, behind the shield, in any order. The pegs may be all of the same color, all different, or any combination in between. The Codebreaker then chooses colored pegs for the first guess and inserts these pegs into the first of the guess rows at the Codebreaker's end of the board. The Codemaker compares the guess with the hidden secret code and indicates to the Codebreaker the "score" for that guess by inserting the appropriate number of black and/or white pegs into the smaller holes adjacent to the guess row.

To provide the score for the current guess supplied by the Codebreaker, the Codemaker compares that guess with the hidden secret code, and determines the following two values:

  1. The number of pegs that match in both color and position in the two codes (this is called the number of exact matches)
  2. The number of pegs in the two codes that match only in color but not in position (this is called the number of color matches only)

Note that in determining these two values, the Codemaker must be careful not to count any peg more than once.

The Codemaker then inserts into the smaller holes opposite the current guess row (the row into which the Codebreaker has most recently placed a guess) a number of black pegs equal to the number of exact matches, and a number of white pegs equal to the number of color matches only. There is nothing about the placement of the black and white scoring pegs to indicate which of the guess pegs correspond to which of the secret code pegs. In other words, the positioning of the scoring pegs has no significance, only the number of each color. If neither a black peg nor a white peg is placed in one of the smaller holes, this means that the Codebreaker has used a color not found in the secret code. And, by extension, if no black or white pegs are placed, this means that the secret code contains none of the colors chosen by the Codebreaker.

The number of black pegs, together with the number of white pegs, form the score used by the Codebreaker to assist in making the subsequent guesses, which proceed similarly until the Codebreaker either guesses the secret code, or runs out of guesses. Once played, all pegs remain in place until the end of the current game.

Both players must exercise a certain amount of care, the Codebreaker in guessing, and the Codemaker in scoring.

End-User Requirements

The end user for whom you will be working will be satisfied in the beginning with a simple console program that uses a text-based interface, as long as it simulates the board game as described above, with the user permitted to play either role and the computer taking on the opposite role. As time goes on, however, and the user's requirements are met, the user will become ever more demanding of new and expanded features that the program must provide.

Basic Initial Requirements

  1. The program must allow the user to be the Codebreaker, with the computer acting as Codemaker, or vice versa.
  2. The program must be a console program, with a text-based interface, and must
    • be menu-driven
    • provide enough on-line information so that a new user can begin playing immediately with the knowledge gained by reading that information
    • permit the user to play as many games as desired in either role during a single run of the program

Desired Extensions

  1. The user should be able to
    1. vary the size of the codes (the number of pegs in a secret code and a guess)
    2. vary the maximum number of guesses allowed
    3. decide whether or not the colors in a secret code must be distinct
    4. decide whether or not a penalty is to be assessed for not guessing the secret code within the maximum number of guesses permitted, and if so, what that penalty should be
    5. decide whether or not a bonus is to be awarded for guessing the answer quickly, and if so, how quickly and what the bonus should be

    For example, one actual version of the game (called Super Mastermind) has eight different colored pegs, and a code size of five. The program should be able to switch easily to a simulation of this version if the user desires, or (for example) to a simpler version than the standard one, with fewer pegs in the code and a smaller number of maximum guesses.

  2. The program should maintain a record of all games played in a database.
  3. The program should be able to stop a game in mid-stream, record all necessary information about the "state" of the game, and re-start that game later, even in a later session and program run (the following week, for example). The program should also be able to "back up" and re-start a game at an earlier point, if, for example, it is discovered at some point that the Codemaker has scored incorrectly. In such a case, a suitable penalty may be applied.
  4. The program should permit two human players to play over the internet.
  5. The program's simple text-based interface should be replaced with a suitable and attractive GUI.
  6. The program should include a "practice-scoring" and "puzzle" features.
  7. The program should include a "plug-in" facility, that permits any number of different codebreaking algorithms to compete against each other using the same sequence of secret codes and record the results of this "algorithm tournament".
  8. The program should have extended on-line information and help that includes
    1. a history of Mastermind
    2. tables of "facts and figures" about various forms of the game (Just how many different codes are possible in the standard game, for example?)
    3. suggested codebreaking strategies, with examples
    4. a list of references and links to relevant web sites
  9. The software should be usable by a blind person.
  10. The user should be able to conduct simulations. For example, the user should be able to give the program a secret code and a starting guess, and then have the computer show the sequence of guesses it would use to get to the secret code from the supplied starting guess. Many other such simulations are possible.