Advertisement
Guest User

Untitled

a guest
May 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1.     int voronoi(int owner)
  2.     {
  3.         voronoiCalled++;
  4.         vector<Grid> myCells;
  5.         vector<Grid> enemyCells;
  6.         for (int i = 0; i < HEIGHT; i++)
  7.         {
  8.             for (int j = 0; j < WIDTH; j++)
  9.             {
  10.                 Grid& cell = grid[i][j];
  11.                 if (cell.type == TileType::Active)
  12.                 {
  13.                     if (cell.owner == owner)
  14.                         myCells.push_back({ cell });
  15.                     else
  16.                         enemyCells.push_back({ cell });
  17.                 }
  18.             }
  19.         }
  20.         int area = 0;
  21.  
  22.         int enemyOwner = owner == 1 ? 0 : 1;
  23.  
  24.         for (int i = 0; i < HEIGHT; i++)
  25.         {
  26.             for (int j = 0; j < WIDTH; j++)
  27.             {
  28.                 Grid& cell = grid[i][j];
  29.                 if (cell.type == TileType::Void) continue;
  30.                 if (cell.owner == enemyOwner && cell.type == TileType::Active)
  31.                 {
  32.                     area -= cell.troopLevel;
  33.                     area--;
  34.                     continue;
  35.                 }
  36.                 if (cell.owner == owner && cell.type == TileType::Active)
  37.                 {
  38.                     area++;
  39.                     continue;
  40.                 }
  41.                 int closestMyCell = INT_MAX;
  42.                 int closestEnemyCell = INT_MAX;
  43.                 for (int j = 0; j < myCells.size(); j++)
  44.                 {
  45.                     Grid & m = myCells[j];
  46.                     if (info.getDist(cell.pos, m.pos) < closestMyCell)
  47.                         closestMyCell = info.getDist(cell.pos, m.pos);
  48.                 }
  49.                 for (int j = 0; j < enemyCells.size(); j++)
  50.                 {
  51.                     Grid & m = enemyCells[j];
  52.                     if (info.getDist(cell.pos, m.pos) < closestEnemyCell)
  53.                         closestEnemyCell = info.getDist(cell.pos, m.pos);
  54.                 }
  55.  
  56.  
  57.                 if (closestMyCell < closestEnemyCell)
  58.                 {
  59.                     area++;
  60.                 }
  61.             }
  62.         }
  63.         return area;
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement