Skip to content

Commit

Permalink
Ensure initial positions are :across or :down
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Brown committed Feb 9, 2014
1 parent 6350c79 commit 2eef442
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/battleship/board.rb
Expand Up @@ -77,6 +77,7 @@ def expand_positions(positions)
end

def expand_position(x, y, length, direction)
raise ArgumentError unless [:across, :down].include?(direction)
dx, dy = direction == :across ? [1, 0] : [0, 1]
(0 ... length).map{ |i| [x + i * dx, y + i * dy] }
end
Expand Down

0 comments on commit 2eef442

Please sign in to comment.