Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // M18 T2 function to know the shortest path to any room
- function pathfinder(rmlist) {
- var nextlist = accumulate(function(a,b) {
- return append(a.getNeighbours(), b);
- }, [], rmlist);
- var prevlist = head(tail(this.shortestpath));
- var nextlist2 = accumulate(function(a,b) {
- if (is_empty_list(member(a, prevlist))) {
- return pair(a, remove(a, b));
- } else {
- return b;
- }
- }, [], nextlist);
- var protect = filter(function(x) {
- return is_instance_of(x, ProtectedRoom);
- }, nextlist2);
- if (is_empty_list(protect)) {
- this.shortestpath = pair(nextlist2, this.shortestpath);
- return pathfinder.call(this, nextlist2);
- } else {
- this.totravel = list(head(protect));
- }
- }
- // create a list for the actual path the player is going to take to get to protected room and stores it as this.totravel
- function createpath() {
- if (is_empty_list(this.shortestpath)) {
- } else {
- var next = head(this.shortestpath);
- var possible = (head(this.totravel)).getNeighbours();
- var move = accumulate(function(a,b) {
- if (is_empty_list(b)) {
- if (is_empty_list(member(a, next))) {
- return b;
- } else {
- return a;
- }
- } else {
- return b;
- }
- }, [], possible);
- this.totravel = pair(move, this.totravel);
- this.shortestpath = tail(this.shortestpath);
- return createpath.call(this);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement