Question: In this game, the computer chooses 4 pegs each with one of 6 colors. This is the color - based predecessor to Wordle. The player

In this game, the computer chooses 4 pegs each with one of 6 colors. This is the color-based predecessor to Wordle. The players job is then to guess the colors that the computer has chosen in the proper order. After each guess by the player, the computer will then give two numbers as feedback. The first number is how many pegs are the proper color and in the proper position. The second number is how many pegs are the proper color, but not in the correct position.
What you need to do:
- Generate a random computer guess of four colors out of: o Red, Orange, Yellow, Green, Blue, Purple
- Read a guess from the user as a string of colors (see example below)
- Score the guess, and report the two values back to the user
- Allow the user to continue to guess until they get it correct, or reach 10 turns and they lose.
- Allow the user to play the game multiple times
Generating random numbers in C is a two-step part. First, we need to seed the random number generator once per program. The idiom to do this is: srand((unsigned int)time(NULL)); When we need random numbers, we can use the rand() function. It returns an unsigned integer between 0 and RAND_MAX. We can use modulus to reduce it to the range we need: int value = rand()%(high - low +1)+ low;
Example:
Welcome to Mastermind!
Would you like to play? yes
Enter guess number 1: rrrr
Colors in the correct place: 1
Colors correct but in wrong position: 0
Enter guess number 2: rrgg
...

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!