%  Move fish randomly but restricted to lie on grid
%  At most one fish can occupy a grid cell position
%  Inputs (run fish4init to get sample inputs)
%    fisho = list of original fish positions
%    d = size of grid to put fish on (1:d,1:d)
%    n = number of time steps to run
%  Outputs:
%    plot of fish positions
%
%  Other routines used: plotfish MoveFishEast, MoveFishNorth, 
%                       MoveFishSouth, MoveFishWest, updateboundaries
%
%  discretize original fish positions onto grid
%  (add an extra row and column at all sides to accomodate toroidal geometry)
   fish = zeros(d+2,d+2);
   where = max( min( [ round(real(fisho)), round(imag(fisho)) ], d), 1);
   wherelin=where(:,1)+where(:,2)*d;
   fish(wherelin)=ones(length(wherelin),1);
   rand('seed',0);
   hold off, clg
   dbug = 0;
%
%  loop over time steps
   for i=1:n,
      oldfish=fish;
%
%     pick a random direction (1=E, 2=N, 3=W, 4=S, later 0 = no move)
      direction = round( 4 * rand(d+2,d+2) + .5);
%
%     update boundaries
      updateboundaries

      MoveFishEast
      MoveFishNorth
      MoveFishWest
      MoveFishSouth
%
%     plot fish positions
      plotfish, 
   end
