Advertisement
xXx_Fortis_xXx

Untitled

Sep 20th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.78 KB | None | 0 0
  1. function walkThroughWall (R)
  2.     if ~R.is_bord('n')
  3.         R.step('n')
  4.     else
  5.         length = 1;
  6.         Door = 0;
  7.         direction = 'w';
  8.         while ~Door
  9.             Door = move(R, direction, length);
  10.             direction = changeDirection(direction);
  11.             length++;
  12.         end
  13.     end
  14. end
  15.  
  16. function Door = stepAndFind (R, direction)
  17.     R.step(direction)
  18.     Door = ~R.is_bord('n');
  19. end
  20.  
  21. function Door = move (R, direction, steps)
  22.     flag = 0;
  23.     for i = [1:steps]
  24.         if stepAndFind(R, direction) && ~flag
  25.             R.step('n');
  26.             flag = 1;
  27.         end
  28.     end
  29.     Door = flag;
  30. end
  31.  
  32. function Direction = changeDirection (direction)
  33.     if direction == 'o'
  34.         Direction = 'w';
  35.     else
  36.         Direction = 'o';
  37.     end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement