CST8204 Lab Assignment 2: Colour Guess
This is clearly not the MasterMind[tm] game, since that is a trademark and copyright of Parker Brothers. However, it is a simple emulation of the game board and pieces for a game very similar to it. I'm sure it's just a coincidence, and that there's quite a reasonable explanation.
Your assignment is to write a C program for a simple 2-player game. Player 1 will enter a combination of colours in response to a prompt. The screen will then clear, and Player 2 will be invited to make a guess of the combination, using upper or lower case. Play continues until the maximum guesses allowed have been made, player 2 has made a correct guess, or Player 2 has conceded defeat.
|
Colour |
Code |
Colour |
Code |
Colour |
Code |
Colour |
Code |
|
Red |
R |
Orange |
O |
Yellow |
Y |
Green |
G |
|
Blue |
B |
Purple |
P |
Tan |
T |
Empty |
E |
You must also set reasonable limits on the size of the combination and the number of guesses permitted. Starting at 4 colours and 7 guesses is reasonable, but you may change this if you wish. A useful technique is to check the length of the combination set by Player 1 and determine from that how many guesses to permit. Then when Player 2 starts, you can announce both numbers.
The reply from your program to a guess will consist of the colour names Black and White, where Black indicates a correct colour in the correct place and White, a correct colour in the wrong place. For example, if the pattern to guess is YRBG and the guess is YGBT, your program would reply with 2 Black (for Y in position 1 and B at 3) and 1 White (for the G in the wrong place, at 2).
As a screen sequence, it might look like this (documentation removed for clarity):
Player 1, please enter your colour combination: YRBG
< screen clears >
You have 7 tries for a 4 colour combination.
No win yet, you get 2 Black and 1 White
. . .
Robert, enter your guess number 6: yrbg
Robert wins! You now have 3 wins and 2 losses.
Play another game? (Y/N):
You will prompt for or accept as a command argument and use player 2's name. You must check for and report duplicate guesses (don't count them as guesses), and keep track of games won and lost. You may not make use of any files, but store all information in arrays.
The game should be self-documenting, telling the players via brief but complete screen messages how to play.
Use system("clear"); to clear the screen. This is an exception, since normally the system() call may not be used for assignments or labs in this course.
At the start of your lab in three weeks time (week 6), you will hand in your assignment as defined in the Submission Standards document. This will include all sections as defined in that document, including your output from the script command to show:
Your tests of your colour-guessing program according to your test plan (string too long, guess too short, invalid colour code, etc.). Be thorough!
A session of at least 3 complete games, showing Player 2 both winning and losing, as well as conceding by using ^D (Control-D) at the prompt for a guess to show that an end-of-file has occurred on stdin.