function ash ( N )

%*****************************************************************************80
%
%% ASH is a special case of CHESS using P = Q = 1/3.
%
%  Discussion:
%
%    This M file is chess.m modified to implement Ash's special
%    values of p = q = 1/3.
%
%    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.
%
%  Modified:
%
%    25 January 2018
%
%  Author:
%
%    Paul Nahin
%
%  Reference:
%
%    Paul Nahin,
%    Dueling Idiots and Other Probability Puzzlers,
%    Princeton, 2012,
%    ISBN: 978-0691155005.
%
%  Input parameters:
%
%    Input, integer N, the number of games in the match.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'ASH:\n' );
  fprintf ( 1, '  A champ plays a chump at N games of chess.\n' );
  fprintf ( 1, '  P is the probability that an individual game is won by the champ.\n' );
  fprintf ( 1, '  Q is the probability that an individual game ends in a tie.\n' );
  fprintf ( 1, '  For this code, P = Q = 1/3.\n' );

  q = 1 / 3;
  ANSWER = zeros(3,round(100*(1-q)));
  p = 1 / 3;
  g = ( 1 - p - q ) * p;
  RZ = zeros(1,N);
  C = zeros(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 - 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

  SUM = 0;
  for k = 1 : N
    SUM = SUM + C(k,N);
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Probablity of a tie is             %g\n', RZ(N) );
  fprintf ( 1, '  Probability the champ wins is      %g\n', SUM );
  fprintf ( 1, '  Probability the challenger wins is %g\n', 1 - RZ(N) - SUM );

  return
end
