function T = walker_2d_update ( T )

%% WALKER_2D_UPDATE updates a random walk grid by one step.
%
  [ nn1, nn1 ] = size ( T );

  TN = zeros ( nn1, nn1 );

  for i = 1 : nn1
    for j = 1 : nn1
      for k = 1 : T(i,j)
        l = randi ( [ 1, 8 ] );
        if ( l == 1 && i + 1 <= nn1 )
          TN(i+1,j) = TN(i+1,j) + 1;
        elseif ( l == 2 && 1 <= i - 1 )
          TN(i-1,j) = TN(i-1,j) + 1;
        elseif ( l == 3 && j + 1 <= nn1 )
          TN(i,j+1) = TN(i,j+1) + 1;
        elseif ( l == 4 && 1 <= j - 1 )
          TN(i,j-1) = TN(i,j-1) + 1;
        else
          TN(i,j) = TN(i,j) + 1;
        end
      end
    end
  end

  T = TN;

  return
end
