Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #include "pledge.h"
  2. #include "config.h"
  3. #include "math.h"
  4. #include "taskmanager.h"
  5.  
  6. Pledge checkPledge(int direction, bool space_left, bool space_top, bool space_right)
  7. {
  8. state_t state;
  9. // Preferred direction
  10. if (direction == 0) {
  11. if (space_top) {
  12. state = straight_pref; // Keep going forward
  13. std::cout << "Dir: " << direction << ", Go forward in preferred direction" << std::endl;
  14. }
  15. else if (!space_top) {
  16. state = turn_left; // Turn left when obstacle in front
  17. direction--;
  18. std::cout << "Dir: " << direction << ", Obstacle ahead, turn left" << std::endl;
  19. }
  20. else if (!space_left && !space_top && !space_right) {
  21. state = turn_180; // Dead end detected
  22. direction--;
  23. direction--;
  24. std::cout << "Dir: " << direction << ", Dead end detected, rotate 180 deg" << std::endl;
  25. }
  26. }
  27. // Other than preferred direction
  28. else {
  29. if (space_right) {
  30. state = turn_right; // Always turn right when there is space
  31. direction++;
  32. std::cout << "Dir: " << direction << ", Turn right, unpreferred direction" << std::endl;
  33. }
  34. else if (!space_right && space_top) {
  35. state = straight;
  36. std::cout << "Dir: " << direction << ", Go straight, unpreferred direction" << std::endl;
  37. }
  38. else if (!space_right && !space_top && space_left) {
  39. state = turn_left;
  40. direction--;
  41. std::cout << "Dir: " << direction << ", Go left, unpreferred direction" << std::endl;
  42. }
  43. else if (!space_right && !space_top && !space_left) {
  44. state = turn_180;
  45. direction--;
  46. direction--;
  47. std::cout << "Dir: " << direction << ", Dead end detected, rotate 180 deg, unpreferred direction" << std::endl;
  48. }
  49. }
  50.  
  51. return Pledge(direction, state);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement