function casino ( trial_num )

%*****************************************************************************80
%
%% casino() simulates the game "Chuck-a-Luck".
%
%  Discussion:
%
%    This function simulates many games of "Chuck-a-Luck" and
%    calculates the average winnings. That is, you bet $1 each
%    game and the winnings (W) are how much MORE money you have
%    over and above the $trial_num betting money. The average
%    winnings are, of course, W/trial_num.
%
%    Three dice are rolled, and you can bet on any number between
%    1 and 6.  If one die comes up with your number, you win as
%    much as you bet.  If two or three dice come up with your number,
%    you win twice or three times your bet.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    29 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
%  Input:
%
%    integer trial_num: the number of trials.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'casino():\n' );
  fprintf ( 1, '  Simulate many games of "Chuck-a-Luck" and\n' );
  fprintf ( 1, '  calculate the average winnings. That is, you bet $1 each time\n' );
  fprintf ( 1, '  and the winnings (W) are how much MORE money you have\n' );
  fprintf ( 1, '  over and above the $trial_num betting money. The average\n' );
  fprintf ( 1, '  winnings are, of course, W/trial_num.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Three dice are rolled, and you can bet on any number between\n' );
  fprintf ( 1, '  1 and 6.  If one die comes up with your number, you win as\n' );
  fprintf ( 1, '  much as you bet.  If two or three dice come up with your number,\n' );
  fprintf ( 1, '  you win twice or three times your bet.\n' );

   W = 0;

  for games = 1 : trial_num

    bet = randi ( [ 1, 6 ] );

    die1 = randi ( [ 1, 6 ] );
    die2 = randi ( [ 1, 6 ] );
    die3 = randi ( [ 1, 6 ] );

    matches = 0;

    if ( bet == die1 )
      matches = matches + 1;
    end
    if ( bet == die2 )
      matches = matches + 1;
    end
    if ( bet == die3 )
      matches = matches + 1;
    end

    if ( matches == 0 )
      W = W - 1;
    else
      W = W + matches;
    end

  end

  W = W / trial_num;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Average winnings per game is %g dollars\n', W );

  return
end
                                      
