Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int voronoi(int owner)
- {
- voronoiCalled++;
- vector<Grid> myCells;
- vector<Grid> enemyCells;
- for (int i = 0; i < HEIGHT; i++)
- {
- for (int j = 0; j < WIDTH; j++)
- {
- Grid& cell = grid[i][j];
- if (cell.type == TileType::Active)
- {
- if (cell.owner == owner)
- myCells.push_back({ cell });
- else
- enemyCells.push_back({ cell });
- }
- }
- }
- int area = 0;
- int enemyOwner = owner == 1 ? 0 : 1;
- for (int i = 0; i < HEIGHT; i++)
- {
- for (int j = 0; j < WIDTH; j++)
- {
- Grid& cell = grid[i][j];
- if (cell.type == TileType::Void) continue;
- if (cell.owner == enemyOwner && cell.type == TileType::Active)
- {
- area -= cell.troopLevel;
- area--;
- continue;
- }
- if (cell.owner == owner && cell.type == TileType::Active)
- {
- area++;
- continue;
- }
- int closestMyCell = INT_MAX;
- int closestEnemyCell = INT_MAX;
- for (int j = 0; j < myCells.size(); j++)
- {
- Grid & m = myCells[j];
- if (info.getDist(cell.pos, m.pos) < closestMyCell)
- closestMyCell = info.getDist(cell.pos, m.pos);
- }
- for (int j = 0; j < enemyCells.size(); j++)
- {
- Grid & m = enemyCells[j];
- if (info.getDist(cell.pos, m.pos) < closestEnemyCell)
- closestEnemyCell = info.getDist(cell.pos, m.pos);
- }
- if (closestMyCell < closestEnemyCell)
- {
- area++;
- }
- }
- }
- return area;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement