Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. void BoardTree::countAndSetWeight() {
  2.     int actuallRow;
  3.     int tileGoalRow;
  4.     int actuallColumn;
  5.     int tileGoalColumn;
  6.     int counter = 0;
  7.  
  8.     for(int i = 0; i < board.getSize(); ++i) {
  9.         if(board.fields[i] != board.getSocketIndex()) {
  10.             if(board.fields[i] != i+1) {
  11.                 actuallRow = i / board.getWidth();
  12.                 tileGoalRow = board.fields[i] - 1 / board.getWidth();
  13.  
  14.                 if(actuallRow < tileGoalRow) {
  15.                     counter += tileGoalRow - actuallRow;
  16.                 }
  17.                 else {
  18.                     counter += actuallRow - tileGoalRow;
  19.                 }
  20.  
  21.                 actuallColumn = i + board.getWidth() % board.getWidth();
  22.                 tileGoalColumn = (board.fields[i] - 1)  + board.getWidth() % board.getWidth();
  23.  
  24.                 if(actuallColumn < tileGoalColumn) {
  25.                     counter += tileGoalColumn - actuallColumn;
  26.                 }
  27.                 else {
  28.                     counter += actuallColumn - tileGoalColumn;
  29.                 }
  30.             }
  31.         }
  32.     }
  33.  
  34.     weight = counter + numberOfMoves;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement