Package ai.nettogrof.battlesnake.info
Class FoodInfo
- java.lang.Object
-
- ai.nettogrof.battlesnake.info.FoodInfo
-
public class FoodInfo extends Object
FoodInfo is the class that contain all the informations and related methods to foods- Version:
- Spring 2021
- Author:
- carl.lajeunesse
-
-
Field Summary
Fields Modifier and Type Field Description private gnu.trove.list.array.TIntArrayListpositionArraylist (int) of all food position (based on square formula)
-
Constructor Summary
Constructors Constructor Description FoodInfo(com.fasterxml.jackson.databind.JsonNode board)Single constructor need the jsonNode board
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)gnu.trove.list.array.TIntArrayListgetPosition()Return all food positionintgetShortestDistance(int headPos)Get the shortest distance from the position provided to a food.intgetShortestDistance(int headX, int headY)Get the shortest distance from the position provided to a food.inthashCode()booleanisFood(int pos)Check if there's a food on a particular square (based on square formula)booleanisFood(int squareX, int squareY)Check if there's a food on a particular squareprivate voidsetFoodInfo(com.fasterxml.jackson.databind.JsonNode foodArray)Take the json field food and convert it into the arraylist position
-
-
-
Method Detail
-
getShortestDistance
public int getShortestDistance(int headX, int headY)Get the shortest distance from the position provided to a food. Doesn't check Snake bodies/hazard/etc- Parameters:
headX- The position XheadY- The position Y- Returns:
- int the number of square between the pos, and the nearest food
-
getShortestDistance
public int getShortestDistance(int headPos)
Get the shortest distance from the position provided to a food. Doesn't check Snake bodies/hazard/etc- Parameters:
headPos- The square position (based on square formula)- Returns:
- int the number of square between the pos, and the nearest food
-
isFood
public boolean isFood(int squareX, int squareY)Check if there's a food on a particular square- Parameters:
squareX- Square position XsquareY- Square position Y- Returns:
- boolean if there's a food
-
isFood
public boolean isFood(int pos)
Check if there's a food on a particular square (based on square formula)- Parameters:
pos- square position- Returns:
- boolean if there's a food
-
setFoodInfo
private void setFoodInfo(com.fasterxml.jackson.databind.JsonNode foodArray)
Take the json field food and convert it into the arraylist position- Parameters:
foodArray- JsonNode field food
-
getPosition
public gnu.trove.list.array.TIntArrayList getPosition()
Return all food position- Returns:
- the position
-
-