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