$30.00
Order NowObjective:
The objective of this project is to write a program in Python that will play the game
of Mastermind where the computer chooses the hidden colors, and the human
player attempts to guess the hidden colors.
The Game:
In the game of Mastermind, one player, the codemaker (in this case the computer)
chooses four colored “pegs” in a particular order. The codebreaker (the human
player) tries to guess the chosen colors by placing four pegs in the guessed order.
For each guess, the codemaker provides a clue about how well the codebreaker
guessed. The codebreaker has 10 guesses to break the code.
Hidden Colors
The codemaker will randomly choose four colors as the hidden colors. You can
define a global list:
ALL_COLORS = [‘red’,’orange’,’yellow’,’green’,’blue’,’purple’]
The hidden colors that are chosen will not be displayed to the codebreaker.
Opponent Guess
The codebreaker will be asked to choose four colors, in a particular order, to guess
what the hidden colors are. For simplicity, you will assign a number to each color so
it is easier for the user to enter a guess. Your display message will look like the
following:
—————————–
Make a guess of four colors:
0 – red
1 – orange
2 – yellow
3 – green
4 – blue
5 – purple
—————————–
Guess color:
The Clue
Once the codebreaker has made a guess, your program will calculate a clue to give
some information about how good the guess is. The clue will consist of the
following:
2 – If the guess has a correct color in the correct position
1 – If the guess has a correct color, but in the wrong position
Note that the order of the elements of the clue should not indicate anything about
which colors are correct.
Examples
1) If the hidden colors are:
[‘orange’, ‘purple’, ‘blue’, ‘yellow’]
and the guess is:
[‘orange’, ‘red’, ‘red’, ‘blue’]
then the clue would be:
[1, 2]
The 1 because the blue guess is a correct color but in the wrong position. And
the 2 because the orange guess is the correct color in the correct position.
2) If the hidden colors are:
[‘red’, ‘blue’, ‘green’, ‘blue’]
and the guess is:
[‘red’, ‘red’, ‘yellow’, ‘yellow’]
then the clue would be:
[2]
Note that the ‘red’ in the second position of the guess does NOT produce a 1
because the ‘red’ in the first position of the hidden colors is already accounted
for by the 2 in the clue.
Game Play
In your program, you will allow the user to make up to 10 guesses. After the game is
done, whether the user guesses correctly, or exhausts all 10 guesses, your program
will ask the user if they would like to play again.
Random Code Generation
The secret code will be generated by your program randomly. In order to allow
Gradescope to test this program, we will use a random number generator with a
chosen seed value. This way whenever the same seed value is used, the same secret
code will be generated.
The program should include the following code to allow for this:
● At the top of the program:
import random
● In the definition of the main function:
def main(seedIn):
● The first line of code in the main function:
random.seed(seedIn)
● In the function that generates the secret code, uses the randint function.
Testing Requirements:
You are required to use functions when writing this program. You have some
freedom in how you implement this program. There are two function are required
to be defined as specified below so that Gradescope can test the code:
Check the Guess:
This fucntion will check the user’s guess and provide a clue. The function skeleton
looks like this:
def checkGuess(guess, secret):
return clue
where guess is a list of colors that the user has guessed, secret is the secret list of
colors that the computer has generated, and clue is a list representing the clue to
the user. The clue should be a list of 1s and 2s, where all 1s appear in the list
before all 2s. If there are no matches, the clue should be an empty list.
Main Function:
The main function should take one parameter, a seed value. This will be used to
seed the random number generator so that when we test the program, we can
predict which secret code will be generated. The main function skeleton should be:
def main(seedValue):
return
The first line of code in the main function should be:
random.seed(seedValue)
The rest of the main function will be your code to call your other functions and run
the overall program.
Sample Output:
The following are examples of what your output should look like in various
scenarios. Note the seed value fed to the main function in each example. This will
help you test your code for the same scenario.
Seed Value 1:
Seed Value 1422:
Seed Value 1223:
Seed Value 4887:
Seed Value 781:
Play Again:
Error Handling:
No More Guesses:
…
Program Requirements:
Your program should meet the following requirements:
1) Your program should work correctly. Your program should do at least the
following correctly:
a. Randomly choose the hidden colors.
b. Ask the user to make a guess of the colors.
c. Test the guess and provide a correct clue to the user.
d. Allow the user to guess at most 10 times.
e. Tell the user if the guess was correct.
2) Your program should use good modular design. It should use functions for
each of the main tasks of the program.
3) Your program should be well-documented. This should include your name
and an overall description of the program at the top of the file. It should also
include a description of any algorithms that are used in the code.
4) Your program should use well-named functions and variables. The code
should be simple to read and understand what is going on given the names of
the functions, and variables along with the comments in the code.
What to Submit:
Please submit your code in a file called projMastermind.py to Gradescope in
the assignment called Programming Project – Mastermind.
NOTE: DO NOT use Gradescope to test and debug your code. You should be doing all
of your testing and debugging in IDLE. Once you are confident that the code is
correct, you can submit to Gradescope.
More About Mastermind:
For other descriptions of the game of Mastermind, see these links:
https://www.wikihow.com/Play-Mastermind
https://www.ultraboardgames.com/mastermind/game-rules.php
Grading the Assignment:
See the Grading Rubric for the Mastermind Programming Project to see how the
assignment will be graded.
WhatsApp us