私は現在、A*検索アルゴリズムに取り組んでいます。アルゴリズムは、テキストファイルの迷路を解決するだけです。私は、A*アルゴリズムがフィニッシュを見つけるのに非常に速いことになっていることを知っています。壁のない20x20の迷路で道を見つけるのに6秒かかるようです。それはそれがそうするのに永遠にかかる正しい道で終わりを見つけます。
コードのどの部分が問題であるかを知っていれば、それを投稿するだけですが、何が問題になっているのか本当にわかりません。これが私が使用するアルゴリズムです...
while(!openList.empty()) {
visitedList.push_back(openList[index]);
openList.erase(openList.begin() + index);
if(currentCell->x_coor == goalCell->x_coor && currentCell->y_coor == goalCell->y_coor)
}
FindBestPath(currentCell);
break;
}
if(map[currentCell->x_coor+1][currentCell->y_coor] != wall)
{
openList.push_back(new SearchCell(currentCell->x_coor+1,currentCell->y_coor,currentCell));
}
if(map[currentCell->x_coor-1][currentCell->y_coor] != wall)
{
openList.push_back(new SearchCell(currentCell->x_coor-1,currentCell->y_coor,currentCell));
}
if(map[currentCell->x_coor][currentCell->y_coor+1] != wall)
{
openList.push_back(new SearchCell(currentCell->x_coor,currentCell->y_coor+1,currentCell));
}
if(map[currentCell->x_coor][currentCell->y_coor-1] != wall)
{
openList.push_back(new SearchCell(currentCell->x_coor,currentCell->y_coor-1,currentCell));
}
for(int i=0;i<openList.size();i++) {
openList[i]->G = openList[i]->parent->G + 1;
openList[i]->H = openList[i]->ManHattenDistance(goalCell);
}
float bestF = 999999;
index = -1;
for(int i=0;i<openList.size();i++) {
if(openList[i]->GetF() < bestF) {
for(int n=0;n<visitedList.size();n++) {
if(CheckVisited(openList[i])) {
bestF = openList[i]->GetF();
index = i;
}
}
}
}
if(index >= 0) {
currentCell = openList[index];
}
}
私はこのコードが厄介で、物事を行うための最も効率的な方法ではないことを知っていますが、それでもそれが何であるかよりも速いはずだと思います。どんな助けでも大歓迎です。
ありがとう。