
n=10; %number of cond cooperators 
nfr=0; %number of free riders
ntit=0; %tit for tat players

t=30; %number of periods


omega=10; %initial endowment
degcoop=0.9; %degree of cooperation imperfectness

%belief vector
b=omega*ones(n,1);
actb=omega*ones(n,1);
expb=omega*ones(n,1);

%initial strategies (what about mixed?)
s=ones(n,1);


%start loop
for i=1:t;
    
    %expectation formation
    b=expb+0.5*(mean(actb)-expb); %adaptive expectations
    %b=actb; %naive exp
      
    %payoff function
    u=omega-s+0.5*sum(s);
    
    %strategy
    s=degcoop*b;       %conditional cooperator, does a percentage of beliefs
    
    s=[s; zeros(nfr,1)];    %add the free riders
    
    what=ceil(rand(ntit,1)*length(actb));
    
    s=[s; actb(  what ) ] ;    %add tit for tat players
    
    actb=s;
    expb=b;
    
    meancont(i)=mean(s);
    meanbel(i)=mean(b);
end

figure(1)
plot(meancont)
hold all
plot(meanbel)
xlabel('period')
legend('average contribution','average belief')





