Mastermind | Computer Science homework help

 

Modify your version of the project to the following specifications.

1)  Randomly generate a code to break in the range of 0000 to 9999.  Use characters not integers.

2)  Include an option which test all possible guesses instead of  playing the game.  A table will be generated which is 10,000 long with a  guess starting at characters 0000 to 9999 incrementing by 1 each time.

     a)  The test will loop and test all possible guesses against your randomly chosen code.

     b)  Print the following headings

              Code   Guess  #right  #right in wrong spot   Sum

Example:   A code was randomly chosen such as 0120

              Code   Guess  #right  #right in wrong spot    Sum

              0120    0000        2                  0                       2

              0120    0001        1                  2                       3

              0120    0002        1                  2                       3

              0120    0003        1                  1                       2

              etc………….

              0120   0012         1                  3                       4

              etc……….

              0120   0120         4                  0                       4

              etc……….

              0120   2100         2                  2                       4

              etc……

              0120   9999         0                  0                       0

This is to make sure you are not double counting.  The max in any  column can be no greater than 4 and the sum can never be greater than  4.  Of course, just because that is true does not mean it is totally  correct.  That is why further checks are required.

Answer the following and check with your modified project.  

3)  How many times should 4 right come up?

4)  How many times should 3 right come up?

5)  How many times should 2 right come up?

6)  How many times should 1 right come up?

7)  How many times should 0 right come up?

8)  Answer the same for number right in the wrong spot like 3) to 7) from above. Answer the same 3) to 7) for the sum.

9)  Does your code verify this?

10)  Include an option where you can put in the code to test instead  of randomly generating the code.  Output the same table as above.  Do  the same comparison.

code

 //System Libraries
#include <iostream> //Input/Output Library
#include <cstdlib>
#include <ctime>
using namespace std;
//User Libraries
//Global Constants, no Global Variables are allowed
//Math/Physics/Conversions/Higher Dimensions – i.e. PI, e, etc…
//Function Prototypes
//Execution begins here
int main(int argc, char** argv) {
//Set the random number seed
srand(time(0)); // using srand to generate different random numbers everytime
int randomint = (rand()%5)+1; // generate a random number between 1 and 5 using rand
//Declare Variables
char colors[4];// the 4 colors of MasterMind
char ex;
//Random for loop
for(int i=0;i<4;i++){
randomint = (rand()%5)+1; // generate random number from 1 to 5 using rand function
switch(randomint){
case 1: // if randomint is 1 assign ‘R’ to colors array
colors[i] = ‘R’;
break;
case 2: // if randomint is 2 assign ‘B’ to colors array
colors[i] = ‘B’;
break;
case 3: // if randomint is 3 assign ‘Y’ to colors array
colors[i] = ‘Y’;
break;
case 4: // if randomint is 4 assign ‘P’ to colors array
colors[i] = ‘P’;
break;
case 5: // if randomint is 5 assign ‘G’ to colors array
colors[i] = ‘G’;
break;
}
}
//Initialize or input i.e. set variable values
char usercolors[4]; // user array for colors input from user
// print to console output
cout <<“The colors of the game is red is R, blue is B, yellow is Y,green is G,purple is P”<<endl;
cout<<“Please use uppercase letters when you play the game”<<endl;
cout<<endl<<endl;
cout<<“Colors R,B,Y,P and G”<<endl;
cout << “Let play the game (:” << endl;
int turncounter = 0; // initialize turncounter to 0
while(turncounter != 12){ // loop 12 times
turncounter++;
cout << “Current try: ” << turncounter << endl;
for(int i=0;i<4;i++){ // Ask user 4 colors
cout << “Color ” << i << “: “;
cin >> usercolors[i];
cout << endl;
}
for(int i=0;i<4;i++){ // compare user entered colors with the random generated colors array
if(usercolors[i] == colors[i]) // if color matches then print right else wrong
cout << “Right” << ” “;
else
cout << “Wrong” << ” “;
}
cout << endl << endl;
// if all four color matches then user win else lost
if(usercolors[0] == colors[0] &&
   usercolors[1] == colors[1] &&
   usercolors[2] == colors[2] &&
   usercolors[3] == colors[3])
{
cout << “You win! Number of tries: ” << turncounter << endl;
return 0;
}else{
cout << “Nope.” << endl << endl;
}
// Ask if user wants to keep trying again or not
cout<<“do you want to exit type Y to exit or N to continue keep trying “<<endl;
cin>>ex;
if(ex==’Y’) // if user types ‘Y’ exit
return 0;
}
if(turncounter == 12){ // if turncounter is 12 user lost
cout << “You lost.):” << endl;
}
return 0;

Premium Custom Essays
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.