-
Notifications
You must be signed in to change notification settings - Fork 3
/
4.htm
1 lines (1 loc) · 3.75 KB
/
4.htm
1
<body id=b><script>b.innerHTML="<center><style>*{font-family:arial;cursor:pointer;-moz-user-select:none;-webkit-user-select:none;user-select:none}.i{border-radius:50%;display:inline-block;line-height:0;box-shadow:0 0 3px}table .i{vertical-align:top}</style><h1>2-Player games ++</h1><p><button id=C onclick=m=[];f=2;a(p=g=s=1)>Tic-Tac-Toe</button> <button id=D onclick=m=[];f=3;a(p=g=s=1)>Tic-Tac-Toe 3D</button> <button id=E onclick=F.style.opacity=.5;m=[];f=1;a(p=g=s=1)>4 in a row</button> <button id=F onclick=m=[];f=w=0;m[27]=m[36]=-1;m[28]=m[35]=1;a(p=g=s=1)>Reversi</button><p id=z>"; a=()=>{l=0;h="<p>";if(0==f){h+="<table border>";for(j=8;j--;)for(h+="<tr>",k=8;k--;)h+="<th width=20 onclick=q("+[l,7-j,7-k]+") id=t"+l+" bgcolor=#5b5>"+["<table bgcolor=0 width=20 height=20 class=i></table>","\u00a0","<table bgcolor=#fff width=20 height=20 class=i></table>"][1+(m[l]=m[l++]||0)];h+="</table><br>"}if(1==f){h+="<table cellspacing=5 bgcolor=#aad>";for(j=6;j--;)for(h+="<tr>",k=7;k--;)h+="<th width=20 onclick=onclick=q("+[l,7-j,7-k]+") bgcolor=#fff style='border-radius:50%;overflow:hidden'>"+["<table bgcolor=red width=20 height=20 class=i></table>","\u00a0","<table bgcolor=yellow width=20 height=20 class=i></table>"][1+(m[l]=m[l++]||0)];h+="</table><br>"}if(2==f){h+="<table style=border-collapse:collapse>";for(j=3;j--;)for(h+="<tr>",k=3;k--;)h+="<th width=20 onclick=q("+[l,7-j,7-k]+") style='"+(j?"border-bottom:2px solid;":"")+(k?"border-right:2px solid;":"")+"'>"+"X\u00a0O"[1+(m[l]=m[l++]||0)];h+="</table><br>"}if(3==f)for(i=3;i--;){h+="<table border style=margin-left:"+4*(1-i)+"em>"; for(j=3;j--;)for(h+="<tr>",k=3;k--;)h+="<th width=20 onclick=q("+[l,7-j,7-k]+")>"+"X\u00a0O"[1+(m[l]=m[l++]||0)];h+="</table><br>"}~m.indexOf(0)?(h+=g?"Next player: <b>"+[["<table bgcolor=0 width=20 height=20 class=i></table>","\u00a0","<table bgcolor=#fff width=20 height=20 class=i></table>"],["<table bgcolor=red width=20 height=20 class=i></table>","\u00a0","<table bgcolor=yellow width=20 height=20 class=i></table>"],"X\u00a0O","X\u00a0O"][f][p+1]+"</b>":"<b>"+[["<table bgcolor=0 width=20 height=20 class=i></table>", "\u00a0","<table bgcolor=#fff width=20 height=20 class=i></table>"],["<table bgcolor=red width=20 height=20 class=i></table>","\u00a0","<table bgcolor=yellow width=20 height=20 class=i></table>"],"X\u00a0O","X\u00a0O"][f][-p+1]+"</b> won!",f||(h+="<p><button onclick=a(p=-p)>Pass")):h+=f?g?"draw":[["<table bgcolor=0 width=20 height=20 class=i></table>","\u00a0","<table bgcolor=#fff width=20 height=20 class=i></table>"],["<table bgcolor=red width=20 height=20 class=i></table>","\u00a0","<table bgcolor=yellow width=20 height=20 class=i></table>"],"X\u00a0O","X\u00a0O"][f][-p+1]+" won!":w?0<w?"<table bgcolor=#fff width=20 height=20 class=i></table> won!":"<table bgcolor=0 width=20 height=20 class=i></table> won!":"Draw!";z.innerHTML=h;~f&&(C.style.opacity=D.style.opacity=E.style.opacity=F.style.opacity=0.5,[F,E,C,D][f].style.opacity=1)};q=(c,d,e)=>{if(g&&!m[c]){if(1<f)for(i=3;i--;)for(j=3;j--;)if(k=9*i,l=3*j,~[m[k+j]+m[k+j+3]+m[k+j+6],m[k+l]+m[k+l+1]+m[k+l+2],m[k+4]+m[k+0]+m[k+8],m[k+4]+m[k+2]+m[k+6],m[l+10]+m[l]+m[l+20],m[l+10]+m[l+2]+m[l+18],m[i+12]+m[i]+m[i+24],m[i+12]+m[i+6]+m[i+18],m[13]+m[0]+m[26],m[13]+m[2]+m[24],m[13]+m[6]+m[20],m[13]+m[8]+m[18],m[l+i]+m[l+i+9]+m[l+i+18]].indexOf(3*(m[c]=p)))g=0;if(1==f){for(;35>c&&!m[c+7];c+=7);for(i=6;i--;)for(j=7;j--;)if(k=7*i+j,~[4>j&&m[k]+m[k+1]+m[k+2]+m[k+3],3>i&&m[k]+m[k+7]+ m[k+14]+m[k+21],3>i&&4>j&&m[k]+m[k+8]+m[k+16]+m[k+24],3>i&&2<j&&m[k]+m[k+6]+m[k+12]+m[k+18]].indexOf(4*(m[c]=p)))g=0}if(!f){s=0;for(i=2;~i--;)for(j=2;~j--;)if(i|j&&(t=0,m[8*(d+i)+e+j]==-p)){k=d+i;for(l=e+j;~k&&9>k&&~l&&9>l&&(m[8*k+l]!=p||!(s=t=1))&&m[8*k+l];k+=i,l+=j);if(t)for(u=d,v=e;u!=k||v!=l;u+=i,v+=j)m[8*u+v]=p}w=0;for(i=64;i--;)w+=m[i]}s&&(p=-p);a()}}</script>