function ash ( N )

#*****************************************************************************80
#
## ash() is a special case of chess() using P = Q = 1/3.
#
#  Discussion:
#
#    A champ plays a chump at N games of chess.
#    P is the probability that an individual game is won by the champ.
#    Q is the probability that an individual game ends in a tie.
#
#  Example:
#
#    For N = 100, the probablity of a tied match is 0.04877.
#
#  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.
#
#  Input:
#
#    integer N, the number of games in the match.
#
  print ( '' )
  print ( 'ash():' )
  print ( '  A champ plays a chump at N games of chess.' )
  print ( '  P is the probability an individual game is won by the champ.' )
  print ( '  Q is the probability an individual game ends in a tie.' )
  print ( '  For this code, P = Q = 1/3.' )

  q = 1.0 / 3.0
  p = 1.0 / 3.0
  g = ( 1.0 - p - q ) * p
  RZ = zeros ( 1, N )
  C = zeros ( N, N )
  for k = 1 : N
    C(k,k) = p ^ k
  end

  for n = 1 : N

    if ( 2 * round ( n / 2 ) == n )
      for d = 0 : 2 : n
        top = ( n + d ) / 2
        bottom = ( n - d ) / 2
        I = binomial ( n, bottom ) * binomial ( top, bottom )
        I = I * ( g ^ bottom ) * ( q ^ d )
        RZ(n) = RZ(n) + I
      end
    else
      for d = 1 : 2 : n
        top = ( n + d ) / 2
        bottom = ( n - d ) / 2
        I = binomial ( n, bottom ) * binomial ( top, bottom )
        I = I * ( g ^ bottom ) * ( q ^ d )
        RZ(n) = RZ(n) + I
      end
    end

  end

  g = 1.0 - p - q

  for c = 2 : N
    k = 1
    n = c
    while ( n <= N )
      C(k,n) = C(k,n-1) * q + C(k+1,n-1) * g
      if ( k == 1 )
        C(k,n) = C(k,n) + RZ(n-1) * p
      else
        C(k,n) = C(k,n) + C(k-1,n-1) * p
      end
      k = k + 1
      n = n + 1
    end
  end

  total = sum ( C(1:N,N) )

  print ( '' )
  print ( '  Probability of a tie is           ', RZ(N) )
  print ( '  Probability the champ wins is     ', total )
  print ( '  Probability the challenger wins is', 1 - RZ(N) - total )

  return

 
