% mfile MoveFishDown
% decide whether to move fish down, move, mark as having moved, and update boundaries
% decide whether fish can move down
  move( 1:d+1, 2:d+1 ) = fish( 1:d+1, 2:d+1 ) & ...
          ( fishdir( 1:d+1, 2:d+1 ) == 4) & ( ~fish( 2:d+2, 2:d+1 ) ) & ...
          ( ~shark( 2:d+2, 2:d+1 ) );
% decide whether fish can breed
  fbreed ( 1:d+1, 2:d+1 ) = ( fishage(  1:d+1, 2:d+1 ) > FBREED ) & ...
         move( 1:d+1, 2:d+1 );
% update fish positions
  fish( 2:d+1, 2:d+1 ) = ( fish( 2:d+1, 2:d+1 ) & (~move( 2:d+1, 2:d+1 ) ) ) ...
          | move( 1:d, 2:d+1 ) | fbreed( 2:d+1, 2:d+1 ) ;
% update fish ages
  fishage( 2:d+1, 2:d+1 ) = ( fishage( 2:d+1, 2:d+1 ) .* ...
                             (~move( 2:d+1, 2:d+1 )) ...
                             .* fish( 2:d+1, 2:d+1 ) ) + ...
                             ( fishage( 1:d,   2:d+1 ) .* move( 1:d, 2:d+1 ) );
  fishage( 2:d+1, 2:d+1 ) = fishage( 2:d+1, 2:d+1 ) .* (~shark( 2:d+1, 2:d+1 ));
% mark fish as having moved
  fishdir( 2:d+1, 2:d+1 ) = fishdir( 2:d+1, 2:d+1 ) .* ( ~move( 1:d, 2:d+1 ))...
                            .* (fishdir( 2:d+1, 2:d+1 ) ~= 4);
  UpdateBoundaries;
  if dbug == 1, 
      subplot(224), plotsharkfish;
      disp(['i= ',num2str(i),' just moved down']), keyboard, 
  end
