Replacement rules for the boe-bot maze navigation
Hi I have a code that i'm working were my boe-bot will navigate through a maze twice, on the first run it navigates through the entire maze storing the paths in memory as it goes. On the second run it has the shortest path to the maze computed and takes the shortest route to the end of the maze. I'm using a replacement rule algorithm in order to complete the maze. I haven't completed it yet but I have concerns about my first two if statements. In my IF statements I am using them as check conditions meaning I want to say every time the boe-bot makes a turn, go to the If statements to see if the next-to-last character in the array is a "U" which stands for U-Turn and If the next-to-last character is a "U", then the last turn was unnecessary. Is there anyone know if I did my if statements correctly for what i want to accomplish, and if not can anyone give me an example of how I can fix them thanks!
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Variables ]
turn VAR Word
turns VAR Word
pointer VAR Byte
ptr VAR pointer 'create an alias for pointer
'
[ Main Routine ]
DO ' Begin main routine
ptr = 0 'Points TO the NEXT available position in the array.
turns(ptr) = turn 'This puts an L in the first position of the array
ptr = ptr + 1 'Add one TO the pointer so the NEXT letter goes in the NEXT position in the array.
IF (turns < 3)THEN 'Array needs at least three characters for this algorithm to work
RETURN
IF (turns(ptr) - 1 <> "U")THEN 'EXIT IF the NEXT-TO-last turn is NOT a U-Turn
RETURN
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Variables ]
turn VAR Word
turns VAR Word
pointer VAR Byte
ptr VAR pointer 'create an alias for pointer
'
[ Main Routine ]
DO ' Begin main routine
ptr = 0 'Points TO the NEXT available position in the array.
turns(ptr) = turn 'This puts an L in the first position of the array
ptr = ptr + 1 'Add one TO the pointer so the NEXT letter goes in the NEXT position in the array.
IF (turns < 3)THEN 'Array needs at least three characters for this algorithm to work
RETURN
IF (turns(ptr) - 1 <> "U")THEN 'EXIT IF the NEXT-TO-last turn is NOT a U-Turn
RETURN
Comments
' {$STAMP BS2}
' {$PBASIC 2.5}
'
[ Variables ]
turn VAR Word
turns VAR Word
pointer VAR Byte
ptr VAR pointer 'create an alias for pointer
'
[ Main Routine ]
DO ' Begin main routine
ptr = 0 'Points TO the NEXT available position in the array.
turns(ptr) = turn 'This puts an L in the first position of the array
ptr = ptr + 1 'Add one TO the pointer so the NEXT letter goes in the NEXT position in the array.
IF (turns < 3)THEN 'Array needs at least three characters for this algorithm to work
RETURN
IF (turns(ptr) - 1 <> "U")THEN 'EXIT IF the NEXT-TO-last turn is NOT a U-Turn
RETURN
IF (turns(3) = "LUL") 'Look at the right three characters in the array
ptr = ptr - 3 'shorten the array by 3 characters. We'll "chop off" the LUL and replace with S
turns(ptr) = "S" 'The turn we should have taken (AND will take NEXT time.
ptr = ptr + 1 'set up the pointer TO point TO the NEXT character in the array.
IF (turns(3) == "LUR") 'Look at the right three characters in the array
ptr = ptr - 3 'shorten the array by 3 characters. We'll "chop off" the LUL and replace with S
turns(ptr) = "U" 'The turn we should have taken (AND will take NEXT time.
ptr = ptr + 1 'set up the pointer TO point TO the NEXT character in the array.
IF (turns(3) == "LUS") 'Look at the right three characters in the array
ptr = ptr - 3 'shorten the array by 3 characters. We'll "chop off" the LUL and replace with S
turns(ptr) = "R" 'The turn we should have taken (AND will take NEXT time.
ptr = ptr + 1 'set up the pointer TO point TO the NEXT character in the array.
' Increment/decrement routine only changes pulse durations by 2 at a time.
IF (turns(3) == "RUL") 'Look at the right three characters in the array
ptr = ptr - 3 'shorten the array by 3 characters. We'll "chop off" the LUL and replace with S
turns(ptr) = "U" 'The turn we should have taken (AND will take NEXT time.
ptr = ptr + 1 'set up the pointer TO point TO the NEXT character in the array.
IF (turns(3) == "RUR") 'Look at the right three characters in the array
ptr = ptr - 3 'shorten the array by 3 characters. We'll "chop off" the LUL and replace with S
turns(ptr) = "L" 'The turn we should have taken (AND will take NEXT time.
ptr = ptr + 1 'set up the pointer TO point TO the NEXT character in the array.
IF (turns(3) == "RUS") 'Look at the right three characters in the array
ptr = ptr - 3 'shorten the array by 3 characters. We'll "chop off" the LUL and replace with S
turns(ptr) = "L" 'The turn we should have taken (AND will take NEXT time.
ptr = ptr + 1 'set up the pointer to point to the NEXT character in the array.
IF (turns(3) == "SUL") 'Look at the right three characters in the array
ptr = ptr - 3 'shorten the array by 3 characters. We'll "chop off" the LUL and replace with S
turns(ptr) = "R" 'The turn we should have taken (AND will take NEXT time.
ptr = ptr + 1 'set up the pointer TO point TO the NEXT character in the array.
IF (turns(3) == "SUR") 'Look at the right three characters in the array
pointer = pointer - 3 'shorten the array by 3 characters. We'll "chop off" the LUL and replace with S
turns(pointer) = "L" 'The turn we should have taken (AND will take NEXT time.
pointer = pointer + 1 'set up the pointer TO point TO the NEXT character in the array.
IF (turns(3) == "SUS") 'Look at the right three characters in the array
pointer = pointer - 3 'shorten the array by 3 characters. We'll "chop off" the LUL and replace with S
turns(pointer) = "U" 'The turn we should have taken (AND will take NEXT time.
pointer = pointer + 1 'set up the pointer TO point TO the NEXT character in the array.