<!doctype html>
<html>
<head>
<title>Three or More 🕒➕➕ Dice 🎲🎲🎲🎲🎲 Game - RJM Programming - March, 2018</title>
<style>
* { font-family: 'DejaVu Sans'; }

.xone:before { font-family: 'DejaVu Sans'; content: '\002680'; color:blue; }
.xtwo:before { font-family: 'DejaVu Sans'; content: '\002681'; color:blue; }
.xthree:before { font-family: 'DejaVu Sans'; content: '\002682'; color:blue; }
.xfour:before { font-family: 'DejaVu Sans'; content: '\002683'; color:blue; }
.xfive:before { font-family: 'DejaVu Sans'; content: '\002684'; color:blue; }
.xsix:before { font-family: 'DejaVu Sans'; content: '\002685'; color:blue; }
.zone:after { font-family: 'DejaVu Sans'; content: '\002680'; color:blue; }
.ztwo:after { font-family: 'DejaVu Sans'; content: '\002681'; color:blue; }
.zthree:after { font-family: 'DejaVu Sans'; content: '\002682'; color:blue; }
.zfour:after { font-family: 'DejaVu Sans'; content: '\002683'; color:blue; }
.zfive:after { font-family: 'DejaVu Sans'; content: '\002684'; color:blue; }
.zsix:after { font-family: 'DejaVu Sans'; content: '\002685'; color:blue; }

.kout:after { content: '\01f44A'; }

#snum { background-color: yellow; }

#header { background-color: #f0f0f0; }

select { white-space:pre-wrap; border-radius: 6px; }
#gamemode { background-color: transparent; }

button { border-radius: 12px; }
input[type=button] { border-radius: 12px; }

h1 { text-align: center; }
h3 { text-align: center; }

</style>
<script type='text/javascript'>
// https://www.w3schools.com/charsets/ref_utf_punctuation.asp

// ․ 8228 2024 ONE DOT LEADER
// ⁖ 8278 2056 THREE DOT PUNCTUATION
// ⁘ 8280 2058 FOUR DOT PUNCTUATION
// ⁙ 8281 2059 FIVE DOT PUNCTUATION
// ⁚ 8282 205A TWO DOT PUNCTUATION
// ⁛ 8283 205B FOUR DOT MARK
// …8230 2026 … HORIZONTAL ELLIPSIS

// Thanks to http://www.math.hawaii.edu/~ramsey/Probability/TwoDice.html
var probabilities=[0,0,1,2,3,4,5,6,5,4,3,2,1]; // score will be 7-guessValue
var score=[0,0], goes=[0,0], names=['Player 👤 1','Player 👤 2'], sels=['',''], stillin=[true,true];
var cactiontd='';
var numplayers=2, khem=0;
var theader='', tgame='';
var d1=7, d2=7, d3=7, d4=7, d5=7, ccomma='', lastwinners='';
var rollno=1;
var numpdone=false, refocus=false;

function andthen() {
khem=0;
document.getElementById('actiontd').innerHTML=cactiontd.replace('Each Player', names[0]);
document.getElementById('tdr').innerHTML='Five Dice 🎲🎲🎲🎲🎲 Roll';
for (var hem=1; hem<=numplayers; hem++) {
document.getElementById('gplayer' + hem).innerHTML=sels[eval(-1 + hem)];
document.getElementById('gplayer' + hem).value='06';
stillin[eval(-1 + hem)]=true;
lastwinners='';
}
}

function roll() {
var hem=khem;
//for (var hem=0; hem<numplayers; hem++) {
document.getElementById('tdr').title='';
d1=7;
d2=7;
d3=7;
d4=7;
d5=7;
ccomma='';
fixinstone(numplayers);
if (cactiontd == '') {
cactiontd=document.getElementById('actiontd').innerHTML;
document.getElementById('actiontd').innerHTML=cactiontd.replace('Each Player', names[0]);
}
if (hem < numplayers) {
document.getElementById('actiontd').innerHTML='';
postroll(hem);
} else {
khem=0;
}
//}
}

