Consider the following situation, often referred to as the prisoner\'s dilemma.
ID: 3647081 • Letter: C
Question
Consider the following situation, often referred to as the prisoner's dilemma. Two accomplices are caught by the police. The police do not have a strong case against the criminals so they offer each of them a plea deal, without giving the criminals an opportunity to consult with each other. The police offer each accomplice the opportunity to rat out the other, for a reduced sentence of 2 years, while the accomplice gets 10 years, assuming that the accomplice does not take that deal also. If both people decide to take the plea deal and rat each other out, then both get a 5 year sentence However, if neither takes the deal, they both serve 3 years in jail.The goal of this project is to take a 10 by 10 grid of prisoners, and determine over multiple iterations how many cooperators are left on the board. Assume each person is an accomplice in at most four different crimes with the four different criminals in the adjacent squares (i.e. the person in a square directly above, directly below, to the right, and to the left of its current square, respectively). Also, each person learns from the previous iteration and switches from a defecter (someone who takes the plea) to a cooperator (someone who does not take the plea), or vice versa, if the total sentence for all four crimes from the previous iteration was 20 years or more.
Examine this problem over at least 10,000 iterations, and figure out if any cooperators will be left on the board. Specifically print to the console "The percentage of cooperators is " followed by the percentage of cooperators on the grid at the end of the last iteration. Give your conclusions about what is happening and why in the report document.
Make sure your program has the following functions whose prototypes or definition are provided below.
void assignInitialValues(string grid[][10], int size); /* where each square in the grid is randomly assigned the value "C" for cooperator or "D" for defector.*/
void iterate(string grid[][10], int size); /* where each square in the grid is modified according the rules provided above.*/
double percentageOfCooperation(string grid[][10], int size);
void printPercentage(double percentage) {cout << "The percentage of cooperators is " << percentage << "% ";}