function casino ( )

#*****************************************************************************80
#
## casino() simulates the game "Chuck-a-Luck".
#
#  Discussion:
#
#    This function simulates 10,000 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 $10,000 betting money. The average
#    winnings are, of course, W/10,000.
#
#    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 GNU LGPL license.
#
#  Modified:
#
#    08 February 2023
#
#  Author:
#
#    Original MATLAB version by Paul Nahin.
#    This version by John Burkardt.
#
#  Reference:
#
#    Paul Nahin,
#    Dueling Idiots and Other Probability Puzzlers,
#    Princeton, 2012,
#    ISBN: 978-0691155005.
#
  print ( '' )
  print ( 'casino():' )
  print ( '  Simulate 10,000 games of "Chuck-a-Luck" and' )
  print ( '  calculate the average winnings. That is, you bet $1 each' )
  print ( '  and the winnings (W) are how much MORE money you have' )
  print ( '  over and above the $10,000 betting money. The average' )
  print ( '  winnings are, of course, W/10,000.' )
  print ( '' )
  print ( '  Three dice are rolled, and you can bet on any number between' )
  print ( '  1 and 6.  If one die comes up with your number, you win as' )
  print ( '  much as you bet.  If two or three dice come up with your number,' )
  print ( '  you win twice or three times your bet.' )

   W = 0

  for games = 1 : 100000

    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 / 100000

  print ( '' )
  print ( '  Average winnings per game is', W, 'dollars.' )

  return

                                      
