Module: StepPattern

Included in:
King, Knight
Defined in:
lib/sapphire-chess/movement_rules/move_step_pattern.rb

Instance Method Summary collapse

Instance Method Details

#available_movesObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/sapphire-chess/movement_rules/move_step_pattern.rb', line 2

def available_moves
  move_directions.each_with_object([]) do |(row_direction, column_direction), moves|
    current_row, current_column = location

    current_row += row_direction
    current_column += column_direction
    possible_location = [current_row, current_column]

    next unless board.within_limits?(possible_location)

    if board.empty_square?(possible_location) || enemy_in?(possible_location)
      moves << possible_location
    end
  end
end