<html>
<head>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<script type="text/javascript">
//<![CDATA[

var mypictures = new Array("http://www.rjmprogramming.com.au/images/01c.gif",
"http://www.rjmprogramming.com.au/images/01d.gif",
"http://www.rjmprogramming.com.au/images/01h.gif",
"http://www.rjmprogramming.com.au/images/01s.gif",
"http://www.rjmprogramming.com.au/images/02c.gif",
"http://www.rjmprogramming.com.au/images/02d.gif",
"http://www.rjmprogramming.com.au/images/02h.gif",
"http://www.rjmprogramming.com.au/images/02s.gif",
"http://www.rjmprogramming.com.au/images/03c.gif",
"http://www.rjmprogramming.com.au/images/03d.gif",
"http://www.rjmprogramming.com.au/images/03h.gif",
"http://www.rjmprogramming.com.au/images/03s.gif",
"http://www.rjmprogramming.com.au/images/04c.gif",
"http://www.rjmprogramming.com.au/images/04d.gif",
"http://www.rjmprogramming.com.au/images/04h.gif",
"http://www.rjmprogramming.com.au/images/04s.gif",
"http://www.rjmprogramming.com.au/images/05c.gif",
"http://www.rjmprogramming.com.au/images/05d.gif",
"http://www.rjmprogramming.com.au/images/05h.gif",
"http://www.rjmprogramming.com.au/images/05s.gif",
"http://www.rjmprogramming.com.au/images/06c.gif",
"http://www.rjmprogramming.com.au/images/06d.gif",
"http://www.rjmprogramming.com.au/images/06h.gif",
"http://www.rjmprogramming.com.au/images/06s.gif",
"http://www.rjmprogramming.com.au/images/07c.gif",
"http://www.rjmprogramming.com.au/images/07d.gif",
"http://www.rjmprogramming.com.au/images/07h.gif",
"http://www.rjmprogramming.com.au/images/07s.gif",
"http://www.rjmprogramming.com.au/images/08c.gif",
"http://www.rjmprogramming.com.au/images/08d.gif",
"http://www.rjmprogramming.com.au/images/08h.gif",
"http://www.rjmprogramming.com.au/images/08s.gif",
"http://www.rjmprogramming.com.au/images/09c.gif",
"http://www.rjmprogramming.com.au/images/09d.gif",
"http://www.rjmprogramming.com.au/images/09h.gif",
"http://www.rjmprogramming.com.au/images/09s.gif",
"http://www.rjmprogramming.com.au/images/10c.gif",
"http://www.rjmprogramming.com.au/images/10d.gif",
"http://www.rjmprogramming.com.au/images/10h.gif",
"http://www.rjmprogramming.com.au/images/10s.gif",
"http://www.rjmprogramming.com.au/images/11c.gif",
"http://www.rjmprogramming.com.au/images/11d.gif",
"http://www.rjmprogramming.com.au/images/11h.gif",
"http://www.rjmprogramming.com.au/images/11s.gif",
"http://www.rjmprogramming.com.au/images/12c.gif",
"http://www.rjmprogramming.com.au/images/12d.gif",
"http://www.rjmprogramming.com.au/images/12h.gif",
"http://www.rjmprogramming.com.au/images/12s.gif",
"http://www.rjmprogramming.com.au/images/13c.gif",
"http://www.rjmprogramming.com.au/images/13d.gif",
"http://www.rjmprogramming.com.au/images/13h.gif",
"http://www.rjmprogramming.com.au/images/13s.gif"
);

var myforstuff = new Array("http://www.rjmprogramming.com.au/images/01c.gif",
"0,2,2",
"http://www.rjmprogramming.com.au/images/01h.gif",
"3,42,13",
"http://www.rjmprogramming.com.au/images/02c.gif",
"http://www.rjmprogramming.com.au/images/02d.gif",
"http://www.rjmprogramming.com.au/images/02h.gif",
"http://www.rjmprogramming.com.au/images/02s.gif",
"http://www.rjmprogramming.com.au/images/03c.gif",
"http://www.rjmprogramming.com.au/images/03d.gif",
"http://www.rjmprogramming.com.au/images/03h.gif",
"http://www.rjmprogramming.com.au/images/03s.gif",
"2,50,4",
"http://www.rjmprogramming.com.au/images/04d.gif",
"http://www.rjmprogramming.com.au/images/04h.gif",
"http://www.rjmprogramming.com.au/images/04s.gif",
"http://www.rjmprogramming.com.au/images/05c.gif",
"http://www.rjmprogramming.com.au/images/05d.gif",
"http://www.rjmprogramming.com.au/images/05h.gif",
"http://www.rjmprogramming.com.au/images/05s.gif",
"http://www.rjmprogramming.com.au/images/06c.gif",
"http://www.rjmprogramming.com.au/images/06d.gif",
"http://www.rjmprogramming.com.au/images/06h.gif",
"http://www.rjmprogramming.com.au/images/06s.gif",
"http://www.rjmprogramming.com.au/images/07c.gif",
"1,51,2",
"http://www.rjmprogramming.com.au/images/07h.gif",
"http://www.rjmprogramming.com.au/images/07s.gif",
"http://www.rjmprogramming.com.au/images/08c.gif",
"http://www.rjmprogramming.com.au/images/08d.gif",
"http://www.rjmprogramming.com.au/images/08h.gif",
"http://www.rjmprogramming.com.au/images/08s.gif",
"http://www.rjmprogramming.com.au/images/09c.gif",
"http://www.rjmprogramming.com.au/images/09d.gif",
"http://www.rjmprogramming.com.au/images/09h.gif",
"http://www.rjmprogramming.com.au/images/09s.gif",
"http://www.rjmprogramming.com.au/images/10c.gif",
"http://www.rjmprogramming.com.au/images/10d.gif",
"http://www.rjmprogramming.com.au/images/10h.gif",
"http://www.rjmprogramming.com.au/images/10s.gif",
"http://www.rjmprogramming.com.au/images/11c.gif",
"http://www.rjmprogramming.com.au/images/11d.gif",
"http://www.rjmprogramming.com.au/images/11h.gif",
"http://www.rjmprogramming.com.au/images/11s.gif",
"http://www.rjmprogramming.com.au/images/12c.gif",
"http://www.rjmprogramming.com.au/images/12d.gif",
"http://www.rjmprogramming.com.au/images/12h.gif",
"http://www.rjmprogramming.com.au/images/12s.gif",
"http://www.rjmprogramming.com.au/images/13c.gif",
"http://www.rjmprogramming.com.au/images/13d.gif",
"http://www.rjmprogramming.com.au/images/13h.gif",
"0,51,1"
);

var odds = 0.0;
var lastodds = 0.0;
var accumulatedodds = 0.0;
var aheadoftheodds = 0.0;
var thispicture = 0;
var goes = 0;
var goesbehind = 0;
var goesahead = 0;
var possibleodds = 0.0;
var achievedresults = 0.0;
var numcards = 0;
var thiscard = 0;
var correct = 0;
var percentwinning = "";
var ingreen = 0;
var plusmaybe = "<span style='color:yellow;'>+";
var incorrect = 0;
var valarr = {};

function htwo() {
document.getElementById('score').innerHTML = "Goes: " + goes + " ... Last Odds: " + lastodds + " ... Accumulated Odds: " + possibleodds + " ... <br>Winning Guesses (% beating the odds): " + achievedresults + percentwinning + " ... Ahead of the Odds (+ve good): " + plusmaybe + aheadoftheodds + "</span>";
}

function initA() {
//document.getElementById("prevA").onclick = prevDo;
//document.getElementById("nextA").onclick = nextDo;
var isel=document.getElementById('numcardsingame');
var ivalarr, inumcards;
for (var ii=0; ii<myforstuff.length; ii++) {
if (myforstuff[ii].indexOf(',') != -1) {
ivalarr = myforstuff[ii].split(',');
inumcards = (ivalarr[1] - ivalarr[0]) / ivalarr[2] + 1;
isel.innerHTML = isel.innerHTML + "<option value='" + myforstuff[ii] + "'>" + inumcards + "</option>";
}
}
}

function prevDo() {
//if (thispicture == 0) {
// thispicture = mypictures.length;
//}
//thispicture--;
//document.getElementById("myPic").src = mypictures[thispicture];
return false;
}

function nextDo() {
//thispicture++;
//if (thispicture == mypictures.length) {
// thispicture = 0;
//}
//document.getElementById("myPic").src = mypictures[thispicture];
return false;
}

