for(_='er~";Z-1]Xp||W=[]V+1UA[S){QinP0<O14-p]Nstyle"+(Si]1>h?")6<i%8?&&);elseC(2":"=0;.push(function(1>hSpdocument.createElement("t=ablefor(if(>"++"</ ===WOh>i;i++)..margP=>p)S8*h+7]+=S.Pn~HTML=.appendChild(1>j++;6<j3,bTbYTY"autoZvar AV,RV,p=s=h=n=i=j=k=l=m(C=a,cQa)20aQij="ZkV;m="Z16l="<td =\'paddPg:9px;bord~:1px solid #000;background:ip?"cyanred#ff0+(7>iO?Zcursor:poPt~;\'onclick=\'C(iU)+\';\'+("rowspan=2><b b> td>,8>i?7>i?j+=l:m=l:klR[0]k.rev~se().joP("+m;R[1]j} 21a)Os?(n=1,=(Oh6W14p?p+2:pU)%16]++,s--,0),setTimeout(Q1)},500)):(n=0,1<]7>p%8?C(pU):2)),Y0>h?"Reload for new gameIn hand: "+s+"<br/>"YourAI\'s+" turnZ 22aQ1]Q7>7<p15N,SN8<p14>Op6pX+U],X=U]=0}0715W(h=1:0j=i71i=8;j152Oh);;)OSi=8+Date.now()%7]QC(iUbreak}} 23a?(h=-1,al~t("You 1<c?"wPlose)):1>n(s==aX,]=0,1){i16A0:7i2RTr)0)}})(';g=/[^ -MRTY[-}]/.exec(_);)with(_.split(g))_=join(shift());eval(_)
// JS1K ENTRY
// Title: Dakon (Javanese Congkak)
// by Muhammad Rifqi Priyo Susanto
// create container and information text
// and place them
b.appendChild(T=document.createElement("table"));
b.appendChild(Y=document.createElement("table"));
// set the margin to auto
// so the container is centered
// because the element tag is "table"
T.style.margin=Y.style.margin="auto";
// initialize variable
var N=[], R=[],
p=s=h=n=i=j=k=l=m=0;
// game container
(Z=function(task,param){
// initialize game
if(!task){
for(i=0;i<16;i++)N.push(i%8>6?0:7);
for(i=0;i<2;i++)R.push(T.appendChild(document.createElement("tr")));
Z(20);
// draw the game
}else if(task===20){
for(i=0,j="",k=[],m="";i<16;i++){
// draw cell aka "house"
l="<td style='padding:9px;border:1px solid #000;background:"+
(i===p?(h<1?"cyan":"red"):"#ff0")+
(i<7&&N[i]>0
?";cursor:pointer;'onclick='Z("+(i+1)+")'"
:";'"
)+
(i%8>6?"rowspan=2><b>"+N[i]+"</b>":">"+N[i]+"</td>");
i<8?i<7?j+=l:m=l:k.push(l);
}
R[0].innerHTML=k.reverse().join("")+m;
R[1].innerHTML=j;
// step event
}else if(task===21){
// if still have seed in hand, run step
if(s>0){
// declare step event
n=1;
// add 1 for next house
// move pointer
N[p=(
h>0&&p===6 || h<1&&p===14 ?
p+2:
p+1
)%16]++;
// decrease seed amount in hand
s--;
// draw the game
Z(20);
// set next step event
setTimeout(function(){Z(21)},500)
// if have no seed in hand
}else{
// stop step event
n=0;
// if seed amount in pointed
// house is more than 1
// and it's not store house
N[p]>1&&p%8<7?
// next step
Z(p+1):
// else
// run analyzer
Z(22)
}
// inform player
// if game has ended, add notice to reload for new game
// else, tell seed amount in hand and whose turn is now
Y.innerHTML=h<0?
"Reload for new game":
"In hand: "+s+"<br/>"+(h<1?"Your":"AI's")+" turn"
;
// game analyzer + AI
}else if(task===22){
if(N[p]===1){
// shooting mechanism (aka "nembak")
// if seed amount in pointed house is 1 and
// pointed house is one of opponent's house then
// add seed from shooted house to storehouse
// and set seed amount of the shooted house to zero
if(h<1&&p<7 || h>0&&p>7&&p<15){
N[h*8+7]+=N[14-p],
N[14-p]=0
}
// bringing mechanism (aka "mikul")
// if seed amount in pointed house is 1 and
// the pointed house is one of opponent's house
// and there IS seed (not 0) at nearby house
// (not storehouse) then
// add seed from nearby house to storehouse
// and set seed amount of the nearby house to zero
if(h<1&&p>8&&p<14 || h>0&&p>0&&p<6){
N[h*8+7]+=N[p-1]+N[p+1],
N[p-1]=N[p+1]=0
}
}
// draw the game
Z(20);
// if pointer is not at storehouse,
// next turn
!(h<1&&p===7 || h>0&&p===15) && (h=h<1?1:0);
// check player's houses (except storehouse)
for(i=0,j=0;i<7;i++)N[i]<1&&j++;
// if it's 0 at all player's houses,
// AI win!
j>6&&Z(23,1);
// check AI's houses (except storehouse)
for(i=8,j=0;i<15;i++)N[i]<1&&j++;
// if it's 0 at all AI's houses,
// player win!
j>6&&Z(23,2);
// if it's AI's turn
if(h>0)
// run
// Artificial Intelegence
// by using loop and random select
for(;;){
// if sample house is more than 0
if(N[i=8+Date.now()%7]>0){
// select the house
Z(i+1);
break;
}
}
// game over
}else if(task===23){
// nobody's turn
h=-1;
// tell who is the winner
alert("You "+(param>1?"win":"lose"));
// select house
}else{
// if step event is NOT running,
if(n<1)
// set the:
// - seed amount in hand
// - pointer
// - seed amount at selected house to zero
s=N[p=task-1],
N[p]=0,
// run step event
Z(21);
}
})();