Question: I need some help starting the code for this game. Write a Python program that will allow the user to play the Mastermind game. The
I need some help starting the code for this game.
Write a Python program that will allow the user to play the Mastermind game. The game should randomly choose a pattern for the secret color code which is made of 4 color "pegs". The pegs available for making the code are blue, red, green, yellow, purple, and pink . A color can be used more than once in the secret code.
Generate the secret code using random numbers from 1 through 6. The numbers will represent the colors as follows: 1 for blue, 2 for red, 3 for green, 4 for yellow, 5 for purple, and 6 for pink. The chosen secret code should be stored in a list in the order they appear in the secret code. Use the function described in the following paragraph to convert this list of integers to a list of strings representing the color names of the pegs in the secret code.
Create a function that will take a list of integers as it's parameter. The function should use a for loop to convert the list of integers to a list of strings containing the color names. For example, if the integer stored in one of the spots in the list is 1, you will change the value stored in the list to the string "blue", 2 will become "red", 3 will become "green", etc. The function should return the list of strings to the caller.
During the play of the game, the player will be allowed to guess the secret code up to 8 times. For each guess, the player will pick 4 colored pegs in the order they think they appear in the secret code. Make sure you ask for each colored peg separately from the user having them enter integers, i.e.1 for blue, 2 for red, 3 for green etc. Store their picks in a list in the order they give them to you. You can then use your function to convert them to the color strings like you did for the secret code.
By comparing the two lists, the game must give the player feedback using black and white "pegs" with the following meanings:
-a black peg means a correct color was chosen and it was put in the correct position.
-a white peg means a correct color was chosen but it was in the wrong position
Store the black and white pegs in a list and print the list for the user to see their feedback for that guess. All black pegs should be presented first to the user in the feedback, followed by white. Remember, if a guess is awarded a black peg for being the right color in the right spot, it is NOT also awarded a white peg. Thus, you will need to make sure you don't award feedback for the same guess twice.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
