フラッド フィル アルゴリズムのバージョンを実装して、マイクロ マウスの迷路の最短距離パスを解決しようとしています。埋められていない隣接する各場所に、その場所から開始場所までの距離を表す番号が割り当てられることを除いて、通常の塗りつぶしと同じように機能します。アルゴリズムが別のセルに移動するたびに、数値が 1 ずつ増加します。左下隅から始まる壁のない迷路の例を次に示します。
2 3 4
1 2 3
0 1 2
ここに私が持っている現在のコードがあります...
void nav_flood_rec(struct nav_array *array, int row, int column, int flood_num)
{
//Check the base case (not shown here)
if (base_case)
return;
//Assign the flood number
arrray->cells[row][column]->flood_number = flood_num;
//North
nav_flood_rec(array, row + 1, column, flood_num + 1);
//East
nav_flood_rec(array, row, column + 1, flood_num + 1);
//South
nav_flood_rec(array, row - 1, column, flood_num + 1);
//West
nav_flood_rec(array, row, column - 1, flood_num + 1);
}
私が抱えている問題は、再帰が一度に1ステップずつ進んでいないことです(漠然としていますが、説明させてください)。すべての方向を確認してからアルゴリズムに進む代わりに、北に移動し続け、他の方向は確認しません。他の方向がチェックされるまで、他の再帰呼び出しをどうにかして譲りたいようです。誰か提案はありますか?