function gamechange(os) {
if (os.value != '') {
valarr = os.value.split(',');
numcards = (valarr[1] - valarr[0]) / valarr[2] + 1;
//alert(numcards);
var ibb = "<tr>";
kk = eval(0+valarr[0]);
for (var jj=1; jj<=numcards; jj++) {
ibb += "<td>";
ibb += "<img title='Click on me if you think it is me the computer chose ... Latest Odds: 1 in " + numcards + "' id='i" + kk + "' onclick='guess(this);' src='" + mypictures[kk] + "' style='border: 5px solid pink;' onmouseover=' this.style.borderColor = \"orange\"; ' onmouseout=' this.style.borderColor = \"pink\"; ' />";
ibb += "</td>";
for (var mm=0; mm<valarr[2]; mm++) {
kk += 1;
}
if ((jj % 13) == 0) ibb += "</tr><tr>";
}
ibb += "</tr>";
document.getElementById('ibody').innerHTML = ibb;
//alert(document.getElementById('ibody').innerHTML);
thiscard = Math.floor((Math.random()*numcards)+1);
}
}

function assertionis(cid, tc) {
var kk = eval(0+valarr[0]);
var vskk = eval(tc-1);
var retis=false;
for (var jj=1; jj<=numcards; jj++) {
if (jj == tc) {
if (cid == ("i" + kk)) retis = true;
}
for (var mm=0; mm<valarr[2]; mm++) {
kk += 1;
}
}
return retis;
}

function guess(iis) {
//var odds = 0.0;
//var lastodds = 0.0;
//var accumulatedodds = 0.0;
//var aheadoftheodds = 0.0;
//var thispicture = 0;
//var goes = 0;
//var goesbehind = 0;
//var goesahead = 0;
//var possibleodds = 0.0;
//var achievedresults = 0.0;
//var numcards = 0;
//var correct = 0;
//var plusmaybe = "";
//var incorrect = 0;
//var thiscard = 0;
//var valarr = {};
goes = goes + 1;
lastodds = eval(parseFloat(1) / parseFloat(numcards));
if (assertionis(iis.id, thiscard)) {
correct = correct + 1;
if (goes == 1) {
possibleodds = eval(parseFloat(1) / parseFloat(numcards));
achievedresults = 1.0; //eval(parseFloat(numcards) / parseFloat(1));
aheadoftheodds = eval(achievedresults - possibleodds);
} else {
possibleodds += eval(parseFloat(1) / parseFloat(numcards));
achievedresults += 1.0; //eval(parseFloat(numcards) / parseFloat(1));
aheadoftheodds = eval(achievedresults - possibleodds);
}
} else {
incorrect = incorrect + 1;
if (goes == 1) {
possibleodds = eval(parseFloat(1) / parseFloat(numcards));
achievedresults = 0.0; //eval(parseFloat(0) / parseFloat(1));
aheadoftheodds = eval(achievedresults - possibleodds);
} else {
possibleodds += eval(parseFloat(1) / parseFloat(numcards));
achievedresults += 0.0; //eval(parseFloat(0) / parseFloat(1));
aheadoftheodds = eval(achievedresults - possibleodds);
}
}
plusmaybe = "<span style='color:red;'>";
if (aheadoftheodds > 0.0) {
ingreen = eval(1 + ingreen);
plusmaybe = "<span style='color:green;'>+";
} else if (aheadoftheodds == 0.0) {
plusmaybe = "<span style='color:yellow;'>";
}
percentwinning = " (" + eval(parseFloat(100) * (parseFloat(ingreen) / parseFloat(goes))) + "%)";
htwo();
thiscard = Math.floor((Math.random()*numcards)+1);
}

//]]>
</script>
</head>
<body onload="initA();" style="background: url('http://www.rjmprogramming.com.au/images/01c.gif') repeat; ">
<div align="center" style="background-color: silver; padding-bottom: 20px;">
<br><h1 title='Are you lucky? Can you keep the yellow and green results coming?'>Ahead of the Odds Game</h1>
<h2 id='score'>Goes: 0 ... Last Odds: n/a ... Accumulated Odds: n/a ... <br>Winning Guesses (% beating the odds): n/a ... Ahead of the Odds (+ve good): <span style='color:yellow;'>+0</span></h2>
<select id='numcardsingame' size=10 onchange='gamechange(this);'><option value=''>Pick a game with number of cards as below ...</option></select>
<table id='itable' style="width:100%;"><tbody id='ibody' style="width:100%;"></tbody></table>
</div>
</body>
</html>