// Le jeu de la vie

function B = avecbordure (A)
    S = size(A)
    l = zeros(1,S(2));
    B = [l;A;l];
    c = zeros(S(1)+2,1);
    B = [c,B,c]
endfunction

function r =vieoumort(A, i, j)
    A =avecbordure(A);
    s = A(i, j) + A(i, j + 1) + A(i, j + 2) + A(i + 1, j) + A(i + 1, j + 2) + A(i + 2, j) + A(i + 2, j + 1) + A(i + 2, j + 2);
    if A(i + 1, j + 1) == 1 & (s == 2 | s == 3) then
        r = 1;
    elseif A(i + 1, j + 1) == 0 & s == 3 then
        r = 1;
    else
        r = 0;
    end
endfunction


function B =evolution(A)
    S =size(A)
    for i = 1 : S(1) do
        for j = 1 : S(2) do
            B(i, j) =vieoumort(A, i, j);
        end
    end
endfunction


clf
V =floor(2*rand(8,8));
for i = 1 : 60 do
    Matplot(V + 8),
    V =evolution(V);
    xpause(200000);
end
