forked from luckywaynexu/public-good-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuzagame2.m
51 lines (48 loc) · 1.05 KB
/
fuzagame2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
L=50;
T=10;
r0=linspace(0.02,1,50);
r=3;
a=1.5;
w=0.5;
rs=1;rm=2;
rc=zeros(1,50);
ri=zeros(1,50);
for ci=1:50
N=ceil(L*L*r0(ci));
G=(-1)*ones(L,L);
b=randperm(L*L);
i=b(1:N);
G(i)=ceil(2*rand(1,N)-1);
P0=G;
[P0]=shouyi(G,P0,L,r,a);
for t=1:T*N
u0=ceil(rand*L);
v0=ceil(rand*L);
while G(u0,v0)==-1
u0=ceil(rand*L);
v0=ceil(rand*L);
end
y=rand;
if y<=w
[P0,G]=xuexi(G,P0,L,r,a,u0,v0,rs);
else
[P0,G]=qianyi(G,P0,L,r,a,u0,v0,rm);
end
end
n1=numel(find(G==1));
%博弈合作者的相对比例
rc(ci)=n1/N;
gc=0;%gc表示孤立合作者的数目
gc=gulihezuo(G,L,gc);
ri(ci)=gc/(L*L);%孤立合作者的绝对比列
end
figure(2)
subplot(2,1,1);
plot (r0,rc,'^-')
legend('ρc')
xlabel('ρ0')
ylabel('fraction of cooperator')
subplot(2,1,2);
plot (r0,ri,'o-')
xlabel('ρ0')
ylabel('ρi')