使用路径查找访问网格中的所有节点?

问题描述 投票:0回答:1

在我们的学期项目中,我们试图制造一辆小型汽车,可以搜索地面上的金属。每次遇到地面上的物体时,都必须标记它的坐标,并找到它周围的路径来访问所有剩余的节点。

我们已经实现了一种方法,我们可以在网格中记下该区域,因此我们将它全部放在x-y坐标中。我们已经考虑使用路径查找算法的修改版本(广度优先,A *或其他)来找到我们通过系统的方式,但是我们在实现它时遇到了麻烦。

是否有可能修改这些算法中的任何一个而不是从节点A到B,它搜索每个坐标,如果遇到地面上的物体,则“重新路径”?

c++ breadth-first-search path-finding
1个回答
0
投票

Logic

首先,我们检查所有方块是否包含金属。然后我们用金属在布尔网格中存储正方形。

Pseudo-Code

bool grid[10000][10000];
for (int i = 0; i < width; i++){
    for(int j = 0; j < height; j++){
       if (square is metal){
           grid[i][j] = true; //means its visited.
       }
    }
}
//Conduct bfs here
typedef pair<int , int> pi; //introduce priority queues
typedef pair<pi, int> ppi;
int dx[8] = {-1,-2, 1 ,2 ,-1, -2, 1, 2};//introduce movement coordinates
int dy[8] = {-2,-1, -2,-1, 2, 1, 2, 1};
//Check if the coordinates of the grid is true(visited) or false(unvisited)

希望这可以帮助。

© www.soinside.com 2019 - 2024. All rights reserved.