Author: Graham Laight
Date: 03:45:50 10/13/04
Go up one level in this thread
On October 12, 2004 at 13:07:22, Omid David Tabibi wrote:
>Reading comments like yours, I come to the conclusion that an Introduction to
>Statistics course should be made mandatory as a prerequisite for joining CCC...
OK - here's a program to use the statistical technique called, "Monte Carlo
Simulation". I hope that this satisfies everyone that I am not statistically
illiterate.
To use:
1. Paste the program below into Notepad (or Vuepad if you're using Unix)
2. Save it as c:\bilbao.htm
3. In your web browser, type "c:\bilbao.htm" in the address bar
enjoy!
-g
------ Program ------
<html>
<head>
<title>Analyse Junior's Poor Performance At Bilbao Oct 2004</title>
<SCRIPT LANGUAGE="JavaScript">
function workItOut()
{
var oLoop = 1, iLoop = 1, wProb = 0,dProb = 0, lProb = 0, score = 0;
var randy = 0;
oLoop = Number(document.game.userInput.value);
if ((oLoop < 1) || (oLoop > 1000000) || (oLoop - Math.ceil(oLoop) != 0))
{
alert("No. simulations should be an integer between 1 and 1,000,000.");
document.game.result.value = "";
return;
}
wProb = Number(document.game.winProb.value);
if ((wProb < 0) || (wProb > 100) || (wProb - Math.ceil(wProb) != 0))
{
alert("The winning probability should be an integer between 0 and 100.");
document.game.result.value = "";
return;
}
dProb = Number(document.game.drawProb.value);
if ((dProb < 0) || (dProb > 100) || (dProb - Math.ceil(dProb) != 0))
{
alert("The drawing probability should be an integer between 0 and 100.");
document.game.result.value = "";
return;
}
lProb = Number(document.game.loseProb.value);
if ((lProb < 0) || (lProb > 100) || (lProb - Math.ceil(lProb) != 0))
{
alert("The losing probability should be an integer between 0 and 100.");
document.game.result.value = "";
return;
}
iLoop = Number(document.game.noGames.value);
if ((iLoop < 1) || (iLoop > 1000) || (iLoop - Math.ceil(iLoop) != 0))
{
alert("Number of games should be an integer between 0 and 1000.");
document.game.result.value = "";
return;
}
if (wProb + dProb + lProb != 100)
{
alert("The 3 percentage probabilities must add up to 100");
document.game.result.value = "";
return;
}
wProb = wProb / 100;
dProb = dProb / 100;
lProb = lProb / 100;
var results = new Array(iLoop * 2);
for (i = 0; i <= iLoop * 2; i++)
results[i] = 0;
for (i = 1; i <= oLoop; i++)
{
score = 0;
for (j=1; j <= iLoop; j++)
{
randy = Math.random();
if (randy < wProb)
score = score + 2;
else
if (randy < wProb + dProb)
score++;
}
results[score]++;
}
var message = "";
for (i = 0; i <= iLoop * 2; i++)
{
if (results[i] > 0)
{
message = message + "DJ won " + i/2 + " points in ";
message = message + Math.round((results[i]/oLoop)*10000)/100;
message = message + "% of the tournaments\n"
}
}
document.game.result.value = message;
} // end of workItOut function
</SCRIPT>
</head>
<body>
<form name="game">
<big><b><u>
<center>Analyse Junior's Poor Performance At Bilbao Oct 2004</center>
</u></b></big><small><br /><br />
<b><u>Explanation:</u></b><font color="#ffffff">..</font>At the Bilbao chess
competition in Bilbao in Oct 2004, Junior unexpectedly produced a result which
was much worse than the other computers taking part. This program helps us to
investigate the extent to which this could have been just plain bad luck.
<br /><br />
Type in the percentage probabilities for Junior winning, losing and drawing
below (the 3 numbers must add up to 100), then click on "Calculate".
The answer will appear in the "Result" field.</small><br /><br />
<center><input type="button" name="Start Simulation" value="Calculate"
onclick="workItOut()" /></center><br /><br />
<table cellspacing="15" title="Results">
<tr><td><b>Number of simulations (0 < integer < 1,000,000):</b></td>
<td><input name="userInput" value="100000" size="65" type="text" />
</td></tr>
<tr><td><b>Percentage probability of game win (0 < integer < 100):</b></td>
<td><input name="winProb" value="10" size="65" type="text" />
</td></tr>
<tr><td><b>Percentage probability of game draw (0 < integer < 100):</b></td>
<td><input name="drawProb" value="70" size="65" type="text" />
</td></tr>
<tr><td><b>Percentage probability of game loss (0 < integer < 100):</b></td>
<td><input name="loseProb" value="20" size="65" type="text" />
</td></tr>
<tr><td><b>Number of games in tournament (0 < integer < 1000):</b></td>
<td><input name="noGames" value="4" size="65" type="text" />
</td></tr>
<tr><td><b>Result:</b></td><td>
<textarea cols="49" rows="10" name="result" readonly="readonly"
title="Simulation Results">
</textarea></td></tr></table>
<br /><br />
<small>©Graham Laight 2004<font color="white">.......</font>
<a href="mailto:GHL@QAD.COM">Write To The Author</a>
<font color="white">.......</font>
<a href="http://mysite.wanadoo-members.co.uk/grahamlaight/index.html">
Home page</a></small>
</form>
</body>
</html>
This page took 0.01 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.