コード例 #1
0
ファイル: lm_astar_search.cpp プロジェクト: valeriyr/Hedgehog
void
AStarSearch::pathToPoint(
		PointsCollection& _path
	,	const ILandscape& _landscape
	,	const GameObject& _forObject
	,	const QPoint& _targetPoint )
{
	IPathFinder::PointsCollection targetPoints;
	targetPoints.push_back( _targetPoint );

	AStarSearch().findPath( _path, _landscape, _forObject, targetPoints );

} // AStarSearch::pathToPoint
コード例 #2
0
void MoveChild() {
	UpdateObjectType *msg;
	ObjectType temp;
	int newx, newy;
	int block;

	while(!childPath) {
		do {
			newx = lrand48() % (HOUSE_WIDTH - 4) + 2;
			newy = lrand48() % (HOUSE_HEIGHT - 4) + 2;
			pthread_mutex_lock(&mapMutex);
			block = map[newy][newx].type;
			pthread_mutex_unlock(&mapMutex);
		} while(block != TYPE_FLOOR);
		childPath = AStarSearch(newx, newy, child.x, child.y);
	}

	msg = Dequeue(&childPath);

	pthread_mutex_lock(&mapMutex);
	temp = map[msg->newy][msg->newx];
	pthread_mutex_unlock(&mapMutex);

	if(temp.type == TYPE_DOOR && temp.locked) {
		while(childPath) {
			free(Dequeue(&childPath));
		}
	} else {
		pthread_mutex_lock(&mapMutex);
		map[msg->newy][msg->newx] = map[msg->oldy][msg->oldx];
		map[msg->oldy][msg->oldx] = childBlock;
		msg->oldObject = map[msg->oldy][msg->oldx];
		msg->newObject = map[msg->newy][msg->newx];
		pthread_mutex_unlock(&mapMutex);

		childBlock = temp;
		child.x = msg->newx;
		child.y = msg->newy;

		ActivateObject(child.x, child.y);

		pthread_mutex_lock(&updateMutex);
		if(!updateQueue) {
			CreateQueue(&updateQueue);
		}
		Enqueue(&updateQueue, msg);
		pthread_mutex_unlock(&updateMutex);
	}
}
コード例 #3
0
ファイル: lm_astar_search.cpp プロジェクト: valeriyr/Hedgehog
void
AStarSearch::pathToObject(
		PointsCollection& _path
	,	const ILandscape& _landscape
	,	const GameObject& _forObject
	,	const GameObject& _targetObject
	,	const int _distance )
{
	IPathFinder::PointsCollection targetPoints;

	fillTargetPoints( _targetObject, _landscape, _distance, targetPoints );

	AStarSearch().findPath( _path, _landscape, _forObject, targetPoints );

} // AStarSearch::pathToObject
コード例 #4
0
ファイル: lm_astar_search.cpp プロジェクト: valeriyr/Hedgehog
boost::shared_ptr< GameObject >
AStarSearch::nearestObject(
		const ILandscape& _landscape
	,	const GameObject& _forObject
	,	const ILandscape::ObjectsCollection& _targetObjects
	,	const int _distance )
{
	IPathFinder::PointsCollection targetPoints;

	ILandscape::ObjectsCollectionConstIterator
			begin = _targetObjects.begin()
		,	end = _targetObjects.end();

	for ( ; begin != end; ++begin )
		fillTargetPoints( **begin, _landscape, _distance, targetPoints );

	PointsCollection path;
	AStarSearch().findPath( path, _landscape, _forObject, targetPoints );

	if ( path.empty() )
		return boost::shared_ptr< GameObject >();

	begin = _targetObjects.begin();

	for ( ; begin != end; ++begin )
	{
		if ( Geometry::checkDistance(
					path.back()
				,	LocateComponent::getRect( *( *begin )->getMemberObject( LocateComponent::Name ) )
				,	_distance ) )
		{
			return *begin;
		}
	}

	return boost::shared_ptr< GameObject >();

} // AStarSearch::nearestObject
コード例 #5
0
ファイル: main.cpp プロジェクト: mhayk/a-star
int	main()
{
	MakeMap();
	AStarSearch("Arad", "Bucharest");
	return 0;
}
コード例 #6
0
bool ompl::LTLVis::VRVPlanner::GraphSearch(const ompl::base::PlannerTerminationCondition &ptc, ompl::geometric::PathGeometric &solution, bool useAStar)
{
  return (useAStar)?(AStarSearch(ptc, solution)):(DijkstraSearch(ptc, solution));
}