function postroll(hem) {
document.getElementById('actiontd').innerHTML=''; //cactiontd.replace('Each Player', names[hem]);
document.getElementById('tdr').innerHTML='Five Dice 🎲🎲🎲🎲🎲 Rolls for ' + names[hem] + ' are ';
d1=7;
while (d1 == 7) {
d1=eval(Math.floor(Math.random() * 6) + 1);
}
document.getElementById('actiontd').innerHTML+='<div style="margin-left:40%;">' + document.getElementById('h' + d1).outerHTML.replace(' id="h' + d1 + '"','') + '</div>';
d2=7;
while (d2 == 7) {
d2=eval(Math.floor(Math.random() * 6) + 1);
}
document.getElementById('actiontd').innerHTML+='<div style="margin-left:40%;">' + document.getElementById('h' + d2).outerHTML.replace(' id="h' + d2 + '"','') + '</div>';
//d1+=d2;

d3=7;
while (d3 == 7) {
d3=eval(Math.floor(Math.random() * 6) + 1);
}
document.getElementById('actiontd').innerHTML+='<div style="margin-left:40%;">' + document.getElementById('h' + d3).outerHTML.replace(' id="h' + d3 + '"','') + '</div>';
//d1+=d3;

d4=7;
while (d4 == 7) {
d4=eval(Math.floor(Math.random() * 6) + 1);
}
document.getElementById('actiontd').innerHTML+='<div style="margin-left:40%;">' + document.getElementById('h' + d4).outerHTML.replace(' id="h' + d4 + '"','') + '</div>';
//d1+=d4;

d5=7;
while (d5 == 7) {
d5=eval(Math.floor(Math.random() * 6) + 1);
}

document.getElementById('actiontd').innerHTML+='<div style="margin-left:40%;">' + document.getElementById('h' + d5).outerHTML.replace(' id="h' + d5 + '"','') + '</div>';
//d1+=d5;



document.getElementById('tdr').innerHTML+=ccomma + diceemoji(d1);
ccomma=', ';
document.getElementById('tdr').innerHTML+=ccomma + diceemoji(d2);
ccomma=', ';
document.getElementById('tdr').innerHTML+=ccomma + diceemoji(d3);
ccomma=', ';
document.getElementById('tdr').innerHTML+=ccomma + diceemoji(d4);
ccomma=', ';
document.getElementById('tdr').innerHTML+=ccomma + diceemoji(d5);

analyze(hem, true);
ccomma='';
if (eval(1 + hem) == numplayers) {
setTimeout(andthen, 5000);
} else {
khem++;
setTimeout(ath, 1500);
//document.getElementById('actiontd').innerHTML=cactiontd.replace('Each Player', names[khem]);
//setTimeout(roll, 2000);
}
}

function ath() {
document.getElementById('actiontd').innerHTML=cactiontd.replace('Each Player', names[khem]);
}

function analyze(ih, oktor) {
var dd=7, idd, jana, kana, rew='', rews='';
var suffan=document.getElementById('tdr').innerHTML.split(' are ')[1];
var ana=document.getElementById('tdr').innerHTML.split(' are ')[1].replace(/\ /g,'').split(',');
ana.sort();
//alert(ana);
var lastone=ana[0], inarow=1, twos=[-1,-1], notit=[], iwhich=0;
for (jana=1; jana<ana.length; jana++) {
if (('' + lastone) == ('' + ana[jana])) {
inarow++;
if (inarow == 2) {
twos[iwhich]=eval(lastone);
iwhich++;
}
} else if (inarow < 3) {
lastone=ana[jana];
inarow=1;
}
}
if (inarow == 5) {
goes[ih]++;
score[ih]+=12;
document.getElementById('score' + eval(1 + ih)).innerHTML='Score: ' + score[ih] + '/' + goes[ih];
//alert(5);
} else if (inarow == 4) {
goes[ih]++;
score[ih]+=6;
document.getElementById('score' + eval(1 + ih)).innerHTML='Score: ' + score[ih] + '/' + goes[ih];
//alert(4);
} else if (inarow == 3) {
goes[ih]++;
score[ih]+=3;
document.getElementById('score' + eval(1 + ih)).innerHTML='Score: ' + score[ih] + '/' + goes[ih];
//alert(3);
} else if (twos[1] != -1 && oktor) {
var ic=ourconfirm(document.getElementById('tdr').innerHTML.split(' are ')[1] + " ... Keep the " + twos[0] + "'s and reroll is OK and keep the " + twos[1] + "'s and reroll is Cancel");
if (ic == true) {
//document.getElementById('tdr').innerHTML=document.getElementById('tdr').innerHTML.replace(twos[0], '0' + twos[0]).replace(twos[0], '0' + twos[0]);
ana=document.getElementById('tdr').innerHTML.split(' are ')[1].replace(/\ /g,'').split(',');
for (kana=0; kana<ana.length; kana++) {
if (('' + ana[kana]) != ('' + twos[0])) notit.push(kana);
}
for (idd=0; idd<3; idd++) {
dd=7;
while (dd == 7) {
dd=eval(Math.floor(Math.random() * 6) + 1);
}
ana[notit[idd]]=('' + dd);
}
for (kana=0; kana<ana.length; kana++) {
rew+=rews + ana[kana];
rews=',';
}
document.getElementById('tdr').innerHTML=document.getElementById('tdr').innerHTML.split(' are ')[0] + ' are ' + rew;
analyze(ih,false);
} else {
//document.getElementById('tdr').innerHTML=document.getElementById('tdr').innerHTML.replace(twos[1], '0' + twos[1]).replace(twos[1], '0' + twos[1]);
ana=document.getElementById('tdr').innerHTML.split(' are ')[1].replace(/\ /g,'').split(',');
for (kana=0; kana<ana.length; kana++) {
if (('' + ana[kana]) != ('' + twos[1])) notit.push(kana);
}
for (idd=0; idd<3; idd++) {
dd=7;
while (dd == 7) {
dd=eval(Math.floor(Math.random() * 6) + 1);
}
ana[notit[idd]]=('' + dd);
}
for (kana=0; kana<ana.length; kana++) {
rew+=rews + ana[kana];
rews=',';
}
document.getElementById('tdr').innerHTML=document.getElementById('tdr').innerHTML.split(' are ')[0] + ' are ' + rew;
analyze(ih,false);
}
} else if (twos[0] != -1 && oktor) {
ouralert(document.getElementById('tdr').innerHTML.split(' are ')[1] + " ... Am keeping the " + twos[0] + "'s and rerolling.");
//document.getElementById('tdr').innerHTML=document.getElementById('tdr').innerHTML.replace(twos[0], '0' + twos[0]).replace(twos[0], '0' + twos[0]);
ana=document.getElementById('tdr').innerHTML.split(' are ')[1].replace(/\ /g,'').split(',');
for (kana=0; kana<ana.length; kana++) {
if (('' + ana[kana]) != ('' + twos[0])) notit.push(kana);
}
for (idd=0; idd<3; idd++) {
dd=7;
while (dd == 7) {
dd=eval(Math.floor(Math.random() * 6) + 1);
}
ana[notit[idd]]=('' + dd);
}
for (kana=0; kana<ana.length; kana++) {
rew+=rews + ana[kana];
rews=',';
}
document.getElementById('tdr').innerHTML=document.getElementById('tdr').innerHTML.split(' are ')[0] + ' are ' + rew;
analyze(ih,false);
} else {
goes[ih]++;
document.getElementById('score' + eval(1 + ih)).innerHTML='Score: ' + score[ih] + '/' + goes[ih];
}

document.getElementById('tdr').innerHTML=document.getElementById('tdr').innerHTML.replace(suffan, document.getElementById('tdr').title);

}


function checkt() {
var inpn=location.search.split('numplayers=')[1] ? decodeURIComponent(location.search.split('numplayers=')[1].split('&')[0]) : '02';

// Make the dropdown look like the nesting h1
var divelem=document.getElementById('gamemode');
var output=document.getElementById('myh1');
divelem.style.fontFamily = window.getComputedStyle(output,null).fontFamily || output.style.fontFamily || output.currentStyle.getCurrentProperty('font-family');
divelem.style.fontSize = window.getComputedStyle(output,null).fontSize || output.style.fontSize || output.currentStyle.getCurrentProperty('font-size');
divelem.style.fontWeight = window.getComputedStyle(output,null).fontWeight || output.style.fontWeight || output.currentStyle.getCurrentProperty('font-weight');
divelem.style.border = window.getComputedStyle(output,null).border || output.style.border || output.currentStyle.getCurrentProperty('border');
divelem.style.padding = window.getComputedStyle(output,null).padding || output.style.padding || output.currentStyle.getCurrentProperty('padding');
divelem.style.margin = window.getComputedStyle(output,null).margin || output.style.margin || output.currentStyle.getCurrentProperty('margin');
divelem.style.overflow = window.getComputedStyle(output,null).overflow || output.style.overflow || output.currentStyle.getCurrentProperty('overflow');
divelem.style.padding = window.getComputedStyle(output,null).padding || output.style.padding || output.currentStyle.getCurrentProperty('padding');
divelem.style.color = window.getComputedStyle(output,null).color || output.style.color || output.currentStyle.getCurrentProperty('color');

if (sels[0] == '') {
sels[0]=document.getElementById('gplayer1').innerHTML;
}
if (sels[1] == '') {
sels[1]=document.getElementById('gplayer2').innerHTML;
}
if (theader == '') {
theader=document.getElementById('header').innerHTML;
}
if (tgame == '') {
tgame=document.getElementById('game').innerHTML;
}
if (cactiontd == '') {
cactiontd=document.getElementById('actiontd').innerHTML;
document.getElementById('actiontd').innerHTML=cactiontd.replace('Each Player', names[0]);
}

if (inpn.replace(/^0/g,'') == inpn && inpn.trim() != '') {
fixinstone(inpn);
}
}

function namechange(tid,tval) {
names[eval(tid.replace('dname','') - 1)]=tval;
}

function fixinstone(ihow) {
var inpn=location.search.split('numplayers=')[1] ? decodeURIComponent(location.search.split('numplayers=')[1].split('&')[0]) : '02';

//document.getElementById('dnum').innerHTML='' + ihow;
document.getElementById('dnum').innerHTML='<span onfocus="refocus=true;" onlosefocus="setTimeout(function(){ refocus=false; }, 3000);" contenteditable=true onblur="fixinstone(this.innerHTML); refocus=false;">' + ihow + '</span>';
if (numpdone && refocus && ('' + numplayers) != ('' + ihow)) { location.href=document.URL.split('?')[0].split('#')[0] + '?numplayers=' + ihow; }
numpdone=true;
if (numplayers < eval(ihow)) {
numplayers=eval(ihow);
var th='', tg='';
for (var jhow=3; jhow<=numplayers; jhow++) {
score.push(0);
goes.push(0);
stillin.push(true);
sels.push(sels[0]);
names.push('Player 👤 ' + jhow);
th+="<th></th><th><div onchange='namechange(this.id,this.innerHTML);' id='dname" + jhow + "' contenteditable=true>Player 👤 " + jhow + "</div><br>Score</th>";
tg+="<td><select style='display:none;' id='gplayer" + jhow + "'><option value='06'>Choose your threeormore value [6] ...</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option></select></td><td><div id='score" + jhow + "'>Score: 0/0</div></td>";
}
document.getElementById('header').innerHTML=theader + th;
document.getElementById('game').innerHTML=tgame.replace('Each Player', names[0]) + tg;
}

if (inpn.replace(/^0/g,'') == inpn && inpn.trim() != '') {
fixinstone(inpn);
}
}

function ouralert(inb) {
var outb=inb, ioff=9855;
for (var ii=1; ii<=6; ii++) {
switch (ii) {
case 1:
outb=outb.replace(/1/g,'1 ' + String.fromCodePoint(ioff + ii));
break;
case 2:
outb=outb.replace(/2/g,'2 ' + String.fromCodePoint(ioff + ii));
break;
case 3:
outb=outb.replace(/3/g,'3 ' + String.fromCodePoint(ioff + ii));
break;
case 4:
outb=outb.replace(/4/g,'4 ' + String.fromCodePoint(ioff + ii));
break;
case 5:
outb=outb.replace(/5/g,'5 ' + String.fromCodePoint(ioff + ii));
break;
case 6:
outb=outb.replace(/6/g,'6 ' + String.fromCodePoint(ioff + ii));
break;
default:
break;
}
}
return alert(outb);
}

function ourconfirm(inb) {
var outb=inb, ioff=9855;
for (var ii=1; ii<=6; ii++) {
switch (ii) {
case 1:
outb=outb.replace(/1/g,'1 ' + String.fromCodePoint(ioff + ii));
break;
case 2:
outb=outb.replace(/2/g,'2 ' + String.fromCodePoint(ioff + ii));
break;
case 3:
outb=outb.replace(/3/g,'3 ' + String.fromCodePoint(ioff + ii));
break;
case 4:
outb=outb.replace(/4/g,'4 ' + String.fromCodePoint(ioff + ii));
break;
case 5:
outb=outb.replace(/5/g,'5 ' + String.fromCodePoint(ioff + ii));
break;
case 6:
outb=outb.replace(/6/g,'6 ' + String.fromCodePoint(ioff + ii));
break;
default:
break;
}
}
return confirm(outb);
}

function diceemoji(totv) {
//return '' + totv;
var hprefix='', hsuffix='', classbit='';
var wasr=rollno;
rollno++;
if (1 == 1) {
hsuffix=('' + totv).replace(/1/g, '<sub class=zone></sub>').replace(/2/g, '<sub class=ztwo></sub>').replace(/3/g, '<sub class=zthree></sub>').replace(/4/g, '<sub class=zfour></sub>').replace(/5/g, '<sub class=zfive></sub>').replace(/6/g, '<sub class=zsix></sub>')
if (document.getElementById('tdr').title == '') {
document.getElementById('tdr').title=hprefix + '<span' + classbit + ' id="span' + wasr + '">' + totv + '</span>' + hsuffix;
} else {
document.getElementById('tdr').title+=',' + hprefix + '<span' + classbit + ' id="span' + wasr + '">' + totv + '</span>' + hsuffix;
}
return '' + totv; //hprefix + '<span' + classbit + ' id="span' + wasr + '">' + totv + '</span>' + hsuffix;
}
return (' <span class="' + firstv + ' ' + secv + '">' + totv + '</span>').replace(/\ 1\"/g, ' zone"').replace(/\ 2\"/g, ' ztwo"').replace(/\ 3\"/g, ' zthree"').replace(/\ 4\"/g, ' zfour"').replace(/\ 5\"/g, ' zfive"').replace(/\ 6\"/g, ' zsix"').replace(/\"1\ /g, '"xone ').replace(/\"2\ /g, '"xtwo ').replace(/\"3\ /g, '"xthree ').replace(/\"4\ /g, '"xfour ').replace(/\"5\ /g, '"xfive ').replace(/\"6\ /g, '"xsix ');
}

</script>
<style>
td { text-align: center; vertical-align: top; }
h4 { background-color: lightblue; font-size: 26px; text-align: center; width: 50px; height: 50px; padding: 10px 10px 10px 10px; border: 5px solid black; }
.six { padding-top: 2px; padding-bottom: 18px; }
</style>
</head>
<body onload="checkt();">
<h1 id=myh1><select dir="rtl" style="text-align:right;" onchange="location.href='/HTMLCSS/' + this.value + '_dice_game.html?rand=' + Math.floor(Math.random() * 19878654);" id=gamemode><option value=threeormore>Three or More</option><option value=runforit>Run for It 🏃‍♀️</option><option value=knockout>Knockout 👊</option></select> 🕒<sup>➕➕</sup> Dice 🎲🎲🎲🎲🎲 Game for <div id='dnum' style='display:inline-block;'><select style='display:inline-block;' onchange='fixinstone(this.value);' id='snum'><option value=2>2</option><option value=3>3</option><option value=4>4</option><option value=5>5</option><option value=6>6</option><option value=7>7</option><option value=8>8</option><option value=9>9</option></select></div> Players 👥</h1>
<h3>RJM Programming <a target=_self href='/HTMLCSS/threeormore_dice_game.html' title=Reload>-</a> March, 2018</h3>
<div style='display:none;'>
<h4 id="h1" class="one">․</h4>
<h4 id="h2" class="two">⁚</h4>
<h4 id="h3" class="three">…</h4>
<h4 id="h4" class="four">⁘</h4>
<h4 id="h5" class="five">⁙</h4>
<h4 id="h6" class="six">…<br>…</h4>
</div>

<table style='width:100%;' border=20 cellpadding=5>
<tr id='header'><th><div id='dname1' contenteditable=true>Player 👤 1</div><br>Score</th><th></th><th title='' id='tdr'>Five Dice 🎲🎲🎲🎲🎲 Roll</th><th></th><th><div id='dname2' contenteditable=true>Player 👤 2</div><br>Score</th></tr>
<tr id='game'><td><div id='score1'>Score: 0/0</div></td><td><select style='display:none;' id='gplayer1'><option value='06'>Choose your threeormore value [6] ...</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option></select></td><td id='actiontd'><input id='mybut' style='width:100%;background-color:yellow;height:150px;border:7px solid red;' type='button' onclick='roll();' value='Roll the Dice 🎲🎲🎲🎲🎲 for Each Player'></input></td><td><select style='display:none;' id='gplayer2'><option value='06'>Choose your threeormore value [6] ...</option><option value='6'>6</option><option value='7'>7</option><option value='8'>8</option><option value='9'>9</option></select></td><td><div id='score2'>Score: 0/0</div></td></tr>
</table>

</body>
</html>