
Ncycles=50;
Nmembers=99;
Ndiseases=4;
killed_by_deases=zeros(Ncycles,Ndiseases);

member_stat=zeros(1,Nmembers);
% let's make them alive
member_stat=member_stat+4;

% let's disease couple unlucky individuals
Ndiseased2=10;
for i=1:Ndiseased2
	m=ceil(Nmembers*rand());
	member_stat(m)=2;
end
Ndiseased3=40;
for i=1:Ndiseased3
	m=ceil(Nmembers*rand());
	member_stat(m)=3;
end

%plot the initial colony status
figure(1);
bar(member_stat);
figure(2);
bar(killed_by_deases);
drawnow('expose');
%pause; %wait for user

for c=1:Ncycles
	if c~=1
		killed_by_deases(c,:)=killed_by_deases(c-1,:);
	end
	% spread diseases
	for i=1:Nmembers
		disease = member_stat(i);

		[self_action, ...
		disease_left_neighbor, ...
		disease_right_neighbor] = disease_outcome(disease);
		
		if (i-1 >= 1)
			% we have left neighbor
			if ( disease_left_neighbor == true)
				if(member_stat(i-1) ~= 1)
					member_stat(i-1)=disease;
				end
			end
		end

		if (i+1 >= Nmembers)
			% we have right neighbor
			if ( disease_left_neighbor == true)
				if(member_stat(i-1) ~= 1)
					member_stat(i-1)=disease;
				end
			end
		end

		if ( (self_action == 1) && (disease ~=1) )
			%calculate deth toll
			killed_by_deases(c,disease)=killed_by_deases(c,disease)+1;
		end
		member_stat(i)=self_action;
	end
	%plot the current colony status
	figure(1);
	bar(member_stat);
	title('health level among members');
	figure(2);
	bar(killed_by_deases(:,[2,3]),'stacked');
	legend('death by hard to heal', 'death by highly contagious');	
	title('death toll');
end



		
