module Stones::WithHead

Public Instance Methods

can_move?(direction) click to toggle source
# File lib/stones/board/with_head.rb, line 3
def can_move?(direction)
  within_bounds? next_position(direction)
end
move!(direction) click to toggle source
# File lib/stones/board/with_head.rb, line 7
def move!(direction)
  move_to! next_position(direction)
end
move_to_edge!(direction) click to toggle source
# File lib/stones/board/with_head.rb, line 11
def move_to_edge!(direction)
  move!(direction) while can_move?(direction)
end

Private Instance Methods

move_to!(position) click to toggle source
# File lib/stones/board/with_head.rb, line 17
def move_to!(position)
  raise OutOfBoardError unless within_bounds? position
  @head_position = position
end
next_position(direction) click to toggle source
# File lib/stones/board/with_head.rb, line 22
def next_position(direction)
  direction.call(*@head_position)
end