Hacker News new | ask | show | jobs
by sadkingbilly 4291 days ago
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;
				}
  }
1 comments

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.