function snakes_bar ( n )

%*****************************************************************************80
%
%% snakes_bar makes a game-length bar chart for Snakes and Ladders.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    30 April 2019
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the number of games to play.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'snakes_bar\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Simulate N one-player games of Snakes and Ladders.\n' );
  fprintf ( 1, '  Use the simulation data to create bar charts\n' );
  fprintf ( 1, '  of the estimated PDF and CDF of the game length.\n' );
%
%  Default N is 500.
%
  if ( nargin < 1 )
    n = 500;
    fprintf ( 1, '\n' );
    fprintf ( 1, '  The input argument N was not supplied.\n' );
    fprintf ( 1, '  Using the default value N = %d\n', n );
  end
%
%  Simulate N games.
%  Tally the number of games that took STEP steps.
%
  step_max = 200;
  steps = zeros ( step_max, 1 );
  seed = 123456789;

  for game = 1 : n
    [ step, seed ] = snakes_one_game ( seed );
    if ( step <= step_max )
      steps(step) = steps(step) + 1;
    end
  end
%
%  Plot the counts.
%
  figure ( 1 )
  bar ( steps );
  grid on
  title ( sprintf ( 'Count of lengths of %d Games of Snakes and Ladders', n ) );

  filename = sprintf ( 'snakes_bar_count_%d.png', n );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  print ( '-dpng', filename );
  pause ( 5 );
%
%  Plot the PDF.
%
  figure ( 2 )
  pdf(1:step_max) = steps(1:step_max) / n;
  bar ( pdf );
  grid on
  title ( sprintf ( 'PDF of lengths of %d Games of Snakes and Ladders', n ) );

  filename = sprintf ( 'snakes_bar_pdf_%d.png', n );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  print ( '-dpng', filename );
  pause ( 5 )
%
%  Plot the CDF.
%
  figure ( 3 )
  cdf = cumsum ( pdf );
  bar ( cdf );
  grid on
  title ( sprintf ( 'CDF of lengths of %d Games of Snakes and Ladders', n ) );

  filename = sprintf ( 'snakes_bar_cdf_%d.png', n );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
  print ( '-dpng', filename );
  pause ( 5 );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'snakes_bar:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end
