Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: newmain.cpp
- * Author: Mohammad, Mohammad
- *
- * Created on October 20, 2019, 5:04 PM
- * This version does not allow duplicate collors, not because I can't implement it, but rather because
- * I'd like to use duplicate colors in the next mastermind example we will do. (Using Donald Knuth's algorith.)
- */
- #include <cstdlib>
- #include <iostream>
- #include <stdlib.h> /* srand, rand */
- #include <time.h>
- using namespace std;
- void check(bool a,bool b);
- /*
- *
- */
- int main(int argc, char** argv) {
- srand (time(NULL));
- char aray[359][3];
- int dontrepeat[4]={10,10,10,10};
- char norepeats[359][3];
- char thecode[4];
- int correct[4]={0,0,0,0};
- char colors[6]={'R','P','Y','G','B','O'};
- char codes[4];
- int curnumb;
- int numbs[6]={1,2,3,4,5,6};
- cout<<"Welcome to masterind! This game pits you against a computer!"<<endl;
- cout<<"See if you can outwit the computer by making the uncrackable code!"<<endl;
- cout<<"Color codes as follows: R (Red), P (Pink), Y (Yellow), G (Green), B (Blue) and O (Orange)"<<endl;
- cout<<"Enter a code of colors (no duplicates) and see if you can beat the computer!"<<endl;
- cout<<"Color 1"<<endl;
- cin>>thecode[0];
- cout<<"Color 2"<<endl;
- cin>>thecode[1];
- cout<<"Color 3"<<endl;
- cin>>thecode[2];
- cout<<"Color 4"<<endl;
- cin>>thecode[3];
- cout<<"The code is "<<thecode[0]<<thecode[1]<<thecode[2]<<thecode[3]<<endl;
- for(int z=0;z<10;z++){
- for(int i=0;i<4;i++){
- int guess = rand() % 6;
- codes[i]=colors[guess];
- }
- cout<<"The computer guessed "<<codes[0]<<codes[1]<<codes[2]<<codes[3];
- cout<<" and the code is "<<thecode[0]<<thecode[1]<<thecode[2]<<thecode[3]<<endl;
- for(int i=0;i<4;i++){
- if (codes[i]==thecode[0]){
- correct[0]=1;
- }
- if (codes[i]==thecode[1]){
- correct[1]=1;
- }
- if (codes[i]==thecode[2]){
- correct[2]=1;
- }
- if (codes[i]==thecode[3]){
- correct[3]=1;
- }
- if (codes[i]==thecode[i]){
- correct[i]=2;
- }
- }
- 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;
- if (correct[0]==2&&correct[1]==2&&correct[2]==2&&correct[3]==2){
- cout<<"The computer cracked the code! Voilla!"<<endl;
- return 1;
- }
- }
- cout<<"The computer failed to beat mastermind... alas... you win."<<endl;
- return 0;
- }
- void check(bool a,bool b)
- {
- cout<<" "<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement