Hello,
I am having trouble implementing my code for Conway's Game of Life. I know that the cases for killing cells are accurate and run well but for some reason the "birthing" cases don't seem to work. I am pretty sure my code covers all the cases so I don't know why my system just dies down eventually from the lack of new cells coming to life. Here is my code:
function GameOfLife(A)B = conv2(full(A > 0),[0,0,0;0,1,0;0,0,0],'same');while trueimshow(B);drawnow; for i=2:size(B,1)-1 for j=2:size(B,2)-1 C = B(i-1:i+1,j-1:j+1); % 3x3 Matrix with i,j point @ center
if B(i,j) == 1 % Cell is currently alive
if (sum(sum(C)) < 3) || (sum(sum(C)) > 4) B(i,j) = 0; % Dies
elseif B(i,j) == 0 % Cell is currently dead
if sum(sum(C)) == 3 B(i,j) = 1; % Is born
end end end end endendend
Any ideas?
Best Answer