forked from luckywaynexu/public-good-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulihezuo.m
61 lines (61 loc) · 1.3 KB
/
gulihezuo.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
52
53
54
55
56
57
58
59
60
61
function gc=gulihezuo(G,L,gc)
%统计最终矩阵中孤立合作者的数目
%先考虑矩阵的四个角
%左上角
if G(1,1)==1%合作
if G(1,2)==-1&&G(2,1)==-1%孤立合作者
gc=gc+1;
end
end
%右上角
if G(1,L)==1
if G(1,L-1)==-1&&G(2,L)==-1
gc=gc+1;
end
end
%左下角
if G(L,1)==1
if G(L,2)==-1&&G(L-1,1)==-1
gc=gc+1;
end
end
%右下角
if G(L,L)==1
if G(L,L-1)==-1&&G(L-1,L)==-1
gc=gc+1;
end
end
%考虑矩阵的边
for i=2:L-1
if G(i,1)==1%左边
if G(i-1,1)+G(i,2)+G(i+1,1)==-3
gc=gc+1;
end
elseif G(i,L)==1%右边
if G(i-1,L)+G(i,L-1)+G(i+1,L)==-3
gc=gc+1;
end
end
end
for j=2:L-1
if G(1,j)==1%上边
if G(1,j-1)+G(2,j)+G(1,j+1)==-3
gc=gc+1;
end
elseif G(L,j)==1%下边
if G(L,j-1)+G(L-1,j)+G(L,j+1)==-3
gc=gc+1;
end
end
end
%考虑矩阵内部
for i=2:L-1
for j=2:L-1
if G(i,j)==1
if G(i,j-1)+G(i-1,j)+G(i+1,j)+G(i,j+1)==-4
gc=gc+1;
end
end
end
end
end