% mfile MoveSharkDown
% decide whether to move sharks down, move, mark as having moved, and 
% update boundaries
% decide whether sharks can move down
  move( 1:d+1, 2:d+1 ) = shark( 1:d+1, 2:d+1 ) & ...
          ( sharkdir( 1:d+1, 2:d+1 ) == 4) & ( ~shark( 2:d+2, 2:d+1 ) );
% decide whether sharks can eat
  eat( 1:d+1, 2:d+1 ) = move( 1:d+1, 2:d+1 ) & fish( 2:d+2, 2:d+1 );
% decide whether sharks can breed
  sbreed ( 1:d+1, 2:d+1 ) = ( sharkage(  1:d+1, 2:d+1 ) > SBREED ) & ...
           move( 1:d+1, 2:d+1 );
% update shark positions
  shark( 2:d+1, 2:d+1 ) = ( shark( 2:d+1, 2:d+1 ) & (~move( 2:d+1, 2:d+1 )))|...
          move( 1:d, 2:d+1 ) | sbreed( 2:d+1, 2:d+1 ) ;
% update shark ages
  sharkage( 2:d+1, 2:d+1 ) = ( sharkage( 2:d+1, 2:d+1 ) .* ...
                              (~move( 2:d+1, 2:d+1 )) ...
                             .* shark( 2:d+1, 2:d+1 ) ) + ...
                             ( sharkage( 1:d,   2:d+1 ) .* move( 1:d, 2:d+1 ) );
% update time since sharks' last meal
  sharkeat( 2:d+1, 2:d+1 ) = ( sharkeat( 2:d+1, 2:d+1 ) .* ...
                             (~move( 2:d+1, 2:d+1 )) ) + ...
                             ( sharkeat( 1:d,   2:d+1 ) .* ...
                             ( move( 1:d, 2:d+1 ) & (~eat( 1:d, 2:d+1 )) ) );
% mark shark as having moved
  sharkdir( 2:d+1, 2:d+1 ) = sharkdir( 2:d+1, 2:d+1 ) .* ...
                          ( ~move( 1:d, 2:d+1 )) .* ...
                          (sharkdir( 2:d+1, 2:d+1 ) ~= 4);
% update (eaten) fish positions
  fish( 2:d+1, 2:d+1 ) = fish( 2:d+1, 2:d+1 ) & (~shark( 2:d+1, 2:d+1 ) );
% update (eaten) fish ages
  fishage( 2:d+1, 2:d+1 ) = fishage( 2:d+1, 2:d+1 ) .* (~shark( 2:d+1, 2:d+1 ));
  UpdateBoundaries;
  if dbug == 1, 
      subplot(224), plotsharkfish;
      disp(['i= ',num2str(i),' just moved down']), keyboard, 
  end
