コード例 #1
0
ファイル: STRPath.cpp プロジェクト: xianyinchen/LUNAPlus
void CSTRPath::TraversalChild(CSTRNode * parent, CSTRNode * child)
{
	int x = child->cellX;
	int y = child->cellY;
	int g = parent->goal + CostNode();
	int num = LinearNumber(x, y, m_nWidth);

	CSTRNode * check = NULL;


	if ((check = GetInList(m_pOpenList, num)) != NULL ) 
	{
		parent->child[parent->childNum++] = check;


		if(g < check->goal)
		{
			check->parent = parent;
			check->goal = g;
			check->fithness = g + check->heuristic;
		} 
	}
	else if ( ( check = GetInList(m_pClosedList, num) ) != NULL ) 
	{
		parent->child[parent->childNum++] = check;

		if(g < check->goal)
		{
			check->parent = parent;
			check->goal = g;
			check->fithness = g + check->heuristic;
			SpreadNode(check);
		} 
	} 
	else 
	{
		// 메모리 풀 사용
		CSTRNode * newnode = AllocNode();
		newnode->SetXY(x, y);
		newnode->parent			= parent;
		newnode->goal			= g;
		newnode->heuristic		= abs(x-m_DestX) + abs(y-m_DestY);
		newnode->fithness		= newnode->goal + newnode->heuristic;
		newnode->cellNumber		= LinearNumber(x, y, m_nWidth);
		newnode->next = NULL;

		AddToOpenList(newnode);

		parent->child[parent->childNum++] = newnode;
	}	
}
コード例 #2
0
bool JPSPlusPathFinder::AddNeighbors(const Cell* currentCell, const Cell* nextCell, const Cell* goalCell, Direction direction)
{
	RETURN_FALSE_IF_NULL(nextCell);
	bool outIsCompleted = false;
	Direction outMarkedDirection;
	const Cell* nextNextCell = Jump(nextCell, goalCell, direction, outIsCompleted, outMarkedDirection);
	if (outIsCompleted)
	{
		LinkCell(currentCell, nextNextCell, (direction));
		LinkCell(nextNextCell, goalCell, outMarkedDirection);
		return true;
	}
	if (nextNextCell)
	{
		AddToOpenList(currentCell, nextNextCell, goalCell, direction);
	}
	return false;
}