• API
• FAQ
• Tools
• Trends
• Archive
daily pastebin goal
17%
SHARE
TWEET

# Untitled

a guest Jun 19th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include "pledge.h"
2. #include "config.h"
3. #include "math.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. }
RAW Paste Data
Top