function sense = boundary_word_sense ( s )

%*****************************************************************************80
%
%% boundary_word_sense() returns the sense of a boundary word.
%
%  Discussion:
%
%    The sense is +1 if the boundary word traces the boundary of the polyomino
%    in a counterclockwise sense, and -1 otherwise.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    20 June 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    char c(*): a character string of 'u', 'd', 'l' and 'r' that
%    represents a path around the boundary of a polyomino.
%
%  Output:
%
%    integer sense: the sense.
%
  check = boundary_word_check ( s );

  if ( ~ check )
    sense = NaN;
    return
  end

  s_len = length ( s );
  s = lower ( s );

  sense = 0;
 
  for i = 1 : s_len

    if ( i < s_len )
      t = s(i:i+1);
    else
      t = [ s(s_len), s(1) ];
    end
 
    if ( is_octave ( ) )

      if ( ( t(1) == 'd' && t(2) == 'r' ) || ...
           ( t(1) == 'l' && t(2) == 'd' ) || ...
           ( t(1) == 'r' && t(2) == 'u' ) || ...
           ( t(1) == 'u' && t(2) == 'l' ) )
        sense = sense + 1;
      elseif ( ( t(1) == 'd' && t(2) == 'l' ) || ...
               ( t(1) == 'l' && t(2) == 'u' ) || ...
               ( t(1) == 'r' && t(2) == 'd' ) || ...
               ( t(1) == 'u' && t(2) == 'r' ) )
        sense = sense - 1;
      end

    else

      t = string ( t );

      if ( t == "dr" | t == "ld" | t == "ru" | t == "ul" )
        sense = sense + 1;
      elseif ( t == "dl" | t == "lu" | t == "rd" | t == "ur" )
        sense = sense - 1;
      end

    end

  end

  sense = sense / 4;

  return
end
