Advertisement
Ramaraunt1

a* rewritten

Jan 24th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. ///a_star_find_path(start_node,end_node);
  2.  
  3. node_width = 32;
  4. start_node = argument0;
  5. cur_node = argument0;
  6. end_node = argument1;
  7. pathed = ds_list_create();
  8. ds_list_add(pathed,start_node);
  9.  
  10. while(cur_node != end_node)
  11. {
  12. lowest_node = noone;
  13. lowest_value = 99999999999;
  14. for(n = 0; n < ds_list_size(cur_node.neighbors); n ++)
  15. {
  16. if (move_score(start_node,end_node,ds_list_find_value(cur_node.neighbors,n)) < ds_list_find_value(cur_node.neighbors,n).movment_score || ds_list_find_value(cur_node.neighbors,n).movement_score == noone)
  17. {
  18. if (ds_list_find_value(cur_node.neighbors,n).movement_score < lowest_value && ds_list_find_index(pathed,ds_list_find_value(cur_node.neighbors,n)) == -1)
  19. {
  20. lowest_value = ds_list_find_value(cur_node.neighbors,n).movement_score;
  21. lowest_node = ds_list_find_value(cur_node.neighbors,n);
  22. }
  23. }
  24. }
  25.  
  26. if (lowest_node == noone)
  27. {
  28. with(obj_pathing_node)
  29. {
  30. if (movement_score != noone && movement_score < other.lowest_value && ds_list_find_index(other.pathed,id) == -1)
  31. {
  32. other.lowest_node = id;
  33. other.lowest_value = movement_score;
  34. }
  35. }
  36.  
  37. if (lowest_node == noone) {return noone;}
  38. else
  39. {
  40. lowest_node.parent = cur_node;
  41. cur_node = lowest_node;
  42. }
  43. }
  44. else
  45. {
  46. lowest_node.parent = cur_node;
  47. cur_node = lowest_node;
  48. }
  49. }
  50.  
  51. while (cur_node != start_node)
  52. {
  53. cur_node.parent.child = cur_node;
  54. cur_node = cur_node.parent;
  55. }
  56.  
  57. //stop memory leaks by destroying ds list.
  58. ds_list_destroy(pathed);
  59.  
  60. return cur_node.child;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement