Exemple #1
0
std::vector<Vect3f> CAStar::Execute()
{
	//CNode* n_FirstNode = new CNode("Init",Vect3f(0.0f,0.0f,0.0f),0.0f,0.0f);
	m_CurrentNode = m_Nodes[0];
	m_CurrentNode->SetPriority(m_CurrentNode->GetLevel()+Heuristic(m_CurrentNode,m_EndPosition)); //TODO Calculate Priority
	m_OpenNodes.push_back(m_CurrentNode);

	while(!IsFinalNode(m_CurrentNode))
	{
		if(!AllNodesVisited())
		{
			VisitNextNode(m_CurrentNode);
		}
	}

	while(m_CurrentNode->GetParent()!=NULL)
	{
		m_Result.push_back(m_CurrentNode->GetPosition());
		m_CurrentNode=m_CurrentNode->GetParent();
	}

	m_Result.push_back(m_CurrentNode->GetPosition());

	return m_Result;
}
// ---------------------------------------------------------------------------
// CSmileyModel::SmileyStringLength
// ---------------------------------------------------------------------------
//
TInt CSmileyModel::SmileyStringLength( TInt aNodeIndex )
    {
    if ( IsFinalNode( aNodeIndex ) )
        {
        TInt linkIndex( iStrArray[aNodeIndex].iChild & ~KLinkIndexMark );
        return iLinkArray[linkIndex].iStrLength;
        }
    return 0;
    }
// ---------------------------------------------------------------------------
// CSmileyModel::FindMatchStr
// ---------------------------------------------------------------------------
//
TInt CSmileyModel::TryFindMatchNode( const TDesC& aText, TInt aTextPos )
    {
    TInt index( 0 );
    index = FindInSibling( index, aText[aTextPos] );
    TInt textPos( aTextPos + 1 );
    while ( index != KInvalidIndex && !IsFinalNode( index ) && 
        textPos < aText.Length() )
        {            
        index = iStrArray[index].iChild;
        index = FindInSibling( index, aText[textPos] );
        if ( index != KInvalidIndex )
            {
            textPos++;
            }
        }
    return index;
    }
Exemple #4
0
void CAStar::ProcesarVecinos(CNode* Node)
{
	/*¿Cómo obtener vecinos del NODO?*/
	for(size_t i=0;i<Node->m_Neighbours.size();++i)
	{
		if(!Node->m_Neighbours[i]->GetClosed())
		{
			CalculateG(Node->m_Neighbours[i]);

			if(std::find(m_OpenNodes.begin(), m_OpenNodes.end(), Node->m_Neighbours[i]) != m_OpenNodes.end()) 
			{	//Esta en la lista de nodos abiertos
				float l_NewG = Node->GetLevel() + Node->m_Neighbours[i]->GetLevel();

				if(l_NewG < Node->m_Neighbours[i]->GetLevel()) 
				{
					Node->m_Neighbours[i]->SetParent(Node);
					Node->m_Neighbours[i]->SetLevel(l_NewG);
					Node->m_Neighbours[i]->SetPriority(Node->m_Neighbours[i]->GetLevel()+Heuristic(Node->m_Neighbours[i],m_EndPosition));
				}

			} else //No está en la lista de nodos abiertos
			{
				Node->m_Neighbours[i]->SetParent(Node);
				
				if(IsFinalNode(Node))
				{
					m_Finished=true;
				}
				else
				{
					//save g,h
					Node->m_Neighbours[i]->SetPriority(Node->m_Neighbours[i]->GetLevel()+Heuristic(Node->m_Neighbours[i],m_EndPosition));
					m_OpenNodes.push_back(Node->m_Neighbours[i]);
				}
			}
		}
	}
}