% mfile MoveFishRight
% decide whether to move fish right, move, mark as having moved, and update boundaries
% decide whether fish can move right
  move( 2:d+1, 1:d+1 ) = fish( 2:d+1, 1:d+1 ) & ...
          ( fishdir( 2:d+1, 1:d+1 ) == 1) & ( ~shark( 2:d+1, 2:d+2 ) ) & ...
          ( ~fish( 2:d+1, 2:d+2 ) );
% decide whether fish can breed
  fbreed ( 2:d+1, 1:d+1 ) = ( fishage(  2:d+1, 1:d+1 ) > FBREED ) & ...
         move( 2:d+1, 1: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( 2:d+1, 1:d ) | 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( 2:d+1, 1:d   ) .* move( 2:d+1, 1:d ) );
  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( 2:d+1, 1:d ))...
                            .* (fishdir( 2:d+1, 2:d+1 ) ~= 1);
  UpdateBoundaries;
  if dbug == 1, 
      subplot(221), plotsharkfish;
      disp(['i= ',num2str(i),' just moved right']), keyboard, 
  end
