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


C++ PathFinding类代码示例

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


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

示例1: PathFinding

void NPC::moveTo(float x, float y) {
	PathFinding pathFinder = PathFinding(_map, _id, _x, _y, x, y, 0.5);
	_path = pathFinder.find();
	if(_path.empty()) {
		_dstX = _x;
		_dstY = _y;
	}
	passNode();
}
开发者ID:benelot,项目名称:SillyTanks,代码行数:9,代码来源:npc.cpp

示例2: test3

int test3() {
    vector<string> board = {"....", ".A..", "..B.", "...."};
    PathFinding* pObj = new PathFinding();
    clock_t start = clock();
    int result = pObj->minTurns(board);
    clock_t end = clock();
    delete pObj;
    int expected = 2;
    if(result == expected) {
        cout << "Test Case 3: Passed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 0;
    } else {
        cout << "Test Case 3: Failed! Time: " << static_cast<double>(end-start)/CLOCKS_PER_SEC << " seconds" << endl;
        return 1;
    }
}
开发者ID:rick-qiu,项目名称:topcoder,代码行数:16,代码来源:srm156_pathfinding.cpp

示例3: PathFind

void SmartAIController::PathFind(Engine::Actor & actor, D3DXVECTOR3 newGoal)
{
	Engine::Vector3 nGoal= Engine::Vector3(newGoal.x, newGoal.y, newGoal.z);
	Engine::Vector3 cGoal= Engine::Vector3(currentGoal.x, currentGoal.y, currentGoal.z);
	
	if(positionToFollow.size()<=0 || (DistanceXYZ(nGoal, cGoal)>20.0f))
	{
		if( (DistanceXYZ(nGoal, cGoal)>20.0f))
			currentGoal=newGoal;

		//AI
		PathFinding playerPath;
		playerPath.SetLinks(Engine::WaypointsData::Manager().links);
		playerPath.SetPoints(Engine::WaypointsData::Manager().points);
		D3DXVECTOR3 currentPos= D3DXVECTOR3( actor.getActorPosition()->getx(), actor.getActorPosition()->gety(), actor.getActorPosition()->getz() );

		positionToFollow=playerPath.findShortestPathByAstar(currentGoal,currentPos);
	}

	Engine::Vector3 closestPositionToFollow= Vector3(positionToFollow[0].x,  positionToFollow[0].y,  positionToFollow[0].z);
	
	float distance=DistanceXZ(closestPositionToFollow, *actor.getActorPosition());

	if(distance<30.0f)
	{
		positionToFollow.erase(positionToFollow.begin() + 0);
	}
	else
	{
		Vector3 follow;
		follow.setx(positionToFollow[0].x - actor.getActorPosition()->getx());
		follow.sety(positionToFollow[0].y - actor.getActorPosition()->gety());
		follow.setz(positionToFollow[0].z - actor.getActorPosition()->getz());
	
		follow=follow.Normalize();

		D3DXVECTOR3 newFollow;
		newFollow= D3DXVECTOR3(follow.getx()* 20 *speed, 0, follow.getz()* 20 *speed);

		actor.TransLatePosition(newFollow);
	}
}
开发者ID:aaraddhyanb,项目名称:GreenLagoon,代码行数:42,代码来源:SmartAIController.cpp

示例4: main

int main()
{
  Graph<> graph(GraphTypes::DIRECTED, GraphTypes::WEIGHTED, GraphTypes::NOCONTENT);
  Graph<> paths_greedy(graph.edgeType(), graph.edgeState(), GraphTypes::NOCONTENT);
  Graph<> paths_dynamic(graph.edgeType(), graph.edgeState(), GraphTypes::NOCONTENT);
  PathFinding<> lookup;

  typedef Exporter<> Export;

  /*
    exemple du cours, exemple n°1, page 83 (attention, celui la page 82 est différent)
  */
  graph.add_edge(1,2, 10);
  graph.add_edge(1,3, 3);
  graph.add_edge(1,5, 6);
  graph.add_edge(1,6, 2);

  graph.add_edge(3,2, 4);
  graph.add_edge(3,4, 1);
  graph.add_edge(3,5, 2);

  graph.add_edge(5,4, 3);

  graph.add_edge(6,2, 1);
  graph.add_edge(6,5, 1);

  try
    {
      lookup.bellman(graph, 1, GraphTypes::Algorithms::GREEDY);
      paths_greedy = lookup.resultGraph();

      lookup.bellman(graph, 1, GraphTypes::Algorithms::DYNAMIC);
      paths_dynamic = lookup.resultGraph();

      //Exports
      Export::ToGraphviz(graph, "bin/test_bellman.graph");
      Export::ToGraphviz(paths_greedy, "bin/greedy_bellman.graph");
      Export::ToGraphviz(paths_dynamic, "bin/dynamic_bellman.graph");

#ifdef _SYSTEM

      //compilation dot
      system("dot -Tpng bin/test_bellman.graph -o bin/test_bellman.png");
      system("dot -Tpng bin/greedy_bellman.graph -o bin/greedy_bellman.png");
      system("dot -Tpng bin/dynamic_bellman.graph -o bin/dynamic_bellman.png");

#endif

      //affichages
      std::cout << "Graph a été exporté dans le fichier test_bellman.graph" << std::endl;
      std::cout << "Bellman Glouton: Arbre des chemins a été exporté dans le fichier greedy_bellman.graph" << std::endl;
      std::cout << "Bellman Dynamique: Arbre des chemins a été exporté dans le fichier dynamic_bellman.graph" << std::endl;

      std::cout << std::endl << "dot -Tpng bin/test_bellman.graph -o bin/test_bellman.png" << std::endl;
      std::cout << "Graph a été compilé dans le fichier test_bellman.png" << std::endl;
      std::cout << std::endl << "dot -Tpng bin/paths_bellman.graph -o bin/paths_bellman.png" << std::endl;
      std::cout << "Bellman glouton: arbre des chemins a été compilé dans le fichier greedy_bellman.png" << std::endl;
      std::cout << "Bellman dynamique: arbre des chemins a été compilé dans le fichier dynamic_bellman.png" << std::endl;

    }

  catch(const GraphException::InvalidOperation & io)
    {
      std::cout << "Caught GraphException::InvalidOperation:" << std::endl << io.what() << std::endl;
    }

  catch(const GraphException::InvalidNodeID & in)
    {
      std::cout << "Caught GraphException::InvalidNodeID:" << std::endl << in.what() << std::endl;
    }

  catch(const GraphException::InvalidEdge & ie)
    {
      std::cout << "Caught GraphException::InvalidEdge:" << std::endl << ie.what() << std::endl;
    }

  catch(const GraphException::BasicGraphException & bge)
    {
      std::cout << "Caught GraphException::BasicGraphException:" << std::endl << bge.what() << std::endl;
    }

  catch(const std::exception & e)
    {
      std::cout << "Caught exception:" << std::endl << e.what() << std::endl;
    }

  catch(...)
    {
      std::cout << "Caught unexpected exception." << std::endl;
    }

  return 0;
}
开发者ID:shinhermit,项目名称:GraphJ,代码行数:93,代码来源:test_bellman.cpp

示例5: main

int main(int argc, char* argv[]) {
	for(int x = 0; x < 20; x++)
		cout << pfft.ScatterTerrain() << endl;

	g_game = new Game();

	g_game->Init("A* Pathfinding - Dieter", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 800, 0, false);
	while (g_game->isRunning()) {
		g_game->handleEvents();
		g_game->Update();
		g_game->Render();
	}
	g_game->Clean();
	return 0;
}
开发者ID:NanoSpriggan,项目名称:AI_Implementation,代码行数:15,代码来源:main.cpp


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