我正在尝试使用下面的 sudo 代码使用左手退出规则来解决迷宫我已经让它大部分工作但是我遇到了让它在遇到死胡同并回来时选择新方向的问题(就像在在第一阶段顶部为真但左、下和右壁为假的正方形的情况下,我的代码正确地从说是否输入左到底部或右侧的 2 中的任何一个,但是当它返回时它选择左侧方向而不是底部,我如何让它选择底部)。
有人可以建议我如何选择新方向 - 我已经在有问题的方法周围加上双星号 (**) 以供您参考提前感谢
Set int entr to LEFT;
Set int exit to-1;
Set boolean backtrack to false;
Set currentSquare to startingSquare;
Set previousSquare to null;
Set currentSquare.onpath to true;
While (currentSquare != endingSquare) {
**Set exit to currentSquare.getLeftHandExit(entr);**
Set previousSquare to currentSquare;
Set currentSquare to currentSquare.adjacentSquare(exit);
If (backtracking is false and exit is same as entrance)
Set backtracking to true;
Remove previousSquare from path;
}
Else if backtracking is true and currentSquare is not on the path
Set backtracking to false;
Add previousSquare to path;
}
If backtracking is true, remove currentSquare from path;
else add currentSquare to path;
entr = currentSquare.oppositeSide(exit);
} // end of While