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; }
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); } }
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; }
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; }
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; }
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; }
//获取节点周围的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; }