Write an algorithm and C++ code of two Computer Bots picking randomly card value
ID: 3827472 • Letter: W
Question
Write an algorithm and C++ code of two Computer Bots picking randomly card values (1-13) from a stack of diamond, spade, hearts and clubs cards. Find out how many times Computer Bot 1 picks Diamond Jack (value 11) and Computer Bot 2 picks Spade Queen (value 12) for an iteration of 10. Make a guess for each Bots and see how close you are in your guess. For right guess score is 100. Check your final score after 10 such guesses. Write an algorithm and C++ code of two Computer Bots picking randomly card values (1-13) from a stack of diamond, spade, hearts and clubs cards. Find out how many times Computer Bot 1 picks Diamond Jack (value 11) and Computer Bot 2 picks Spade Queen (value 12) for an iteration of 10. Make a guess for each Bots and see how close you are in your guess. For right guess score is 100. Check your final score after 10 such guesses.Explanation / Answer
#include <iostream>
#include <algorithm>
using namespace std;
int count1 = 0, count2 = 0;
static const char *card_value[] =
{
"Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten", "Jack", "Queen", "King"
};
static const char *card_type[] =
{
"Spade", "Clubs", "Diamond", "Hearts"
};
void ComputerBot1(int n)
{
if(card_value[n % 13] == "Jack" && card_type[n / 13] == "Diamond" ){
count1++;
}
}
void ComputerBot2(int n)
{
if(card_value[n % 13] == "Queen" && card_type[n / 13] == "Spade" ){
count2++;
}
}
int main()
{
srand((unsigned int)time(NULL));
int deck[52];
for (int i=0;i<52;deck[i++]=i);
for(int i=0;i<10;i++){
random_shuffle(deck, deck+52);
for_each(deck, deck+10, ComputerBot1);
}
cout << "ComputerBot1 picks Diamond Jack " << count1 << " times" << endl;
for(int i=0;i<10;i++){
random_shuffle(deck, deck+52);
for_each(deck, deck+10, ComputerBot2);
}
cout << "ComputerBot2 picks Queen Spade " << count2 << " times" << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.