Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void cPathing::traceBack(cVector start, cVector end)
- {
- path_final.push(end);
- int endTest = 0;
- // 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"
- do {
- // create vectors for the north, east, south and west of the top vector
- cVector west(path_final.top().x - 1, path_final.top().y);
- cVector north(path_final.top().x, path_final.top().y - 1);
- cVector east(path_final.top().x + 1, path_final.top().y);
- cVector south(path_final.top().x, path_final.top().y + 1);
- // find the vector with the lowest value
- cVector lowest = west;
- if (board.board[north.x][north.y].getI() < board.board[lowest.x][lowest.y].getI()) {
- lowest = north;
- }
- if (board.board[east.x][east.y].getI() < board.board[lowest.x][lowest.y].getI()) {
- lowest = east;
- }
- if (board.board[south.x][south.y].getI() < board.board[lowest.x][lowest.y].getI()) {
- lowest = south;
- }
- // push the vector with the lowest value to the path
- path_final.push(lowest);
- endTest = board.board[path_final.top().x][path_final.top().y].getI();
- } while (endTest != B_START && path_final.size() < 50);
- // find the node "board.board[][]" with lowest distance around the end node in clockwise orientation of West, North, East and South
- // push the adjacent point with lowest distance to the path stack using the function of "path_final.push(cVector())"
- /* work back from lowest to S to populate the stack with the final path from S to T*/
- // 1. using a do-while loop, starting from the lowest point "cVetor" around the target point, finishing at the start point
- // 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
- // 3. in each loop, push the lowest point "cVetor" to the path stack using the function of "path_final.push()"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement