Guest User

Untitled

a guest
Apr 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. void path_correct(int array[]){
  2. int forward_count =0;
  3. int temp_placemarker = counter;
  4. //You want to find the 2 right turns and then count how many forwards there are after it befor
  5. e a left.
  6. //then take that many forwards off either side of the 2 right turns and shift everything down
  7. appropriately. //so [0,0,0,0,2,2,0,0,1] needs to be replaced with [0,0,1]
  8. if(path[temp_placemarker] == 1){ temp_placemarker--;
  9. //only bother looking for the rights if we don't have a left yet.
  10. while(path[temp_placemarker] != 2 && temp_placemarker > 0){
  11. //count how many forwards are between the 1 and the last 2
  12. forward_count++;
  13. //step backwards in the array each time until we find the last 2.
  14. temp_placemarker--;
  15. }
  16. if(path[temp_placemarker] == 2){
  17. temp_placemarker = temp_placemarker - 1; //back up past the 2's.
  18. counter = temp_placemarker - forward_count; //Back up everything to the new spot we found.
  19. array[counter] = 1; //put in the new left turn now that we're not wasting our time with the dead end.
  20. counter++;
  21. //path corrected, continue on the with robot function.
  22. }
  23. }
  24. }
Add Comment
Please, Sign In to add comment