Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. // M18 T2 function to know the shortest path to any room
  2. function pathfinder(rmlist) {
  3. var nextlist = accumulate(function(a,b) {
  4. return append(a.getNeighbours(), b);
  5. }, [], rmlist);
  6. var prevlist = head(tail(this.shortestpath));
  7. var nextlist2 = accumulate(function(a,b) {
  8. if (is_empty_list(member(a, prevlist))) {
  9. return pair(a, remove(a, b));
  10. } else {
  11. return b;
  12. }
  13. }, [], nextlist);
  14. var protect = filter(function(x) {
  15. return is_instance_of(x, ProtectedRoom);
  16. }, nextlist2);
  17. if (is_empty_list(protect)) {
  18. this.shortestpath = pair(nextlist2, this.shortestpath);
  19. return pathfinder.call(this, nextlist2);
  20. } else {
  21. this.totravel = list(head(protect));
  22. }
  23. }
  24.  
  25. // create a list for the actual path the player is going to take to get to protected room and stores it as this.totravel
  26. function createpath() {
  27. if (is_empty_list(this.shortestpath)) {
  28.  
  29. } else {
  30. var next = head(this.shortestpath);
  31. var possible = (head(this.totravel)).getNeighbours();
  32. var move = accumulate(function(a,b) {
  33. if (is_empty_list(b)) {
  34. if (is_empty_list(member(a, next))) {
  35. return b;
  36. } else {
  37. return a;
  38. }
  39. } else {
  40. return b;
  41. }
  42. }, [], possible);
  43. this.totravel = pair(move, this.totravel);
  44. this.shortestpath = tail(this.shortestpath);
  45. return createpath.call(this);
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement