% mfile MoveSharkUp 
% decide whether to move sharks up, move, mark as having moved, and update boundaries
% decide whether sharks can move up
  move( 2:d+2, 2:d+1 ) = shark( 2:d+2, 2:d+1 ) & ...
          ( sharkdir( 2:d+2, 2:d+1 ) == 2 ) & ( ~shark( 1:d+1, 2:d+1 ) );
% decide whether sharks can eat
  eat( 2:d+2, 2:d+1 ) = move( 2:d+2, 2:d+1 ) & fish( 1:d+1, 2:d+1 );
% decide whether sharks can breed
  sbreed ( 2:d+2, 2:d+1 ) = ( sharkage(  2:d+2, 2:d+1 ) > SBREED ) & ...
          move( 2:d+2, 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( 3:d+2, 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( 3:d+2, 2:d+1 ) .* move( 3:d+2, 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( 3:d+2, 2:d+1 ) .* ...
                             ( move( 3:d+2, 2:d+1 ) & (~eat( 3:d+2, 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 ) ~= 2);
% 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(222), plotsharkfish;
      disp(['i= ',num2str(i),' just moved up']), keyboard, 
  end
