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


C++ AStarNode类代码示例

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


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

示例1: if

/// Flip a node when touched 
KDvoid Ch7_GridPathfinding::flipNodeWithTouchedNode ( const CCPoint& tPoint )
{
	KDint	x = (KDint) tPoint.x;
	KDint	y = (KDint) tPoint.y;
	
	if ( x == 0 && y == 0 )
	{
		return;
	}
	if ( x == m_tGridSize.x - 1 && y == m_tGridSize.y - 1 )
	{
		return;
	}
	
	if ( x < 0 || y < 0 || x > m_tGridSize.x - 1 || y > m_tGridSize.y - 1 )
	{
		return;
	}
	
	AStarNode*		pNode = (AStarNode*) ( (CCArray*) m_pGrid->objectAtIndex ( x ) )->objectAtIndex ( y );
	CCSprite*		pSprite = (CCSprite*) m_pSprites->objectForKey ( ccszf ( "(%d,%d)", x, y ) );
	
	if ( pNode->isActive ( ) && m_bAddMode )
	{
		// Remove node as neighbor and vice versa
		pNode->setActive ( KD_FALSE );
		pSprite->setColor ( ccc3 ( 100, 100, 100 ) );
	}
	else if ( !m_bAddMode )
	{
		pNode->setActive ( KD_TRUE );
		// Change sprite color
		pSprite->setColor ( ccc3 ( 200, 200, 200 ) );
	}
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:36,代码来源:Ch7_GridPathfinding.cpp

示例2: CCDictionary

/// Add sprites which correspond to grid nodes 
KDvoid Ch7_GridPathfinding::addGridArt ( KDvoid )
{	
	m_pSprites = new CCDictionary ( );

	for ( KDint x = 0; x < (KDint) m_tGridSize.x; x++ )
	{
		for ( KDint y = 0; y < (KDint) m_tGridSize.y; y++ )
		{
			AStarNode*	pNode = (AStarNode*) ( (CCArray*) m_pGrid->objectAtIndex ( x ) )->objectAtIndex ( y );

			CCSprite*	pSprite = CCSprite::create ( "gridNode.png" );
			pSprite->setPosition ( pNode->getPosition ( ) );
			if ( pNode->isActive ( ) )
			{
				pSprite->setColor ( ccc3 ( 200, 200, 200 ) );
			}
			else
			{
				pSprite->setColor ( ccc3 ( 100, 100, 100 ) );
			}
			m_pGridNode->addChild ( pSprite );
			m_pSprites->setObject ( pSprite, ccszf ( "(%d,%d)", x, y ) );
		}
	}
	
	// Add start point at (0,0)
	CCSprite*	pStartSprite =  CCSprite::create ( "start_button.png" );
	pStartSprite->setPosition ( ccp ( m_tStartCoord.x * m_fNodeSpace + m_fNodeSpace / 2, m_tStartCoord.y * m_fNodeSpace + m_fNodeSpace / 2 ) );
	m_pGridNode->addChild ( pStartSprite );
	
	// Add end point at (gridSize.x-1,gridSize.y-1)
	CCSprite*	pEndSprite =  CCSprite::create ( "end_button.png" );
	pEndSprite->setPosition ( ccp ( m_tEndCoord.x * m_fNodeSpace + m_fNodeSpace / 2, m_tEndCoord.y * m_fNodeSpace + m_fNodeSpace / 2 ) );
	m_pGridNode->addChild ( pEndSprite );
}
开发者ID:mcodegeeks,项目名称:OpenKODE-Framework,代码行数:36,代码来源:Ch7_GridPathfinding.cpp

示例3: popClosed

AStarNode AStar::popClosed()
{
	auto i = std::min_element(closedList->begin(), closedList->end());
	AStarNode temp = *i;
	closedList->erase(i);
	temp.setClosed(false);
	return temp;
}
开发者ID:MidnightDrifter,项目名称:CS580Proj2Pathfinding,代码行数:8,代码来源:AStar.cpp

示例4: check_duplicate

/* 
* Check if a position is in the list 
* @param pos: The position to check the list for
* @param parent_coord: The parent to check the list for
* @return the A* Node pointer if it is in the list, NULL otherwise
*/
AStarNode* AStarNodeList::check_duplicate(Position* pos, Coord* parent_coord)
{
	/* Find the node in the list based on the position only */
	AStarNode* found = list->find(pos);

	/* Check the node for the parent */
	if (found->check_parent(parent_coord) == false)
		return NULL;
	return found;
}
开发者ID:ahoff23,项目名称:MS_Project,代码行数:16,代码来源:AStarNodeList.cpp

示例5: popOpenMin

AStarNode AStar::popOpenMin()
{
	//if()
	auto i = std::min_element(openList->begin(), openList->end());
	AStarNode temp = *i;
	openList->erase(i);
	
	//openList->erase(std::min_element(openList->begin(), openList->end()));
	temp.setOpen(false);
	return temp;
}
开发者ID:MidnightDrifter,项目名称:CS580Proj2Pathfinding,代码行数:11,代码来源:AStar.cpp

示例6: canMoveHorizontal

bool AStar::canMoveHorizontal(const AStarNode& current, const AStarNode& destination) const
{
	if (this->isValidNode(destination.getXCoord(), destination.getYCoord()) && !destination.getWall())
	{
		return true;
	}

	else
	{
		return false;
	}
}
开发者ID:MidnightDrifter,项目名称:CS580Proj2Pathfinding,代码行数:12,代码来源:AStar.cpp

示例7: Reset

void AStar::Reset()
{
	AStarNode *node;
	for(int i = 0; i < Nodes.Count(); i++)
	{
		node = Nodes[i];
		node->SetClosed(false);
		node->SetOpened(false);
	}
	Path.RemoveAll();
	Opened.RemoveAll();
	Closed.RemoveAll();
}
开发者ID:Spacetech,项目名称:gmodmodules,代码行数:13,代码来源:astar.cpp

示例8: NodeGreaterThan

inline bool AStar::ExpandNode()
{
    // Get the min-weight element off the fringe.
    std::pop_heap(FringeNodes.begin(), FringeNodes.end(), NodeGreaterThan());
    CurrentNode = FringeNodes.back();
    FringeNodes.pop_back();

    MapCoordinates TestCoordinates = CurrentNode->LocationCoordinates;

    if (VisitedCoordinates.find(TestCoordinates) != VisitedCoordinates.end())
    {
        return false;
    }

    if (TestCoordinates == GoalCoordinates)
    {
        return true; //GenerateBestPath();
    }

    // mark as VisitedCoordinates if not already VisitedCoordinates
    VisitedCoordinates.insert(TestCoordinates);

    MapCoordinates NeiboringCoordinates;
    DirectionFlags TestDirections = SearchGraph->getDirectionFlags(TestCoordinates);

    // Check all Neibors
	for (uint8_t i = 0, DirectionType = Direction::ANGULAR_DIRECTIONS[i]; i < NUM_ANGULAR_DIRECTIONS; ++i, DirectionType = Direction::ANGULAR_DIRECTIONS[i])
    {
        if (TestDirections & (1 << i))  // Connectivity is valid for this direction
        {
            NeiboringCoordinates = TestCoordinates;
            NeiboringCoordinates.TranslateMapCoordinates(DirectionType);

            // If Coordinate is not already on the VisitedCoordinates list
            if (VisitedCoordinates.find(NeiboringCoordinates) == VisitedCoordinates.end())
            {
                float EdgeCost = SearchGraph->getEdgeCost(TestCoordinates, DirectionType);
                GraphReads++;

                AStarNode* NewNode = NodePool->ProvideObject();
                NewNode->Set(NeiboringCoordinates, CurrentNode, DirectionType, CurrentNode->PathLengthFromStart + EdgeCost, MainHeuristic->Estimate(NeiboringCoordinates, GoalCoordinates), TieBreakerHeuristic->Estimate(NeiboringCoordinates, GoalCoordinates));

                // Add the new Node to the Fringe
                FringeNodes.push_back(NewNode);
                std::push_heap(FringeNodes.begin(), FringeNodes.end(), NodeGreaterThan());
            }
        }
    }

    return false; // Goal was not found
}
开发者ID:Ackak,项目名称:Khazad,代码行数:51,代码来源:Astar.cpp

示例9: delete_node

/* 
* Remove a parent from a node and delete it if it runs out of parents
* @param pos: The position of the node to remove
* @param parent_pos: The parent of the position to remove
* (only remove a position/parent combo)
* @param del_mem: True if the node should be deleted here, false if it should
* simply be marked for deletion (so the OPEN list heap does not contain deleted nodes)
* @return 0 if the node is not found, 
* 1 if it is found but not deleted, 2 if it is found and deleted
*/
int AStarNodeList::delete_node(Position* pos, Coord* parent_coord, bool del_mem)
{
	/* Find the node iterator */
	AStarNode* found = list->find(pos);

	/* Make sure the node exists */
	if (found == NULL)
		return 0;

	/* If the node has no more parents after the deletion of this parent */
	if (found->del_parent(parent_coord) == 0)
	{


	/*	Position check = Position(0, 5, 5);
		if (check == *pos)
		{
			std::cout << "PRE DELETION" << std::endl;
			print_list();
		}*/


		/* remove it from the list */
		list->erase(pos);



		/* Delete the node pointed to by the list or mark it for deletion */
		if (del_mem == true)
			delete found;
		else
			found->mark_for_deletion();

	
		/*
		if (check == *pos)
		{
			std::cout << "POST DELETION" << std::endl;
			print_list();
		}
		*/


		return 2;
	}
	/* The node was found but not deleted */
	return 1;
}
开发者ID:ahoff23,项目名称:MS_Project,代码行数:58,代码来源:AStarNodeList.cpp

示例10: nodeEqualsNode

bool AStarNode::nodeEqualsNode(AStarNode node) {
    for(int i = 0; i < state.getDim(); i++)
        for(int j = 0; j < state.getDim(); j++)
            if(state.getData()[i][j] != node.getState().getData()[i][j])
                return false;
    return true;
}
开发者ID:craigpullar,项目名称:Solving-Sudoku,代码行数:7,代码来源:AStarNode.cpp

示例11: setEndPoints

void AStar::setEndPoints(const MapCoordinates &StartCoords, const MapCoordinates &GoalCoords)
{
    StartCoordinates = StartCoords;
    GoalCoordinates = GoalCoords;
    GraphReads = ExpandedNodes = 0;
    FinalPath = NULL;
    FringeExausted = false;

    FringeNodes.clear();
    VisitedCoordinates.clear();

    NodePool->Wipe();

    AStarNode* StartNode = NodePool->ProvideObject();
    StartNode->Set(StartCoordinates, NULL, DIRECTION_NONE, 0, MainHeuristic->Estimate(StartCoords, GoalCoords), TieBreakerHeuristic->Estimate(StartCoords, GoalCoords));

    FringeNodes.push_back(StartNode);
    std::make_heap(FringeNodes.begin(), FringeNodes.end(), NodeGreaterThan());

    //VisitedCoordinates.insert(StartCoordinates);
};
开发者ID:Ackak,项目名称:Khazad,代码行数:21,代码来源:Astar.cpp

示例12: Save

bool AStar::Save(IFileSystem *filesystem, const char *Filename)
{
	CUtlBuffer buf;

	AStarNode *Node;
	NodeList_t Links;

	int TotalNumLinks = 0;
	int NodeTotal = Nodes.Count();

	//////////////////////////////////////////////
	// Nodes
	buf.PutInt(NodeTotal);

	for(int i = 0; i < NodeTotal; i++)
	{
		Node = Nodes[i];

		buf.PutFloat(Node->GetPos().x);
		buf.PutFloat(Node->GetPos().y);
		buf.PutFloat(Node->GetPos().z);

		TotalNumLinks += Node->GetLinks().Count();
	}
	//////////////////////////////////////////////

	//////////////////////////////////////////////
	// Links
	buf.PutInt(TotalNumLinks);

	for(int i = 0; i < NodeTotal; i++)
	{
		Node = Nodes[i];
		Links = Node->GetLinks();
		for(int li = 0; li < Links.Count(); li++)
		{
			buf.PutInt(Node->GetID());
			buf.PutInt(Links[li]->GetID());
		}
	}
	//////////////////////////////////////////////

	//////////////////////////////////////////////
	// Write File

	FileHandle_t fh = filesystem->Open(Filename, "wb");
	if(!fh)
	{
		return false;
	}

	filesystem->Write(buf.Base(), buf.TellPut(), fh);
	filesystem->Close(fh);
	//////////////////////////////////////////////

	return true;
}
开发者ID:Spacetech,项目名称:gmodmodules,代码行数:57,代码来源:astar.cpp

示例13: AStarNode

/// takes the AASimpleGenerator pointer to access grid from, plus start and end X,Y pairs (start and end of the path)
void AStar::Setup(const ASimpleGenerator *pGenerator, uint32 sx, uint32 sy, uint32 ex, uint32 ey)
{
	pGen = pGenerator;
	if (pGen == NULL) return;

	if (sx >= (uint32)pGen->GridWidth || sy >= (uint32)pGen->GridHeight || ex >= (uint32)pGen->GridWidth || ey >= (uint32)pGen->GridHeight) return;
	startx = sx;
	starty = sy;
	endx = ex;
	endy = ey;

	AStarNode *pNode = new AStarNode();
	pNode->x = sx;
	pNode->y = sy;
	// start node has no G cost because it doesn't move :)
	pNode->F = pNode->H = pNode->GetHCost(ex, ey);

	
	// add our first node to the open list
	mOpenList.Add(pNode);

	mOpenList.Sort(AStar::AStarNodePredicate);

}
开发者ID:zoombapup,项目名称:EventExample,代码行数:25,代码来源:AStar.cpp

示例14: SudokuGameEngine

vector<AStarNode> AStarNode::getChildNodesForNode(AStarNode node){
    SudokuGameEngine engine = SudokuGameEngine();
    vector<Action> actions = engine.getPossibleActionsForState(node.getState());
    vector<AStarNode> children;
    
   
    
    for (Action action : actions) {
        children.push_back(AStarNode (node.getCorrectness(),
                                      GameState (engine.takeActionForState(action, node.getState()))
                                                 , &action, &node));
    }
    
    for (AStarNode child : children) {
        int correctness = 0;
        for (Action action : actions)
            if (action.getRow() == child.getAction().getRow() && action.getCol() == child.getAction().getCol())
                correctness++;
        child.setCorrectness(correctness + child.getPreviousNode().getCorrectness());

    }
    
    return children;
}
开发者ID:craigpullar,项目名称:Solving-Sudoku,代码行数:24,代码来源:AStarNode.cpp

示例15: AStarNode

void AStar::ExamineNode(AStarNode &node)
{

	// Check if node should be ignored, updated or pushed into openList
	
	// Is the node walkable?
	if(!(m_nodeMap.isWalkable(node.GetPosition().x, node.GetPosition().y)))
	{
		return;
	}

	// Check the closedList
	for(unsigned int i = 0; i < m_closedList.size(); i++)
	{
		if(m_closedList[i]->GetPosition() == node.GetPosition())
		{
			// Found in the closed list so abort operation
			return;
		}
	}

	// Check the openList
	for(unsigned int i = 0; i< m_openList.size(); i++){
		if(m_openList[i]->GetPosition() == node.GetPosition()){
			// Found in the openList, check values if it is to be updated
			if(m_openList[i]->GetG() > node.GetG()){
				// The G value will be shorter via the current node so update
				m_openList[i]->SetG(node.GetG());
				// Change the node to point to our current node
				m_openList[i]->SetParent(node.GetParent());
			}
			// It was found and the operation was complete
			return;
		}
	}

	// If it has come to this point the node was not found in the list so push it into the openList
	m_openList.push_back(new AStarNode(node));
}
开发者ID:hoshi89,项目名称:Forgotten,代码行数:39,代码来源:AStar.cpp


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