Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. long double calculateManhattan(shared_ptr<Board> board) {
  2.     long double power = 0;
  3.     vector<vector<int>> temp;
  4.     int it = 0;
  5.     int height = board->getHeight();
  6.     int weight = board->getWidth();
  7.  
  8.     /// konwersja vector<int> na vector<vector<int>>
  9.     for (int i = 0; i != height; i++) {
  10.         temp.push_back(std::vector<int>());
  11.  
  12.         for (int j = 0; j != weight; j++) {
  13.             temp[i].push_back(board->getData()[it]);
  14.             it++;
  15.         }
  16.     }
  17.  
  18.     for (int i = 0; i != height; i++) {
  19.         for (int j = 0; j != weight; j++) {
  20.  
  21.             if (temp[i][j] == 0) {
  22.                 temp[i][j] = i * j;
  23.             }
  24.             power += abs(  j - ((temp[i][j] - 1) % weight));
  25.             power += abs(  i - ((temp[i][j] - 1) / height));
  26.  
  27.             //odleglosc euklidesowa
  28.             //power += sqrt(abs(j - (long double)((temp[i][j] - 1) % weight) * 2.0 ) + abs( i - ((long double)temp[i][j] - 1.0) / (long double)height*2.0));
  29.         }
  30.     }
  31.     return power;
  32. }
  33.  
  34.  
  35. long double calculateEuklidean(shared_ptr<Board> board) {
  36.     long double power = 0;
  37.     vector<vector<int>> temp;
  38.     int it = 0;
  39.     int height = board->getHeight();
  40.     int weight = board->getWidth();
  41.  
  42.     /// konwersja vector<int> na vector<vector<int>>
  43.     for (int i = 0; i != height; i++) {
  44.         temp.push_back(std::vector<int>());
  45.  
  46.         for (int j = 0; j != weight; j++) {
  47.             temp[i].push_back(board->getData()[it]);
  48.             it++;
  49.         }
  50.     }
  51.  
  52.     for (int i = 0; i != height; i++) {
  53.         for (int j = 0; j != weight; j++) {
  54.  
  55.             if (temp[i][j] == 0) {
  56.                 temp[i][j] = i * j;
  57.             }
  58.  
  59.             power += sqrt(abs((j - (temp[i][j] - 1) % weight) * 2.0 ) + abs( (i - (temp[i][j] - 1.0) / (long double)height)*2.0));
  60.         }
  61.     }
  62.  
  63.     return power;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement