本文整理汇总了C++中AStar::findPath方法的典型用法代码示例。如果您正苦于以下问题:C++ AStar::findPath方法的具体用法?C++ AStar::findPath怎么用?C++ AStar::findPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AStar
的用法示例。
在下文中一共展示了AStar::findPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
int **map = new int*[10 * 10];
memset(map, 0, 10 * 10);
AStar* astar = AStar::create(map,10,10);
vector<ASNode> path = astar->findPath(0,1,9,9);
astar->printPath(path);
return 1;
}
示例2: move
void Boss::move(int dir) {
if (died) {
return;
}
bool cancelCurrentPath = false;
if (pathAStar != NULL) {
// boss follow the path left.
if (pathAStar->size() > 1) {
Tile *currentTile = pathAStar->popBack();
int nextRow = currentTile->row;
int nextCol = currentTile->col;
// if the next position is empty
if (sim->board->validate(nextRow, nextCol) &&
sim->board->getProp(nextRow, nextCol) == NULL &&
sim->board->getUnit(nextRow, nextCol) == NULL) {
sim->board->setUnit(row, col, NULL);
sim->board->setUnit(nextRow, nextCol, this);
}
else {
pathAStar->pushBack(currentTile);
cancelCurrentPath = true;
}
if (!cancelCurrentPath) {
return;
}
}
delete pathAStar;
pathAStar = NULL;
}
AStar *aStar = new AStar();
DLLContainer<Tile *> *path = aStar->findPath(row, col, sim->board->getHero()->getRow(), sim->board->getHero()->getCol());
delete aStar;
if (path != NULL && path->size() > 2) {
pathAStar = path;
path->popBack(); // boss skip boss' position.
// while (!path->isEmpty()) {
// Tile *currentTile = path->popBack();
// cout << "(" << currentTile->row << ", " << currentTile->col << ")->";
// }
// cout << endl;
// sim->board->print();
// exit(1);
return;
}
if (path != NULL) {
delete path;
}
// if hero is adjavcent then hit him.
for (int i = row-1; i <= row+1; i++) {
for (int j = col-1; j <= col+1; j++) {
if (sim->board->validate(i, j) &&
sim->board->getUnit(i, j) != NULL &&
sim->board->getUnit(i, j)->isHero()) {
sim->board->getUnit(i, j)->decHp(atk); // found! attak!!!
return;
}
}
}
Monster::move(dir);
}
示例3: main
int main(int argc, const char * argv[])
{
AStar astar;
int rows = 20, columns = 20;
Tiles env(rows, columns);
random_device generator;
uniform_int_distribution<int> distribution(1,20);
vector<int> impassableNodes;
for (int i = 0; i < columns * rows; i++)
{
int dice_roll = distribution(generator);
if (dice_roll == 3)
{
impassableNodes.push_back(i);
}
}
cout << "blocks(" << impassableNodes.size() << "): ";
for (auto i : impassableNodes)
{
env.SetUntraverseable(i);
cout << i << ", ";
}
cout << endl;
std::uniform_int_distribution<int> startEndDistribution(0,rows * columns-1);
int start, end;
while (true) {
start = startEndDistribution(generator);
if (std::find(impassableNodes.begin(), impassableNodes.end(), start) == impassableNodes.end())
{
break;
}
}
while (true) {
end = startEndDistribution(generator);
if (std::find(impassableNodes.begin(), impassableNodes.end(), end) == impassableNodes.end())
{
break;
}
}
cout << "start = " << start << ", end = " << end << ";" << endl;
env.DrawMap(start, end);
std::cout<<"-----------\n\n\n\n";
astar.findPath(env, start, end);
// astar.findPath(env, 11, 18);
auto p = env.GetSmoothedPath(astar.getResultPath());
for (auto n : p)
{
cout << n << ", ";
}
cout << endl;
env.DrawSolution(p);
return 0;
}