Advertisement
321igor

Untitled

Mar 19th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. void prioritizeLocations(List<Location> unsorted, PirateGame game, Pirate pirate) {
  2.         int[] values = new int[unsorted.size()];
  3.         int minDist;    //Minimum distance
  4.         int currentDist;    //Temporary variable
  5.         for (int i = 0; i < unsorted.size(); i++) {
  6.             minDist = Integer.MAX_VALUE;
  7.             for (Pirate enemy : game.enemySoberPirates()) {
  8.                 currentDist = game.distance(enemy, unsorted.get(i));
  9.                 if (currentDist < minDist)
  10.                     minDist = currentDist;
  11.             }
  12.             values[i] = minDist;    //Rating a location by the distance from the closest enemy ship
  13.         }
  14.         quickSort(values, 0, values.length - 1, unsorted);  //Sorts safe first
  15.         boolean treasure = pirate.hasTreasure();
  16.         if (treasure)
  17.             game.debug("We have a treasure, ID: " + pirate.getId());
  18.         boolean booze = pirate.getReloadTurns() <= 0;
  19.         if (booze)
  20.             game.debug("We have booze, ID: " + pirate.getId());
  21.         if ((!pirate.hasTreasure() && pirate.getReloadTurns() <= 0)) {    //Go dangerous if got no treasure but have booze
  22.             Collections.reverse(unsorted);  //Dangerous road
  23.             game.debug("We went the dangerous road! ID: " + pirate.getId());
  24.         }
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement