The game takes place on an M-by-N board. Each square is occupied by a cooperator (C) or a defector (D).
In a given round each square plays prisoner's dilemma with each of its immediate neighbors, including itself. Each square has either 4, 6, or 9 such neighbors. The payoffs are as follows
C vs. C, each receives 1 C vs. D, C receives 0 and D receives b D vs. D, each receives 0The score of a square is the sum of the neighborly payoffs.
At the next generation, each square assumes the identity of the winner (highest scorer) of the last neighborly round.
For example, the score of the board
D D D b 2b 2b D D C D C C is 3b 5 4 and so if b=1.9 the next generation is D D C C C C 3 5 4 D D CWe monitor the game's progress by
painting a square blue when C remains C painting a square red when D remains D painting a square yellow when C becomes D painting a square green when D becomes CYou will write the
function evo(M,N,b,gen)
after 10 and 100 generations respectively. It is fascinating to watch the fraction of cooperators ebb and flow. You will want to quantify this in a graph of the form
I recommend that evo delegate to three subfunctions
function S = score(A,b) function An = advance(S,A) function evodisp(A,An)
Your work will be graded as follows
Final Draft, 110 points total
8 pts for headers CONTAINING detailed USAGE
8 pts for further comments in code
4 pts for indentation
20 pts for correct score function
30 pts for correct advance function
20 pts for correct evodisp function
in the following, suppose M=N=99, b=1.9,
starting from the C board with lone center D
5 pts for jpeg of generation 101
5 pts for jpeg of generation 200
10 pts for jpeg of Fraction of Cooperators, up to gen=300