lib/battlesnake/board.rb in battlesnake-0.1.3 vs lib/battlesnake/board.rb in battlesnake-0.1.4

- old
+ new

@@ -39,16 +39,17 @@ @food = data['food'].map{ |attrs| Location.new(attrs) } @hazards = data['hazards'].map{ |attrs| Location.new(attrs) } end ## - # List of all occupied locations on the board; snakes, food, hazards, etc + # List of all occupied locations on the board; snakes, hazards, etc. + # Does NOT include food, since we don't want to avoid that. # # @return [Array<Location>] list of occupied locations def occupied_locations return @occupied_locations if defined?(@occupied_locations) - @occupied_locations = snakes.map(&:body).flatten + food + hazards + @occupied_locations = snakes.map(&:body).flatten + hazards end ## # Whether the supplied location is occupied. # @@ -75,9 +76,19 @@ # @param [Location] location being tested for availability. # # @return [Boolean] true if location is available (unoccupied by snakes, food, hazards, etc). def available?(location) on_board?(location) && !occupied?(location) + end + + ## + # Whether the supplied location is food. + # + # @param [Location] location being tested for availability. + # + # @return [Boolean] true if location is food. + def food?(location) + food.include?(location) end ## # List of directions (up, down, left, right) available for moving from given _Location_. # \ No newline at end of file