コード例 #1
0
ファイル: CBobsMap.cpp プロジェクト: bjutlgr/PathFinder
int CBobsMap::CalculateInvalidPointCount(const vector<WayPoint> &waypoints)
{

		int count = 0;
		if(waypoints.size()<1) return -1;
		vector<WayPoint>::const_iterator iter = waypoints.begin();
		SPoint spPre =m_spA;
		iter++;
		SPoint spNext =iter->absoluteXY;

		while(iter!=waypoints.end())
		{
			spNext =iter->absoluteXY;
			//no intersect with barriers and in the rectange of bounds
			if(BarrierIntersection(spPre,spNext)||!IsValidPoint(spNext))
			{
				count++;
			}
			spPre = spNext;
			iter++;
		}
		
		//check B point
		spNext = m_spB;
		if(BarrierIntersection(spPre,spNext)||!IsValidPoint(spNext))
		{
			count++;
		}
		return count;

}
コード例 #2
0
ファイル: Player.cpp プロジェクト: kimsin3003/BattleShip
void Player::SetupShips()
{

	for (auto ship : m_Ships) {

		
		
		
		Point start;
		Point temp;
		int dir;
		
		do {
			start.x = rand() % MAP_WIDTH;
			start.y = rand() % MAP_WIDTH;
				
			dir = rand() % DIR_MAX;

			if (IsValidPoint(start, ship->GetShipSize(), dir)) {
				std::cout << ship->GetName() << " 배치 완료" << std::endl;
				for (int i = 0; i < ship->GetShipSize(); i++) {
					temp = MakePointDirected(start, dir, i);
					ship->AddPoint(temp);
					printf("%d %d \n", temp.x, temp.y);
					std::cout << i << "번째:" << ship->Getpoint(
						
						i).x << ship->Getpoint(i).y << "\n" << std::endl;
				}
				break;
			}

		} while (true);
	}

}
コード例 #3
0
ファイル: CRegion.cpp プロジェクト: bucketyied/Source
bool CTeleport::RealizeTeleport()
{
	ADDTOCALLSTACK("CTeleport::RealizeTeleport");
	if ( !IsValidPoint() || !m_ptDst.IsValidPoint() )
	{
		DEBUG_ERR(("Bad teleport coords %s\n", WriteUsed()));
		return false;
	}
	CSector *pSector = GetSector();
	return pSector ? pSector->AddTeleport(this) : false;
}
コード例 #4
0
ファイル: CRect.cpp プロジェクト: DarkLotus/Source
size_t CPointBase::GetRegions( DWORD dwType, CRegionLinks & rlinks ) const
{
	ADDTOCALLSTACK("CPointBase::GetRegions");
	if ( !IsValidPoint() )
		return 0;

	CSector *pSector = GetSector();
	if ( pSector )
		return pSector->GetRegions(*this, dwType, rlinks);

	return 0;
}
コード例 #5
0
ファイル: CRect.cpp プロジェクト: DarkLotus/Source
CRegionBase * CPointBase::GetRegion( DWORD dwType ) const
{
	ADDTOCALLSTACK("CPointBase::GetRegion");
	// What region in the current CSector am i in ?
	// We only need to update this every 8 or so steps ?
	// REGION_TYPE_AREA
	if ( ! IsValidPoint())
		return NULL;

	CSector *pSector = GetSector();
	if ( pSector )
		return pSector->GetRegion(*this, dwType);

	return NULL;
}
コード例 #6
0
ファイル: CBobsMap.cpp プロジェクト: bjutlgr/PathFinder
bool CBobsMap::GetOneValidPath(vector<int> &vecBits,int chromolen)
{
	int testCount=0;
	int iChromoLength=chromolen;
	int iCutCount=iChromoLength+1;

	Coordinate cord(m_spA,m_spB);

	SPoint spPre=m_spA;
	
	int randomY = 0;
	//divied space 
	SVector2D line(m_spA.x-m_spB.x,m_spA.y-m_spB.y);
	int diffX = (int) Vec2DLength(line)/iCutCount;
	for(int i=1;i<=iChromoLength;i++)
	{	
		randomY = RandInt(-150,150);
		SPoint spRelative(i*diffX,randomY);
		SPoint spPathAbsolute=cord.GetCoordinate(spRelative.x,spRelative.y);
		while(true)
		{			

			if(!BarrierIntersection(spPre,spPathAbsolute)&&IsValidPoint(spPathAbsolute))
			{
				break;
				
			}else
			{
				testCount++;
				if(testCount>100) 
				{
					return false;
				}
			}
			
			randomY = RandInt(-150,150);
			spRelative=SPoint(i*diffX,randomY);
			spPathAbsolute=cord.GetCoordinate(spRelative.x,spRelative.y);
		}	
		//save waypoint
		vecBits.push_back(randomY);
		spPre=spPathAbsolute;
	}

	
	return true;
}
コード例 #7
0
ファイル: CAstar.cpp プロジェクト: xiaohuajiao/Demo
//获取节点周围的8个相邻点坐标
vector<Point> CAstar::GetNeighbor(Point p)
{
	static int dir[8][2] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};

	vector<Point> neighbor;
	Point temp;

	for(int i=0; i<8; i++)
	{
		temp.x = p.x+dir[i][1];
		temp.y = p.y+dir[i][0];
		if(IsValidPoint(temp))
			neighbor.push_back(temp);
	}

	return neighbor;
}