function [threshold] = calculatethreshold (A,x,y)
%A is the coral matrix, while x,y determine the location of the cell in
%question.
maxX=size(A,1);
maxY=size(A,2);
polypsabove= sum(A(x,y:maxY));
lightfactor = 2*polypsabove; %More polyps above this cell exist, greater the threshhold is and less likely to grow.
crowdingfactor = A(x+1,y)+A(x-1,y)+A(x,y+1)+A(x,y-1)+A(x+1,y+1)+A(x+1,y-1)+A(x-1,y+1)+A(x-1,y-1); % More polyp around it, the more nutrients needed. Simulates competition. Include diagonals because lolwhynot
threshold = lightfactor + crowdingfactor;