Advertisement
Guest User

shoveThatInYourTracebackAndPathIt

a guest
Nov 20th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. void cPathing::traceBack(cVector start, cVector end)
  2. {
  3.     path_final.push(end);
  4.     int endTest = 0;
  5.  
  6.     // push the end point to the path stack using the function "path_final.push()", note that the data type in the path stack is "cVector"
  7.     do {
  8.         // create vectors for the north, east, south and west of the top vector
  9.         cVector  west(path_final.top().x - 1, path_final.top().y);
  10.         cVector north(path_final.top().x, path_final.top().y - 1);
  11.         cVector  east(path_final.top().x + 1, path_final.top().y);
  12.         cVector south(path_final.top().x, path_final.top().y + 1);
  13.         // find the vector with the lowest value
  14.         cVector lowest = west;
  15.         if (board.board[north.x][north.y].getI() < board.board[lowest.x][lowest.y].getI()) {
  16.             lowest = north;
  17.         }
  18.         if (board.board[east.x][east.y].getI() < board.board[lowest.x][lowest.y].getI()) {
  19.             lowest = east;
  20.         }
  21.         if (board.board[south.x][south.y].getI() < board.board[lowest.x][lowest.y].getI()) {
  22.             lowest = south;
  23.         }
  24.         // push the vector with the lowest value to the path
  25.         path_final.push(lowest);
  26.  
  27.         endTest = board.board[path_final.top().x][path_final.top().y].getI();
  28.     } while (endTest != B_START && path_final.size() < 50);
  29.     // find the node "board.board[][]" with lowest distance around the end node in clockwise orientation of West, North, East and South  
  30.  
  31.  
  32.    
  33.     // push the adjacent point with lowest distance to the path stack using the function of "path_final.push(cVector())"
  34.  
  35.  
  36.  
  37.     /* work back from lowest to S to populate the stack with the final path from S to T*/
  38.     // 1. using a do-while loop, starting from the lowest point "cVetor" around the target point, finishing at the start point
  39.     // 2. in each loop, find the lowest node "board.board[][]" from the four adjacent node of the current node in clockwise orientation of West, North, East and South
  40.     // 3. in each loop, push the lowest point "cVetor" to the path stack using the function of "path_final.push()"
  41.  
  42.    
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement