Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void path_correct(int array[]){
- int forward_count =0;
- int temp_placemarker = counter;
- //You want to find the 2 right turns and then count how many forwards there are after it befor
- e a left.
- //then take that many forwards off either side of the 2 right turns and shift everything down
- appropriately. //so [0,0,0,0,2,2,0,0,1] needs to be replaced with [0,0,1]
- if(path[temp_placemarker] == 1){ temp_placemarker--;
- //only bother looking for the rights if we don't have a left yet.
- while(path[temp_placemarker] != 2 && temp_placemarker > 0){
- //count how many forwards are between the 1 and the last 2
- forward_count++;
- //step backwards in the array each time until we find the last 2.
- temp_placemarker--;
- }
- if(path[temp_placemarker] == 2){
- temp_placemarker = temp_placemarker - 1; //back up past the 2's.
- counter = temp_placemarker - forward_count; //Back up everything to the new spot we found.
- array[counter] = 1; //put in the new left turn now that we're not wasting our time with the dead end.
- counter++;
- //path corrected, continue on the with robot function.
- }
- }
- }
Add Comment
Please, Sign In to add comment