CSC 326 Assignment 3

Object-oriented Mastermind

Fall 1999

Due: October 18, 1999


Mastermind is a simple board game which stretches your powers of deduction. You are to write an object-oriented C++ program to implement it. The interaction is quite simple; text I/O will suffice for this assignment.

The basic idea is this: the person you are playing against arranges 4 pegs in a line. Each peg is one of six colors (multiple pegs of same color is OK). You can't see them. Your job is to guess the colors and position! You make your move (lay out 4 pegs), and your opponent gives you clues as described below. Based on the clues, you try again. Continue until you match or give up!

Rules:

 


Objects for object-oriented solution:

Board (space for 12 moves, 12 responses, and one solution)

Move (space for 4 pegs) -- player generates moves, genie generates a solution move

Response (space for 4 chits)

Genie (generates solution; generates response based on player move and solution)

Pegs (unlimited supply of each of 6 colors: red, white, green, blue, yellow, black)

Chits (unlimited supply of each of 2 colors: white, black)

Game (space for one board, and the "Run" function conducts the game).

Player (represents you. Generates moves upon your input)


This should be a good object-oriented solution. For example, the board should have a "display" function which in turn invokes the "display" function of each move, which in turn invokes the "display" function of each peg....

The "main" function should do nothing more than create a Game object then call its "run" function. If you wish, put this in a loop that allows the user to play multiple games.

The program should offer some instructions so I can interact without having to read any external documentation (e.g. good input prompts and so forth. You do not need to explain the rules.).

The main program should be in file master.cpp. Classes should be defined in .h and .cpp files separate from master.cpp. The executable should be named master.exe.

To turn in: Collect the executable and all source files into a folder called Master, and submit it to your eccentric upload folder for csc326.


Move evaluation strategy: Make two left-right passes through the move. On the first pass, look for correct pegs (matching color and position). For each correct peg, generate a black chit and mark that peg as used (in both move and solution). If all pegs are correct, game is over. Otherwise, make a second pass through the move. For each remaining unmarked peg in the move, look for an unmarked peg of the same color in the solution. If found, generate a white chit and mark that peg as used (in both move and solution).

 

 


Some example move evaluations, using character codes for colors and numbers for position.

(R=red, G=green, B=blue, K=black, W=white, Y=yellow)

Example 1

Move: 1R 2R 3W 4K, Solution: 1R 2B 3K 4R, Respose: 1 black chit, 2 white chits

Pass one:

1R matches 1R, so generate a black chit. move: 1x 2R 3W 4K, solution: 1x 2B 3K 4R

Pass two:

2R matches 4R, generate white chit. move: 1x 2x 3W 4K, solution: 1x 2B 3K 4x

3W doesn't match anything, no change.

4K matches 3K, generate white chit. move: 1x 2x 3W 4x, solution: 1x 2B 3x 4x


Example 2

Move: 1Y 2R 3Y 4K, Solution: 1W 2B 3Y 4R, Respose: 1 black chit, 1 white chit

Pass one:

3Y matches 3Y, so generate a black chit. move: 1Y 2R 3x 4K, solution: 1W 2B 3x 4R

Pass two:

1Y doesn't match anything, no change.

2R matches 4R, generate white chit. move: 1Y 2x 3x 4K, solution: 1W 2B 3x 4x

4K doesn't match anything, no change.

 


[Assignments | CSC 326 | Peter Sanderson | Computer Science | SMSU ]


Last reviewed: 7 October 1999

Peter Sanderson ( PeteSanderson@mail.smsu.edu )