Class: SlidingPiece
Instance Attribute Summary
Attributes inherited from Piece
Instance Method Summary collapse
Methods inherited from Piece
#dup, #in_range_of_enemy?, #initialize, #move_into_check?, #sum_positions, #symbol, #valid_moves
Constructor Details
This class inherits a constructor from Piece
Instance Method Details
#explore(dir) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pieces/sliding_piece.rb', line 15 def explore(dir) pos = @pos.dup positions = [] while @board.on_board?([pos[0] + dir[0], pos[1] + dir[1]]) pos[0] += dir[0] pos[1] += dir[1] if @board.occupied?(pos) if @board.piece_at(pos).color == self.color break else positions << pos.dup break end end positions << pos.dup end positions end |
#moves ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/pieces/sliding_piece.rb', line 6 def moves moves = [] move_dirs.each do |dir| moves += explore(dir) end moves end |