Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: DJ-DF 5-0! How is this possible?

Author: Dann Corbit

Date: 11:29:54 04/25/01

Go up one level in this thread


// stronger.cpp: Is your favorite player really stronger?
//        Programmed by Leen Ammeraal
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

double binom(int n, int k)
{  double x = 1;
   for (int j=0; j<k; ++j)
      x *= double(n - j) / (j + 1);
   return x;
}

int main()
{  int n, nA, nB, nD;
   double p = 0.5;
   cout << "Player A may be stronger than player B "
           "or may have won by luck.\n";
   cout << "How many times has A won? ";
   cin >> nA;
   cout << "How many times has B won? ";
   cin >> nB;
   cout << "How many draws (preferably an even number)? ";
   cin >> nD;
   nA += nD/2;
   nB += nD/2;
   n = nA + nB;
   cout << "Our computation will be based on the score "
        << nA << " - " << nB << endl;
   double s = 0, t = 0;

   for (int i=0; i<=nB; ++i)
   {  t = binom(n, i) * pow(p, i) * pow(1-p, n-i);
          // t is the probability of B obtaining i points.
      s += t;
   }
   // s is the probability of B obtaining nB points or less.
   // This is equal to the probability of A obtaining nA points
   // or more.
   cout << "If A and B had the same strength, the probability of A\n";
   cout << "obtaining this score (or better) would be equal to "
        << fixed << setprecision(1)
        << s * 100 << "%.\n";
   return 0;
}
/*
E:\>stronger
Player A may be stronger than player B or may have won by luck.
How many times has A won? 5
How many times has B won? 0
How many draws (preferably an even number)? 0
Our computation will be based on the score 5 - 0
If A and B had the same strength, the probability of A
obtaining this score (or better) would be equal to 3.1%.
*/



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.