Skip to content

Commit

Permalink
feature: add horizontal move class
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland Studer committed Dec 22, 2021
1 parent 4cd608c commit d8e1285
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/move/horizontal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Move
# unlimited horizontal movement for a piece
class Horizontal
def unhindered_legal_end_positions(position)
position = Position.parse(position) if position.is_a? String
letters = ("A".."H").to_a - [position.letter]
letters.map { |l| Position.new(l, position.number) }
end
end
end
2 changes: 2 additions & 0 deletions main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
require_relative 'lib/board'
require_relative 'lib/position'
require_relative 'lib/piece'

require_relative 'lib/move/horizontal'
14 changes: 14 additions & 0 deletions test/move/horizontal_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require "minitest/autorun"

module Move
class HorizontalTest < Minitest::Test
def test_returns_unhindered_positions
move = Move::Horizontal.new

legal_end_positions = %w[A3 B3 C3 E3 F3 G3 H3].map { |p| Position.parse(p) } # without D4
assert_equal legal_end_positions, move.unhindered_legal_end_positions("D3")
end
end
end

0 comments on commit d8e1285

Please sign in to comment.