Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote