
Show HN: Battleboat.js – A robot that plays Battleship - Kortaggio
http://kortaggio.github.io/battleboat/
======
GoldenStake
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

Here is the setup:
[http://imgur.com/gallery/5jx3ARG](http://imgur.com/gallery/5jx3ARG)

~~~
christiangenco
I found a similar setup: [http://imgur.com/aOaZYrs](http://imgur.com/aOaZYrs)

It'd be fun to automate the process and find the absolute _best_ strategy
against this deterministic guessing algorithm.

Edit: the only placement that actually matters is that of the smallest ship,
ie: [http://imgur.com/YQ01k95](http://imgur.com/YQ01k95)

------
sadkingbilly
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;
    				}
      }

~~~
Kortaggio
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.

------
amenghra
I always wondered if playing on a hex-grid with some feedback on how close is
the nearest ship would make the game more interesting?

------
urs2102
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!

------
niix
Awesome! Won the first game, was feeling a bit worried at first!

------
frozenport
Isn't there a rule that ship can't touch?

~~~
jmah
Not that I can see here:
[http://www.hasbro.com/common/instruct/battleship.pdf](http://www.hasbro.com/common/instruct/battleship.pdf)

------
wxm
Won my first game.

[Evidence: [http://frupic.frubar.net/32232](http://frupic.frubar.net/32232)]

~~~
have_faith
Thanks for the evidence, I was doubting your posts authenticity.

------
amcnett
Fun. It'd be nice if there were some kind of transition to display the bot's
shots.

------
jaachan
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.

------
Graham42x
It's reached a point where I can no longer beat the bot!

------
kordless
Would have been a more appropriate post for yesterday, yar.

------
yincrash
won my 3rd game. definitely hard

