Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RECURSIVE BACKTRACKING ALGORITHM PSEUDOCODE
- *CODE STRUCTURE*
- create stack
- create list for pathed tiles
- pick start tile
- add start tile to list
- add start tile to stack
- assign start tile to cur_tile
- WHILE stack is not empty{
- IF cur_tile has neighbor unpathed
- {
- connect and move to random neighbor
- }
- ELSE IF cur_tile has no neihbors unpathed
- {
- pop from path and assign poped to cur_tile
- }
- }
- A* PATHFINDING ALGORITHIM PSEUDOCODE
- *TERMS*
- h-score - the heuristic cost of a tile, or how far it is from the end_tile
- g-score - the gained cost of a tile, or how much was spent to get to it.
- m-score - the move score, or the h-score + g-score
- *CODE STRUCTURE*
- *CREATE EVENT CODE*
- create a grid of pathing nodes.
- create a list of neighbors for each node containing the surrounding nodes of each node
- create a parent variable for each node and set them to null
- create a child variable for each node and set to null
- *FUNCTION TO ACTUALLY PATHFIND*
- next_node_in_path pathfinding_function(start_node,end_node)
- {
- create OPEN priority list
- create CLOSED list
- cur_node = start_node
- add cur_node to CLOSED
- WHILE cur_node != end_node
- {
- FOR each neighbor of current node
- {
- IF neighbor is traversible (not a wall) and not in CLOSED
- {
- IF neighbor is not in OPEN
- {
- h-score of neighbor
- get g-score of neighbor
- get m-score of neighbor
- add neighbor to OPEN with priority of m-score
- }
- ELSE IF new g-score to neighbor is smaller than previous g-score path
- {
- calculate new g-score
- get m-score of neighbor
- add neighbor to OPEN with a priority of m-score
- }
- }
- }
- IF open is empty (no paths left!)
- {
- delete datastructures CLOSED and OPEN to avoid memory leaks!
- return NULL
- }
- else
- {
- new_node = ds_priority_delete_min(OPEN);
- new_node.parent = cur_node
- new_node = cur_node
- add cur_node to CLOSED
- }
- }
- WHILE cur_node != start_node
- {
- cur_node.parent.child = cur_node;
- cur_node = cur_node.parent;
- }
- delete datastructures CLOSED and OPEN to avoid memory leaks!
- return cur_node.child
- }
Advertisement
Add Comment
Please, Sign In to add comment