Algorithm 用Pbasic中的boe机器人计算迷宫的最短距离

Algorithm 用Pbasic中的boe机器人计算迷宫的最短距离,algorithm,robotics,path-finding,basic,Algorithm,Robotics,Path Finding,Basic,我正在和一个叫boe机器人的机器人合作一个项目 我的目标是两次穿越迷宫。在第一次运行时,我的boe机器人穿过迷宫,将路径存储在内存中。在第二次运行时,它将所有路径存储在内存中,并删除导致死胡同的坏路径——因此boe机器人可以选择到迷宫末端的最短路径 为了做到这一点,我需要创建替换规则来解析出导致死胡同的坏路由 我在pbasic中创建了一个代码,但是我的代码出错了。有没有人能帮我解决这个问题 ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[ Variables

我正在和一个叫boe机器人的机器人合作一个项目

我的目标是两次穿越迷宫。在第一次运行时,我的boe机器人穿过迷宫,将路径存储在内存中。在第二次运行时,它将所有路径存储在内存中,并删除导致死胡同的坏路径——因此boe机器人可以选择到迷宫末端的最短路径

为了做到这一点,我需要创建替换规则来解析出导致死胡同的坏路由

我在pbasic中创建了一个代码,但是我的代码出错了。有没有人能帮我解决这个问题

' {$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 or left turn in 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(3)(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 Left U-Turn Left 
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 Left U-Turn Right
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 Left U-turn Straight
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 Right U-turn Left 
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 Right U-turn Right
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 Right U-turn Straight
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 Straight U-turn Left 
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 Straight U-turn Right
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 Straight U-turn Straight 
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.
“{$STAMP BS2}
“{$PBASIC 2.5}
'----[变量]----------------------------------------------------------
转变字
转换变量字
指针变量字节
ptr VAR pointer'为指针创建别名
'---[主程序]-------------------------------------------------------
开始主要的例行公事
ptr=0'指向阵列中的下一个可用位置。
turns(ptr)=turn'这会将L置于阵列的第一个位置或阵列的左转弯处
ptr=ptr+1'将一个字母添加到指针,使下一个字母进入数组中的下一个位置。
如果(圈数<3),则“数组需要至少三个字符才能使此算法工作
返回
如果(转弯(3)(ptr)-1“U”),则“如果下一个最后一个转弯不是U形转弯,则退出”
返回
如果(turns(3)=“LUL”)'查看数组中的右三个字符左U向左转
ptr=ptr-3'将数组缩短3个字符。我们将“砍掉”LUL并用S替换
轮次(ptr)=“S”'我们本应该(并且将在下次)进行的轮次。
ptr=ptr+1'设置指向数组中下一个字符的指针。
如果(turns(3)=“LUR”)'查看数组中的右三个字符左U向右转
ptr=ptr-3'将数组缩短3个字符。我们将“切掉”LUL并替换为S
圈数(ptr)=“U”'我们本应该(并且将在下次)进行的圈数。
ptr=ptr+1'设置指向数组中下一个字符的指针。
如果(圈数(3)=“LUS”)'查看数组中的右三个字符左U形转弯直行
ptr=ptr-3'将数组缩短3个字符。我们将“切掉”LUL并替换为S
回合数(ptr)=“R”'我们本应该(并且将在下次)进行的回合数。
ptr=ptr+1'设置指向数组中下一个字符的指针。
'增量/减量例行程序一次仅改变2个脉冲持续时间。
如果(turns(3)=“RUL”)'查看数组中的右三个字符右U向左转
ptr=ptr-3'将数组缩短3个字符。我们将“切掉”LUL并替换为S
圈数(ptr)=“U”'我们本应该(并且将在下次)进行的圈数。
ptr=ptr+1'设置指向数组中下一个字符的指针。
如果(turns(3)=“RUR”)'查看数组中的右三个字符右U向右转
ptr=ptr-3'将数组缩短3个字符。我们将“切掉”LUL并替换为S
轮次(ptr)=“L”'我们本应该(并且将在下次)进行的轮次。
ptr=ptr+1'设置指向数组中下一个字符的指针。
如果(turns(3)=“RUS”)'查看数组中的右三个字符右U形转弯直行
ptr=ptr-3'将数组缩短3个字符。我们将“切掉”LUL并替换为S
轮次(ptr)=“L”'我们本应该(并且将在下次)进行的轮次。
ptr=ptr+1'设置指向数组中下一个字符的指针。
如果(圈数(3)=“SUL”)'看数组中的右三个字符,直U形左转
ptr=ptr-3'将数组缩短3个字符。我们将“切掉”LUL并替换为S
回合数(ptr)=“R”'我们本应该(并且将在下次)进行的回合数。
ptr=ptr+1'设置指向数组中下一个字符的指针。
如果(turns(3)=“SUR”)'查看数组中的右三个字符,向右直U形转弯
pointer=pointer-3'将数组缩短3个字符。我们将“切掉”LUL并替换为S
圈数(指针)=“L”'我们应该(并且将在下次)进行的圈数。
pointer=pointer+1'将指针设置为指向数组中的下一个字符。
如果(turns(3)=“SUS”)'直接查看数组中的三个字符
pointer=pointer-3'将数组缩短3个字符。我们将“切掉”LUL并替换为S
转弯(指针)=“U”'我们本应该(并且将在下次)转弯。
pointer=pointer+1'将指针设置为指向数组中的下一个字符。

此迷宫解决方法是a*规划算法的一个简单版本。您可能希望查看我的页面,其中介绍了此迷宫解决方法:


那里有一些伪代码可以帮助您修复代码。

您的语法或算法有问题吗?如果您想得到更好的答案,您可能需要添加更多标记(pbasic等)、输出错误和(可能的)错误伪代码。您确实需要发布错误。请签出并加入新的robotics stackexchange论坛:area51.stackexchange.com/Propositions/40020/robotics