It's slightly modified version of popular game "Sea Battle". Just click on enemy territory. F5 to restart game.
var d,e,v,f=[],g=[],h="fillStyle",j=a.fillRect.bind(a),k="strokeStyle",m="strokeRect",n=0,o=alert,p=0,q=Math.random,r=function(){return.5-q()},s=[4,3,3,2,2,2,1,1,1,1].sort(r),t=s.sort(r),u=660;for(c.width=u,c.height=u/2,i=10;i--;){for(v=0|q()*(10-s[i]),l=s[i];l--;)f[v+l+10*i]=1;for(v=0|q()*(10-t[i]),l=t[i];l--;)g[v+l+10*i]=1}d=1,b.onmousedown=function(a){var b=a.clientX-350,c=a.clientY-20;2>d&&b>0&&300>b&&c>0&&300>c&&(e=[0|b/30,0|c/30])},setInterval(function(){if(1==d&&e){var b=e[0]+10*e[1];1==g[b]&&(g[b]=9,p++),g[b]||(g[b]=10,d=2),p>19&&(o("Win"),d=9),e=0}if(2==d){var c=0|10*q(),l=0|10*q();e&&(9>e[0]&&(c=e[0]+1,l=e[1]),e=0);var b=c+10*l;1==f[b]&&(f[b]=7,e=[c,l],n++),f[b]||(f[b]=8,d=1),n>19&&(o("Lose"),d=9)}for(i=100;i--;){var r=30*(0|i/10)+12,s=30*(i%10)+12;(1==f[i]||7==f[i])&&(a[h]="#00f",j(s,r,27,27)),f[i]>6&&(a[h]="#000",j(s+10,r+10,10,10)),(9==g[i]||d>8&&1==g[i])&&(a[h]="red",j(s+330,r,27,27)),g[i]>8&&(a[h]="#000",j(s+340,r+10,10,10)),a[k]="#000",a[m](s-2,r-2,30,30),a[k]="#000",a[m](s+328,r-2,30,30)}},9)
dmFyIGQsZSx2LGY9W10sZz1bXSxoPSJmaWxsU3R5bGUiLGo9YS5maWxsUmVjdC5iaW5kKGEpLGs9InN0cm9rZVN0eWxlIixtPSJzdHJva2VSZWN0IixuPTAsbz1hbGVydCxwPTAscT1NYXRoLnJhbmRvbSxyPWZ1bmN0aW9uKCl7cmV0dXJuLjUtcSgpfSxzPVs0LDMsMywyLDIsMiwxLDEsMSwxXS5zb3J0KHIpLHQ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DMwKSxhW2tdPSIjMDAwIixhW21dKHMrMzI4LHItMiwzMCwzMCl9fSw5KQ==
var gameState,
lastClick,
playerGameTable = [],
pcGameTable = [],
fillStyle = "fillStyle",
fillRect = a.fillRect.bind(a),
strokeStyle = "strokeStyle",
strokeRect = "strokeRect",
pcHits = 0,
al = alert,
playerHits = 0,
M = Math.random,
sortFn = function() { return 0.5 - M() },
ships = [4,3,3,2,2,2,1,1,1,1].sort(sortFn),
ships2 = ships.sort(sortFn),
WandH = 660,
start;
c.width = WandH;
c.height = WandH/2;
for (i = 10; i--;) {
start = (M()*(10-ships[i]))|0;
for (l = ships[i]; l--;) {
playerGameTable[start+l+i*10] = 1; // 1 means to add valid visible shippart
}
start = (M()*(10-ships2[i]))|0;
for (l = ships2[i]; l--;) {
pcGameTable[start+l+i*10] = 1; // 1 means to add valid invisible shippart
}
}
gameState = 1;
b.onmousedown = function(e){
var x = e.clientX - 350;
var y = e.clientY - 20;
if (gameState < 2) {
if (x > 0 && x < 300 && y > 0 && y < 300) {
lastClick = [ x/30|0, y/30|0 ];
}
}
};
setInterval(function(){
//Player Move
if (gameState == 1) {
if (lastClick) {
//check if we hit
var index = lastClick[0] + lastClick[1] * 10;
if (pcGameTable[index] == 1) {
pcGameTable[index] = 9;
playerHits++;
}
if (!pcGameTable[index]){
pcGameTable[index] = 10;
gameState = 2;
}
//check if we won already
if (playerHits > 19) {
al('Win');
gameState = 9;
}
lastClick = 0;
}
}
//PC move
if (gameState == 2) {
//check if we hit
var x = M()*10|0;
var y = M()*10|0;
if (lastClick) {
if ( lastClick[0] < 9 ) {
x = lastClick[0] + 1;
y = lastClick[1];
}
lastClick = 0;
}
var index = x + y * 10;
if (playerGameTable[index] == 1) {
playerGameTable[index] = 7;
lastClick = [ x, y ];
pcHits++;
}
if (!playerGameTable[index]){
playerGameTable[index] = 8;
gameState = 1;
}
//check if PC won already
if (pcHits > 19) {
al('Lose');
gameState = 9;
}
}
//drawing player ships
for (i = 100; i--;) {
var temp = (i/10|0)*30+12, temp2 = (i%10)*30+12;
if (playerGameTable[i] == 1 || playerGameTable[i] == 7) {
a[fillStyle] = "#00f";
fillRect(temp2, temp, 27, 27);
}
if (playerGameTable[i] > 6) {
a[fillStyle] = "#000";
fillRect(temp2+10, temp+10, 10, 10);
}
if (pcGameTable[i] == 9 || (gameState > 8 && pcGameTable[i] == 1)) {
a[fillStyle] = "red";
fillRect(temp2+330, temp, 27, 27);
}
if (pcGameTable[i] > 8) {
a[fillStyle] = "#000";
fillRect(temp2+340, temp+10, 10, 10);
}
a[strokeStyle] = "#000";
a[strokeRect](temp2-2, temp-2, 30, 30);
a[strokeStyle] = "#000";
a[strokeRect](temp2+328, temp-2, 30, 30);
}
}, 9)