コード例 #1
0
ファイル: Util.java プロジェクト: ryancheu/Battle2013Team0
 public static void continueComputation() {
   // System.out.println("b" + Clock.getBytecodesLeft());
   if (!started) return;
   while (!que.isEmpty()) {
     if (Clock.getBytecodesLeft() < 2000) return;
     MapLocation loc = que.poll().b;
     if (visited[loc.x][loc.y]) continue;
     visited[loc.x][loc.y] = true;
     int thisDist = distances[loc.x][loc.y] + costs[loc.x][loc.y];
     int nextX, nextY, dy;
     for (int dx = -1; dx <= 1; ++dx)
       for (dy = -1; dy <= 1; ++dy) {
         nextX = loc.x + dx;
         nextY = loc.y + dy;
         if (nextX < 0 || nextX >= gridWidth || nextY < 0 || nextY >= gridHeight) continue;
         if (distances[nextX][nextY] > thisDist) {
           distances[nextX][nextY] = thisDist;
           que.add(Pair.of(thisDist, new MapLocation(nextX, nextY)));
           parents[nextX][nextY] = loc;
         }
       }
     // System.out.println("c" + Clock.getBytecodesLeft());
   }
   done = true;
 }
コード例 #2
0
ファイル: Util.java プロジェクト: ryancheu/Battle2013Team0
 public static void startComputation(MapLocation start) {
   mapWidth = Map_Width;
   mapHeight = Map_Height;
   squareSize = (int) Math.sqrt(mapWidth * mapHeight) / 10;
   System.out.println(squareSize);
   gridWidth = (mapWidth + squareSize - 1) / squareSize;
   gridHeight = (mapHeight + squareSize - 1) / squareSize;
   startSquare = new MapLocation(start.x / squareSize, start.y / squareSize);
   distances = new int[gridWidth][gridHeight];
   costs = new int[gridWidth][gridHeight];
   parents = new MapLocation[gridWidth][gridHeight];
   visited = new boolean[gridWidth][gridHeight];
   done = false;
   mines = mRC.senseNonAlliedMineLocations(start, MAX_DIST_SQUARED);
   for (int i = 0; i < gridWidth; i++)
     for (int j = 0; j < gridHeight; j++) {
       costs[i][j] = squareSize;
       distances[i][j] = MAX_DIST_SQUARED * GameConstants.MINE_DEFUSE_DELAY;
       visited[i][j] = false;
       parents[i][j] = null;
       if (i == gridWidth - 1)
         costs[i][j] += GameConstants.MINE_DEFUSE_DELAY * (mapWidth % squareSize);
       if (j == gridHeight - 1)
         costs[i][j] += GameConstants.MINE_DEFUSE_DELAY * (mapHeight % squareSize);
     }
   for (MapLocation mine : mines) {
     costs[mine.x / squareSize][mine.y / squareSize] +=
         GameConstants.MINE_DEFUSE_DELAY / squareSize;
   }
   distances[startSquare.x][startSquare.y] = 0;
   que = new PriorityQueue<Pair<Integer, MapLocation>>();
   que.add(Pair.of(0, startSquare));
   started = true;
 }