-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrade.m
47 lines (40 loc) · 1.12 KB
/
trade.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
function x=trade(player,opp,strategy)
if (strategy == 1) %always protectionism
x=0;
elseif (strategy == 2) %always free trade
x=1;
elseif(strategy==3) %Currency control for Currency control (titfortat)
if(isempty(opp))
x=1; % Be nice first
else
x=opp(length(opp)); % Repeat last opponent's trade
end
elseif(strategy==4) %GRIM
threshold=0.9;
s1=rand(1,1);
if(isempty(opp)) && s1<threshold % Be nice first randomly probability 0.9
x=1;
elseif (isempty(opp)) && s1>=threshold
x=1;
else
if(sum(opp)<length(opp)) && s1<threshold % After one protectionism,protectionism
% always with probability
% 0.95
x=0;
else
x=1;
end
end
else % random free trader , and protecctionist trader
s=rand(1,1);
if (strategy==5)
threshold = 0.35;
else
threshold = 0.65;
end
if(s<threshold)
x=0;
else
x=1;
end
end