Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void BoardTree::countAndSetWeight() {
- int actuallRow;
- int tileGoalRow;
- int actuallColumn;
- int tileGoalColumn;
- int counter = 0;
- for(int i = 0; i < board.getSize(); ++i) {
- if(board.fields[i] != board.getSocketIndex()) {
- if(board.fields[i] != i+1) {
- actuallRow = i / board.getWidth();
- tileGoalRow = board.fields[i] - 1 / board.getWidth();
- if(actuallRow < tileGoalRow) {
- counter += tileGoalRow - actuallRow;
- }
- else {
- counter += actuallRow - tileGoalRow;
- }
- actuallColumn = i + board.getWidth() % board.getWidth();
- tileGoalColumn = (board.fields[i] - 1) + board.getWidth() % board.getWidth();
- if(actuallColumn < tileGoalColumn) {
- counter += tileGoalColumn - actuallColumn;
- }
- else {
- counter += actuallColumn - tileGoalColumn;
- }
- }
- }
- }
- weight = counter + numberOfMoves;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement