% SCRIPT scriptBoundedRWRevisited
%   Simulates the bounded random walk from the center of a 21X21 grid,
%   and see which grid is visited most often

M = 10000;      % try M times
S = 21;         % size of the grid
N = (S+1)/2;    % input variable of function RandomWalk2D
ns = 100;       % number of steps

counter = zeros(S, S);   % keep track of how many times each grid is visited

for k=1:M
    [x y] = BoundedRandomWalk2D(N, ns);
    for j=1:length(x)
        % increase the counter
        counter(y(j)+N, x(j)+N) = counter(y(j)+N, x(j)+N) + 1;
    end
end

mesh(1-N:N-1, 1-N:N-1, counter)
