Advertisement
Guest User

BFSPropagatingInfluence

a guest
Nov 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. void InfluenceWorld::BFSToAddInfluence(int startingIndex)
  2. {
  3.     float influence = 1.0f;
  4.  
  5.     std::queue<std::pair<int, float>> workingSet;
  6.  
  7.     std::map<int, bool> finishedSet;
  8.  
  9.     workingSet.push(std::make_pair(startingIndex, influence));
  10.  
  11.     while (!workingSet.empty())
  12.     {
  13.         std::pair<int, float> curIndexInfluencePair = workingSet.front();
  14.         workingSet.pop();
  15.  
  16.         if (finishedSet.find(curIndexInfluencePair.first) != finishedSet.end())
  17.         {
  18.             continue;
  19.         }
  20.  
  21.         int gridX = -1;
  22.         int gridY = -1;
  23.         GetGridPointFromIndex(curIndexInfluencePair.first, gridX, gridY);
  24.  
  25.         int neighborIndex = -1;
  26.  
  27.         if (curIndexInfluencePair.second / 2 >= 0.125)
  28.         {
  29.             if (gridX > 0)
  30.             {
  31.                 neighborIndex = curIndexInfluencePair.first - 1;
  32.                 workingSet.push(std::make_pair(neighborIndex, (curIndexInfluencePair.second / 2)));
  33.             }
  34.  
  35.             if (gridX < kWorldWidth - 1)
  36.             {
  37.                 neighborIndex = curIndexInfluencePair.first + 1;
  38.                 workingSet.push(std::make_pair(neighborIndex, (curIndexInfluencePair.second / 2)));
  39.             }
  40.  
  41.             if (gridY > 0)
  42.             {
  43.                 neighborIndex = curIndexInfluencePair.first - kWorldWidth;
  44.                 workingSet.push(std::make_pair(neighborIndex, (curIndexInfluencePair.second / 2)));
  45.             }
  46.  
  47.             if (gridY < kWorldHeight - 1)
  48.             {
  49.                 neighborIndex = curIndexInfluencePair.first + kWorldWidth;
  50.                 workingSet.push(std::make_pair(neighborIndex, (curIndexInfluencePair.second / 2)));
  51.             }
  52.         }
  53.        
  54.         m_pTiles[curIndexInfluencePair.first]->AddInfluence(curIndexInfluencePair.second);
  55.  
  56.         finishedSet[curIndexInfluencePair.first] = true;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement