Optimal placement of the boats is pretty simple to find in games like this.
After playing a round or two a simple pattern in the searching algorithm emerges.
After a few iterations of optimization you get the most moves before the bot finds your boat
The probability grid is very neat. One question though, it looks like Ship.DIRECTION_VERTICAL and Ship.DIRECTION_HORIZONTAL might be flipped. It seems consistent, so it's ok. Just the label "vertical" actually means "horizontal" and vice-versa.
for (var i = 0; i < this.shipLength; i++) {
if (direction === Ship.DIRECTION_VERTICAL) {
if (this.playerGrid.cells[x + i][y] === CONST.TYPE_SHIP ||
this.playerGrid.cells[x + i][y] === CONST.TYPE_MISS ||
this.playerGrid.cells[x + i][y] === CONST.TYPE_SUNK) {
return false;
}
}
The Ship.DIRECTION_VERTICAL and Ship.DIRECTION_HORIZONTAL are correct. :) It just seems backward because by a quirk of how the the grid cells are generated in JS, the x-direction is actually visually up/down and the y-direction is visually left/right.
Beat it three times by simply clustering the boats together. Assumed that any program which will be 'good' at Battleship will also be one that will have an efficient way of searching for ships throughout the board. By clustering them all next to each other - the boat wastes moves searching the rest of the board. Cool regardless!
I'm just getting "Please enable Javascript" Checking out the console I'm getting two "SecurityError: The operation is insecure." errors during the localStorage access, probably due to me disabling cookies. Can't find which domain the cookies are under so can't play it now.
After a few iterations of optimization you get the most moves before the bot finds your boat
Here is the setup: http://imgur.com/gallery/5jx3ARG