示例#1
0
 public static int getTileDirection(Tile currTile, Tile nextTile) {
   int currX = currTile.getX(), currY = currTile.getY();
   int nextX = nextTile.getX(), nextY = nextTile.getY();
   int newX, newY;
   for (int k = 0; k < 8; ++k) {
     newX = currX + nextTiles[k][0];
     newY = currY + nextTiles[k][1];
     if (nextX == newX && nextY == newY) {
       return k;
     }
   }
   return -1;
 }
示例#2
0
 public static Tile calculateNextMove(Tile currTile, Tile destination) {
   int newX, newY, currDistance, bestDistance = 9999999;
   int currX = currTile.getX(), currY = currTile.getY();
   int endX = destination.getX(), endY = destination.getY();
   Tile bestTile = null, newTile = null;
   if (currX == endX && currY == endY) return null;
   for (int k = 0; k < 8; ++k) {
     newX = currX + nextTiles[k][0];
     newY = currY + nextTiles[k][1];
     newTile = Grid.getTile(newX, newY);
     if (!newTile.hasUnit() && !newTile.isHasBase()) {
       currDistance = Math.max(Math.abs(newX - endX), Math.abs(newY - endY));
       // System.out.println("(" + newX + ", " + newY + ")-> " + currDistance);
       if (bestDistance > currDistance) {
         bestDistance = currDistance;
         bestTile = newTile;
       }
     }
   }
   return bestTile;
 }
示例#3
0
 public static boolean nextTo(Unit currUnit, Tile destination) {
   int currX = currUnit.getX(), currY = currUnit.getY();
   int nextX = destination.getX(), nextY = destination.getY();
   int newX, newY;
   for (int k = 0; k < 8; ++k) {
     newX = currX + nextTiles[k][0];
     newY = currY + nextTiles[k][1];
     if (newX == nextX && newY == nextY) {
       return true;
     }
   }
   return false;
 }
示例#4
0
 public static Tile nearestEmptyTile(Tile currTile) {
   int currX = currTile.getX(), currY = currTile.getY(), newX, newY;
   if (!currTile.hasUnit()) {
     return currTile;
   }
   for (int k = 0; k < 8; ++k) {
     newX = currX + TileUtils.nextTiles[k][0];
     newY = currY + TileUtils.nextTiles[k][1];
     if (newX < 0 || newX >= Grid.getSizeX() || newY < 0 || newY >= Grid.getSizeY()) continue;
     if (!Grid.masterGrid[newX][newY].hasUnit()) {
       return Grid.getTile(newX, newY);
     }
   }
   return null;
 }
示例#5
0
 private static int dfsBarbarian(Tile currTile, int depth) {
   if (depth == 0) return 0;
   if (currTile == null) return 0;
   if (currTile.hasUnit()) {
     Unit currUnit = currTile.getUnit();
     if (currUnit instanceof Barbarian) return 0;
     return 3;
   }
   if (currTile.isHasBase()) {
     if (currTile.isBarbaric()) return 0;
     return 10;
   }
   int newX, newY;
   int currMax = -999;
   for (int k = 0; k < 8; ++k) {
     newX = currTile.getX() + nextTiles[k][0];
     newY = currTile.getY() + nextTiles[k][1];
     currMax = Math.max(currMax, dfsBarbarian(Grid.getTile(newX, newY), depth - 1) - 1);
   }
   return currMax;
 }