Supposed I have this data structure:
I am using a hash map to represent the data structure:
HashMap<Point, Tile> board;
Where Point class is just consisting of int x and int y which is used to represent the coordinate in the data structure above.
Point(int x, int y);
In Tile class, every tile has an animal token on top. Such that:
Tile(Habitat habitat, Animal animalToken);
My aim is to calculate the score according to the animal tokens placed on top of the tiles.
This link has the rules for scoring for each animal.
What I've tried is completely mess, which always end up with 100+ of codes just to calculate a score for one specific animal. Is there any algorithm/searching algorithm I should know about to make my life easier?
PS: I have little knowledge on graph structure.
Edit:
private static ArrayList<Tile> adjacentAvailableTile(Point point)
{
return adjacentAvailableTile(adjacentAvailablePoints(point));
}
private static ArrayList<Tile> adjacentAvailableTile(ArrayList<Point> points)
{
ArrayList<Tile> availableTiles = new ArrayList<>();
for (Point point : points)
{
Tile tile = board.get(point);
availableTiles.add(tile);
}
return availableTiles;
}
private static ArrayList<Point> adjacentAvailablePoints(Point originPoint)
{
Point[] sixAdjacentPoint = new Point[6];
int i = 0;
for (Position pos : Position.values()) //loop through enum Position
{
//sixAdjacentPoint now has the adjacent points of the given point
sixAdjacentPoint[i++] = getPoint(originPoint, pos);
}
ArrayList<Point> availablePoint = new ArrayList<>();
for (Point point : sixAdjacentPoint)
{
if (board.containsKey(point))
availablePoint.add(point);
}
return availablePoint;
}
I now can find adjacent tiles from a given point.