matlab experiment
Jie Bao, since 2003-04-12
Experimental report (Will be online soon)
----------- strategy.m
% strategy: strategy for agent in iterated prisoner dilemma
% Jie Bao 2003-04-12
% Input:
% method
% Return value:
% 1 : Cooperation , 2 : Defect
function decision = strategy(method)
switch lower(method)
case 'nice',
%disp('Nice');
decision = 1;
case 'wicked',
%disp('Wicked');
decision = 2;
case 'random',
%disp('Random');
rr = rand;
if rr > 0.5
decision = 1;
else
decision = 2;
end
otherwise,
disp('Unknown method in "strategy" function.');
decision = 0;
end
return
------------------ b2003_04_12_pd.m
% b2003_04_12_pd: prisoner dilemma
% Jie Bao 2003-04-12
NumberOfAgent = 2;
% Basic Action
% C - Cooperation
% D - Defect
NumberOfAction = 2;
Action = ['CD'] ;
% agent's
Payoff = ones(NumberOfAgent,NumberOfAction,NumberOfAction);
% 1st dim: # of agent
% 2nd dim: agent 1's action#
% 3rd dim: agent 2's action#
% Set Payoff
Payoff(1,:,:) = [3,0 ; 5,1];
Payoff(2,:,:) = [3,5 ; 0,1];
% the game
Type1 = 'random';
Type2 = 'random';
TotalPayoff = zeros(1,NumberOfAgent);
for i = 1:2000
s1 = strategy(Type1);
s2 = strategy(Type2);
p1 = Payoff(1,s1,s2);
p2 = Payoff(2,s1,s2);
TotalPayoff = TotalPayoff + [p1 p2];
end
% show the result
for i = 1: NumberOfAgent
info = sprintf('Agent %d \"s payoff = %.2f', i , TotalPayoff(i));
disp(info)
end
[Return to Jie Bao's Homepage]