% THIS PROGRAM REPLICATES THE HAWK, DOVE, LAW-ABIDER MODEL IN DISCRETE TIME
% Adapted from Gilbert & Troitzsch, Matlab implementation by James Kitts, 2005
% This code is to be used in the context of a lab exercises, from Soc 537
% Adapted by CK to a simple Hawk-Dove Game
%-----------------------------------------------------------------------------
% ---------------------------------------------------------------------
% VERSION IN SCALAR ALGEBRA NOTATION
% ---------------------------------------------------------------------
clc; clear all; close all; % clear screen, variables & functions, close figures
% PARAMETERS
%pay_doves=[2.0 0.0 ]; % payoff for doves against doves/hawks
%pay_hawks=[10 -4.5 ]; % payoff for hawks against doves/hawks
pay_doves=[1 4 ]; % payoff for doves against doves/hawks
pay_hawks=[0 2 ]; % payoff for hawks against doves/hawks
%pay_lawab=[6.0 -2.5 5.0]; % payoff for lawabiders against doves/hawks/lawabiders
maxt=150; % number of iterations to run
% INITIAL CONDITIONS
p_hawks(1)=.1; % proportion hawks
p_doves(1)=.9; % proportion doves
%p_lawab(1)=.05; % proportion lawabiders
for t=1:maxt-1
% Fitness for each strategy is payoff against each other strategy j weighted by frequency of j
fit_hawks = p_doves(t)*pay_hawks(1) + p_hawks(t)*pay_hawks(2);
fit_doves = p_doves(t)*pay_doves(1) + p_hawks(t)*pay_doves(2);
% fit_lawab = p_doves(t)*pay_lawab(1) + p_hawks(t)*pay_lawab(2) + p_lawab(t)*pay_lawab(3);
% Global mean fitness (fitness of all i, weighted by frequency of i)
meanfitness = fit_hawks*p_hawks(t) + fit_doves*p_doves(t)
% Adjustment in proportion of strategy i is fitness of i minus the mean fitness
adj_hawks = (fit_hawks-meanfitness);
adj_doves = (fit_doves-meanfitness);
% Dynamic equations --- Delta = current_proportion * adjustment
p_hawks(t+1)= p_hawks(t) + p_hawks(t)*adj_hawks;
p_doves(t+1)= p_doves(t) + p_doves(t)*adj_doves;
end;
plot(1:maxt,p_doves,1:maxt,p_hawks);
legend('Dove','Hawk'); xlabel('Time'); ylabel('Proportion');