function p = infect(Pop,i,j,n,m,tau)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  function p = infect(Pop,i,j,n,m,tau)                  %
%  for                                                   %
%  A solution to CSE Your Homework Assignment Project 5  %
%  Models of Infection: Person to Person                 %
%  Dianne P. O'Leary   09/03                             %
%                                                        %
%  This function checks the North, South, East, and      %
%  West neighbors of Pop(i,j) (if they exist)            %
%  on its  n x m  grid                                   %
%  and, through a Monte Carlo trial with infection rate  %
%  tau, decides whether Pop(i,j) is infected by any of   %
%  them.                                                 %
%                                                        %
%  On output, p=1 if Pop(i,j) is infected, and           %
%  p=0 otherwise.                                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



t = 0;

if (i > 1)
  if (Pop(i-1,j)>0)
     t = (rand < tau);
  end
end

if (i < n)
  if (Pop(i+1,j)>0)
     t = t + (rand < tau);
  end
end

if (j > 1)
  if (Pop(i,j-1)>0)
     t = t + (rand < tau);
  end
end

if (j < m)
  if (Pop(i,j+1)>0)
     t = t + (rand < tau);
  end
end

p = 0;
if (t > 0)
   p = 1;
end
