Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // find neighbor with lowest cost based on costMap
- for(Aim direction : directions) {
- Tile neighbor = ai.getTile(a, direction);
- Ilk ilk = ai.getIlk(neighbor);
- int cost = costMap[neighbor.getRow()][neighbor.getCol()];
- // 0 means unexplored, so skip.
- if(cost == 0) continue;
- // ignore directions that are not passable.
- if(!ilk.isUnoccupied() || !ilk.isPassable()) continue;
- // ignore direction if it goes to the square
- // that this ant came from last turn. This
- // helps avoid ants dancing back and forth between
- // two squares because of a conflict in objectives.
- if(antMoveHistory.get(a) == direction) {
- historySkipped = true;
- continue;
- }
- // if lowestCost is undefined,
- // use current direction and cost as baseline
- if(lowestCost == -1) {
- selectedDir = direction;
- lowestCost = cost;
- continue;
- }
- // if current cost is lower than previous
- // lowestCost, use it as the new lowestCost
- if(cost < lowestCost) {
- lowestCost = cost;
- selectedDir = direction;
- }
- }
Add Comment
Please, Sign In to add comment