Hacker News new | comments | show | ask | jobs | submit login
Show HN: Battleboat.js – A robot that plays Battleship (kortaggio.github.io)
52 points by Kortaggio on Sept 20, 2014 | hide | past | web | favorite | 16 comments



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


I found a similar setup: 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


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.


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?


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!


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


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



Won my first game.

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


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


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


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.


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


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


won my 3rd game. definitely hard




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: