当前位置: 首页>>代码示例>>C++>>正文


C++ AStar类代码示例

本文整理汇总了C++中AStar的典型用法代码示例。如果您正苦于以下问题:C++ AStar类的具体用法?C++ AStar怎么用?C++ AStar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AStar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AStar

AStar* AStar::create(int ** map,int width,int height,bool useApproximateDest){
    AStar*  instance = new AStar(map,width,height,useApproximateDest);
    if (instance->init()) {
        return instance;
    }
    return nullptr;
}
开发者ID:owlwisp,项目名称:GameTools,代码行数:7,代码来源:Astar.cpp

示例2: main

int main()
{
    out.open("log.txt");

    GameMap gmap(50,50);
    gmap.load_from_file("map.txt");

    NodePtr src(new Node(Coordinate(0,0)));
    NodePtr dest(new Node(Coordinate(4,3)));

    AStar astar;
    Path res;
    res = astar.get_shorten_path(gmap, src, dest);
    Path::iterator it = res.begin();
    for (; it!=res.end(); ++it)
    {
        cout << (*it)->get_coordinate() << " ";
        gmap.set_cell((*it)->get_coordinate().x,(*it)->get_coordinate().y,'>');
    }
    cout << endl;

    gmap.dump("map_res.txt");

    std::cout << "Hello world!" << std::endl;
    return 0;
}
开发者ID:imousewyfzml,项目名称:mylibrary,代码行数:26,代码来源:myaStar.cpp

示例3: main

int main()
{
	int * main_map;
	AStar star;
	main_map = generateMap(10,10);
	bool result=star.Init(main_map, 10, 10);
	star.AStarSearch(1, 99);
	return 0;
}
开发者ID:johnjsb,项目名称:IGVC2015,代码行数:9,代码来源:test.cpp

示例4: 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;
}
开发者ID:owlwisp,项目名称:GameTools,代码行数:9,代码来源:Astar.cpp

示例5: main

int main()
{	
	sf::RenderWindow window(sf::VideoMode(Constants::screenWidth, Constants::screenHeight), "Puzzle15");
	
	Puzzle15 puzzle;

	srand(time(NULL));
	Configuration config;

	int solvable[16] ={ 2, 5, 3, 4, 1, 10, 6, 8, 9, 14, 7, 11, 13, 16, 15, 12 };
	config.setConfiguration(solvable);

	puzzle.changeConfiguration(config);

	std::vector<Configuration> result;

	AStar solver;
	solver.Run(config, result);

	//puzzle.changeConfiguration(config);

	while (window.isOpen())
	{
		sf::Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();
			else
			{
				if (event.type == sf::Event::KeyPressed)
				{
					if (event.key.code == sf::Keyboard::Space)
					{
						if (!result.empty())
						{
							puzzle.changeConfiguration(result.back());
							result.pop_back();
						}
					}
				}
			}
		}

		window.clear();
		puzzle.draw(&window);
		window.display();
	}
	
	return 0;

	/*AStar algorithm;
	algorithm.Run();
	system("pause");*/
}
开发者ID:n4mm0,项目名称:AIProgramming,代码行数:55,代码来源:main.cpp

示例6: main

int main(void)
{
	//Puzzle::PuzzleState g = { 1, 2, 3, 8, 0, 4, 7, 6, 5 };
	//Puzzle start(3);
	//Puzzle goal(g, 3);

	AStar aStar;
	AStar::PuzzleState start = { { 5, 2, 0, 4, 7, 6, 8, 3, 1 }, 0, 0 };
	//AStar::PuzzleState start = { { 2, 3, 4, 1, 8, 0, 7, 6, 5 }, 0, 0 };
	AStar::PuzzleState goal = { { 1, 2, 3, 8, 0, 4, 7, 6, 5 }, 0, 0 };
	aStar.solve(start, goal);

	return (0);
}
开发者ID:jbalestr42,项目名称:42,代码行数:14,代码来源:main.cpp

示例7: AStar

AStar* AStar::create()
{
	AStar *pRet = new AStar();
	if (pRet && pRet->init())
	{
		pRet->autorelease();
		pRet->retain();
		return pRet;
	}
	else
	{
		delete pRet;
		pRet = NULL;
		return NULL;
	}	
}
开发者ID:cubemoon,项目名称:tower-skycity-one,代码行数:16,代码来源:AStar.cpp

示例8: main

int main(int argc, char** argv)
{
	AStar search;
	std::vector<RHNode*> results;

	gamestate start1;
	initTest1(start1);

	RHNode startNode1(start1);
	search.search(startNode1, results);

	printf("\nSuccess!\n");
	printf("\nSolution found with: \n");
	printf("%i moves", results.size());

}
开发者ID:hawkaa,项目名称:ducking-wookie,代码行数:16,代码来源:main.cpp

示例9: AStar

void GridLayer::testAstar()
{
    int startX;
    int startY;
    int endX;
    int endY;
    
    for (int r = 0; r < m_row; r++) {
        for (int c = 0; c < m_col; c++) {
            if(m_data[r][c] == FLAG_PATH)
            {
                m_data[r][c] = FLAG_EMPTY;
            }
            
            if (m_data[r][c] == FLAG_START)
            {
                startX = c;
                startY = r;
            }
            
            if (m_data[r][c] == FLAG_END)
            {
                endX = c;
                endY = r;
            }
        }
    }
    
    AStar* astar = new AStar(m_data, m_row, m_col);
    std::vector<Step*> moveList = astar->getPath(startX, startY, endX, endY);
    delete astar;
    
    // 删除起点终点
    moveList.pop_back();
    std::vector<Step*>::iterator iter = moveList.begin();
    moveList.erase(iter);
    
    // 赋值
    for (auto step : moveList)
    {
        m_data[step->gy][step->gx] = 1;
    }
    

    
    infoMap();
}
开发者ID:shysean,项目名称:Cocos2dxDemo,代码行数:47,代码来源:AStarTest.cpp

示例10: numRows

AStar::AStar(const AStar& other) : numRows(other.getRowCount()), numCols(other.getColCount())
{
	map = new std::vector<std::vector<AStarNode*>*>(numRows);
	for(int i=0;i<numRows;i++)
	{
		map->at(i) = new std::vector<AStarNode*>(numCols);
		for (int j = 0; j < numCols; j++)
		{
			*(map->at(i)->at(j)) = *(other.map->at(i)->at(j));  //Double check this!!!!
																
		}
	}
	openList = new std::vector<AStarNode>(*other.getOpenList());
	closedList = new std::vector<AStarNode>(*other.getClosedList());
	goalNode = new AStarNode(other.getGoalNode());
	
}
开发者ID:MidnightDrifter,项目名称:CS580Proj2Pathfinding,代码行数:17,代码来源:AStar.cpp

示例11: wp

void Manager::calculateWayPoint(){
	vector<Waypoint> vecWaypoints;

	Graph gr = _map->GetGraphFromGrid();

	AStar a;
	Node* start = gr.GetNodeByPos(_slam->BestPrticle()->GetX(), _slam->BestPrticle()->GetY());
	Node* end = gr.GetNodeByPos(40, 47);
	vector<Node*> vec = a.GetShortestPath(start, end);
	for (int i = vec.size() - 1; i > 0; --i) {
		Waypoint wp(vec.operator [](i)->getXPos(),vec.operator [](i)->getYPos());
		cout << "AStar path: (" << wp.getX() << "," << wp.getY() << ")" << endl;
		vecWaypoints.push_back(wp);
	}
	cout << "Finished AStar path" << endl;

	this->_robot->SetWaypointVector(vecWaypoints);
}
开发者ID:benor1470,项目名称:newRobotics,代码行数:18,代码来源:Manager.cpp

示例12: NavGraphSearchState

/** Search for a path between two nodes.
 * This function executes an A* search to find an (optimal) path
 * from node @p from to node @p to.
 * @param from node to search from
 * @param to goal node
 * @param estimate_func function to estimate the cost from any node to the goal.
 * Note that the estimate function must be admissible for optimal A* search. That
 * means that for no query may the calculated estimate be higher than the actual
 * cost.
 * @param cost_func function to calculate the cost from a node to another adjacent
 * node. Note that the cost function is directly related to the estimate function.
 * For example, the cost can be calculated in terms of distance between nodes, or in
 * time that it takes to travel from one node to the other. The estimate function must
 * match the cost function to be admissible.
 * @param use_constraints true to respect constraints imposed by the constraint
 * repository, false to ignore the repository searching as if there were no
 * constraints whatsoever.
 * @param compute_constraints if true re-compute constraints, otherwise use constraints
 * as-is, for example if they have been computed before to check for changes.
 * @return ordered vector of nodes which denote a path from @p from to @p to.
 * Note that the vector is empty if no path could be found (i.e. there is non
 * or it was prohibited when using constraints.
 */
fawkes::NavGraphPath
NavGraph::search_path(const NavGraphNode &from, const NavGraphNode &to,
		      navgraph::EstimateFunction estimate_func,
		      navgraph::CostFunction cost_func,
		      bool use_constraints, bool compute_constraints)
{
  if (! reachability_calced_)  calc_reachability();

  AStar astar;

  std::vector<AStarState *> a_star_solution;

  if (use_constraints) {
    constraint_repo_.lock();
    if (compute_constraints && constraint_repo_->has_constraints()) {
      constraint_repo_->compute();
    }

    NavGraphSearchState *initial_state =
      new NavGraphSearchState(from, to, this, estimate_func, cost_func,
			      *constraint_repo_);
    a_star_solution =  astar.solve(initial_state);
    constraint_repo_.unlock();
  } else {
    NavGraphSearchState *initial_state =
      new NavGraphSearchState(from, to, this, estimate_func, cost_func);
    a_star_solution =  astar.solve(initial_state);
  }

  std::vector<fawkes::NavGraphNode> path(a_star_solution.size());
  NavGraphSearchState *solstate;
  for (unsigned int i = 0; i < a_star_solution.size(); ++i ) {
    solstate = dynamic_cast<NavGraphSearchState *>(a_star_solution[i]);
    path[i] = solstate->node();
  }

  float cost =
    (! a_star_solution.empty())
      ? a_star_solution[a_star_solution.size() - 1]->total_estimated_cost
      : -1;

  return NavGraphPath(this, path, cost);
}
开发者ID:jmlich,项目名称:fawkes,代码行数:66,代码来源:navgraph.cpp

示例13: QWidget

Widget::Widget(QWidget *parent) :
	QWidget(parent),
	ui(new Ui::Widget)
{
	ui->setupUi(this);

	int size = 3;
	QVector<QVector< GameObject *> > cells;

	cells = QVector<QVector <GameObject*> > (size);
	for (int i = 0; i < cells.size(); i++)
	{
		cells[i] = QVector <GameObject*> (size);
		for (int j = 0; j < cells[i].size(); j++)
		{
			cells[i][j] = nullptr;
		}
	}

	cells[0][0] = new GameObject();
	cells[0][1] = new TreeObject();
	cells[0][2] = new TreeObject();
	cells[1][0] = new GameObject();
	cells[1][1] = new GameObject();
	cells[1][2] = new GameObject();
	cells[2][0] = new GameObject();
	cells[2][1] = new GameObject();
	cells[2][2] = new GameObject();

	AStar *astar = new AStar();
	astar->addCells(cells);

	QList<QPoint *> path = astar->calcualtePath(QPoint(0, 0), QPoint(2, 2));

	QList<QPoint *>::iterator i;

	for (i = path.begin(); i != path.end(); ++i)
		qDebug() << (*i)->x() << (*i)->y() << '\n';
}
开发者ID:EldarGiniyatullin,项目名称:Project_game,代码行数:39,代码来源:widget.cpp

示例14: main

int main()
{
	char maps[1000][1000] =
	{
		{ 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 },
		{ 0, 0, 0, 1, 0, 1, 0, 1, 0, 1 },
		{ 1, 1, 1, 1, 0, 1, 0, 1, 0, 1 },
		{ 0, 0, 0, 1, 0, 0, 0, 1, 0, 1 },
		{ 0, 1, 0, 1, 1, 1, 1, 1, 0, 1 },
		{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
		{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		{ 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 },
		{ 1, 1, 0, 0, 1, 0, 1, 0, 0, 0 },
		{ 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 },
	};

	// 搜索参数
	AStar::Param param;
	param.width = 1000;
	param.height = 1000;
	param.allow_corner = false;
	param.start = AStar::Vec2(0, 0);
	param.end = AStar::Vec2(999, 999);
	param.is_canreach = [&](const AStar::Vec2 &pos)->bool
	{
		return maps[pos.y][pos.x] == 0;
	};

	// 执行搜索
	AStar as;
	Duration duration;
	auto path = as.search(param);

	std::cout << (path.empty() ? "路径未找到!" : "路径已找到!") << std::endl;
	std::cout << "本次寻路耗时" << duration.nano_seconds() << "纳秒" << std::endl;
	std::cout << '\n';
	system("pause");
	return 0;
}
开发者ID:jay602,项目名称:a-star,代码行数:39,代码来源:main.cpp

示例15: main

int main(int argc, char *argv[])
{
	char maps[10][10] =
	{
		{ 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 },
		{ 0, 0, 0, 1, 0, 1, 0, 1, 0, 1 },
		{ 1, 1, 1, 1, 0, 1, 0, 1, 0, 1 },
		{ 0, 0, 0, 1, 0, 0, 0, 1, 0, 1 },
		{ 0, 1, 0, 1, 1, 1, 1, 1, 0, 1 },
		{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
		{ 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
		{ 0, 0, 0, 0, 1, 0, 0, 0, 1, 0 },
		{ 1, 1, 0, 0, 1, 0, 1, 0, 0, 0 },
		{ 0, 0, 0, 0, 0, 0, 1, 0, 1, 0 },
	};

	// 搜索参数
	AStar::Param param;
	param.width = 10;
	param.height = 10;
	param.corner = false;
	param.start = AStar::Vec2(0, 0);
	param.end = AStar::Vec2(9, 9);
	param.can_reach = [&](const AStar::Vec2 &pos)->bool
	{
		return maps[pos.y][pos.x] == 0;
	};

	// 执行搜索
	AStar as;
	Duration duration;
	auto path = as.find(param);
	std::cout << (path.empty() ? "路径未找到!" : "路径已找到!") << std::endl;
	std::cout << "本次寻路耗时" << duration.nano_seconds() << "纳秒" << std::endl;
	std::cout << '\n';

	return 0;
}
开发者ID:cd756819220,项目名称:a-star-algorithm,代码行数:38,代码来源:Test.cpp


注:本文中的AStar类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。