以下の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