Method: ChessData::Board#locations_of

Defined in:
lib/chess_data/board.rb

#locations_of(piece, identifier = "") ⇒ Object

Return the location of given piece on board. Identifier can be a letter or number, and if present the piece location must contain it



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/chess_data/board.rb', line 112

def locations_of piece, identifier=""
  identifier = identifier.upcase
  result = []

  8.times do |row|
    8.times do |col|
      if @board[row][col] == piece
        square = Board.coords_to_square col, row
        if identifier.empty? || square.include?(identifier)
          result << square
        end
      end
    end
  end

  return result
end