Advertisement
moathon

mastermind guesser

Oct 20th, 2019
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.61 KB | None | 0 0
  1. /*
  2.  * File:   newmain.cpp
  3.  * Author: Mohammad, Mohammad
  4.  *
  5.  * Created on October 20, 2019, 5:04 PM
  6.  * This version does not allow duplicate collors, not because I can't implement it, but rather because
  7.  * I'd like to use duplicate colors in the next mastermind example we will do. (Using Donald Knuth's algorith.)
  8.  */
  9.  
  10. #include <cstdlib>
  11. #include <iostream>
  12. #include <stdlib.h>     /* srand, rand */
  13. #include <time.h>
  14. using namespace std;
  15. void check(bool a,bool b);
  16. /*
  17.  *
  18.  */
  19. int main(int argc, char** argv) {
  20.     srand (time(NULL));
  21.     char aray[359][3];
  22.     int dontrepeat[4]={10,10,10,10};
  23.     char norepeats[359][3];
  24.     char thecode[4];
  25.     int correct[4]={0,0,0,0};
  26.     char colors[6]={'R','P','Y','G','B','O'};
  27.     char codes[4];
  28.     int curnumb;
  29.     int numbs[6]={1,2,3,4,5,6};
  30.     cout<<"Welcome to masterind! This game pits you against a computer!"<<endl;
  31.     cout<<"See if you can outwit the computer by making the uncrackable code!"<<endl;
  32.     cout<<"Color codes as follows: R (Red), P (Pink), Y (Yellow), G (Green), B (Blue) and O (Orange)"<<endl;
  33.     cout<<"Enter a code of colors (no duplicates) and see if you can beat the computer!"<<endl;
  34.     cout<<"Color 1"<<endl;
  35.     cin>>thecode[0];
  36.     cout<<"Color 2"<<endl;
  37.     cin>>thecode[1];
  38.     cout<<"Color 3"<<endl;
  39.     cin>>thecode[2];
  40.     cout<<"Color 4"<<endl;
  41.     cin>>thecode[3];
  42.     cout<<"The code is "<<thecode[0]<<thecode[1]<<thecode[2]<<thecode[3]<<endl;
  43.     for(int z=0;z<10;z++){
  44.     for(int i=0;i<4;i++){
  45.        int guess = rand() % 6;
  46.        codes[i]=colors[guess];
  47.     }
  48.     cout<<"The computer guessed "<<codes[0]<<codes[1]<<codes[2]<<codes[3];
  49.     cout<<" and the code is "<<thecode[0]<<thecode[1]<<thecode[2]<<thecode[3]<<endl;
  50.     for(int i=0;i<4;i++){
  51.         if (codes[i]==thecode[0]){
  52.                 correct[0]=1;
  53.             }
  54.             if (codes[i]==thecode[1]){
  55.                 correct[1]=1;
  56.             }
  57.             if (codes[i]==thecode[2]){
  58.                 correct[2]=1;
  59.             }
  60.             if (codes[i]==thecode[3]){
  61.                 correct[3]=1;
  62.             }
  63.         if (codes[i]==thecode[i]){
  64.             correct[i]=2;
  65.         }
  66.     }
  67.     cout<<"The computer got "<<correct[0]<<correct[1]<<correct[2]<<correct[3]<<" where 0 is wrong, 1 is wrong position, and 2 is right."<<endl;
  68.     if (correct[0]==2&&correct[1]==2&&correct[2]==2&&correct[3]==2){
  69.         cout<<"The computer cracked the code! Voilla!"<<endl;
  70.         return 1;
  71.     }
  72.     }
  73.     cout<<"The computer failed to beat mastermind... alas... you win."<<endl;
  74.     return 0;
  75. }
  76.  
  77. void check(bool a,bool b)
  78. {
  79.     cout<<" "<<endl;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement