Guest User

Untitled

a guest
Apr 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1.         // find neighbor with lowest cost based on costMap
  2.         for(Aim direction : directions) {
  3.             Tile neighbor = ai.getTile(a, direction);
  4.             Ilk ilk = ai.getIlk(neighbor);         
  5.             int cost = costMap[neighbor.getRow()][neighbor.getCol()];
  6.            
  7.             // 0 means unexplored, so skip.        
  8.             if(cost == 0) continue;
  9.            
  10.             // ignore directions that are not passable.
  11.             if(!ilk.isUnoccupied() || !ilk.isPassable()) continue;         
  12.                        
  13.             // ignore direction if it goes to the square
  14.             // that this ant came from last turn. This
  15.             // helps avoid ants dancing back and forth between
  16.             // two squares because of a conflict in objectives.
  17.             if(antMoveHistory.get(a) == direction) {
  18.                 historySkipped = true;
  19.                 continue;
  20.             }      
  21.            
  22.            
  23.             // if lowestCost is undefined,
  24.             // use current direction and cost as baseline
  25.             if(lowestCost == -1) {             
  26.                 selectedDir = direction;
  27.                 lowestCost = cost;
  28.                 continue;
  29.             }
  30.            
  31.             // if current cost is lower than previous
  32.             // lowestCost, use it as the new lowestCost
  33.             if(cost < lowestCost) {
  34.                 lowestCost = cost;
  35.                 selectedDir = direction;
  36.             }
  37.         }
Add Comment
Please, Sign In to add comment