Exemplo n.º 1
0
void rotate(DoubleCRT& d, long amt, 
            const vector< vector< DoubleCRT > > & maskTable)

// rotate d by amt

{
  const FHEcontext& context = d.getContext();
  const PAlgebra& al = context.zMstar;
  //  const PAlgebraModTwo& al2 = context.modTwo;

  long ngens = al.numOfGens();
  long nslots = al.NSlots();

  amt = amt % nslots;
  if (amt < 0) amt += nslots;

  if (amt == 0) return;

  long i, v;

  i = ngens-1;
  v = coordinate(al, i, amt);
  rotate1D(d, i, v, maskTable);

  if (i == 0) return;

  DoubleCRT mask(context, d.getIndexSet());
  mask.SetZero();
  mask.Add(maskTable[i][v], false);

  DoubleCRT tmp(context, d.getIndexSet());


  for (i--; i >= 0; i--) {
    v = coordinate(al, i, amt);

    tmp.SetZero();
    tmp += d;
    tmp *= mask;
    d -= tmp;
    rotate1D(d, i, v+1, maskTable);
    rotate1D(tmp, i, v, maskTable); 
    d += tmp;

    if (i > 0) {
      tmp.SetZero();
      tmp.Add(maskTable[i][v], false);
      tmp.Sub(maskTable[i][v+1], false);
      mask *= tmp;
      mask.Add(maskTable[i][v+1], false);
    }
  }


}
Exemplo n.º 2
0
dungeons::dungeons()
{
    std::default_random_engine generator(time(0));
    std::ofstream myfile;
    std::uniform_int_distribution<int> mazeSize(500,1000);
    std::uniform_int_distribution<int> mazestart(0,1000);
    w=mazeSize(generator);
    h=w;
    directions[0]=coordinate(0,-1);
    directions[1]=coordinate(1,0);
    directions[2]=coordinate(0,1);
    directions[3]=coordinate(-1,0);
    while(true)
    {
        mazebegin.x=mazestart(generator);
        mazebegin.y=mazestart(generator);
        if (mazebegin.x<w and mazebegin.y<h)
        {
            break;
        }
    }

    dungeon_grid.resize(h);

    for (int i=0;i<h;i++)
    {
        dungeon_grid[i].resize(w);
        for (int j=0;j<w;j++)
        {
            dungeon_grid[i][j]=false;
        }
    }

    std::string dungeonTextFile;
    hallwaymaker();
    for (int i=0;i<dungeon_grid.size();i++)
    {
        for (int j=0;j<dungeon_grid.size();j++)
        {
            if (dungeon_grid[i][j]==true)
            {
                dungeonTextFile+='.';
            }
            else
            {
                dungeonTextFile+='H';
            }
        }
        dungeonTextFile+='\n';
    }
    myfile.open ("map.txt");
    myfile << dungeonTextFile;
    myfile.close();
}
Exemplo n.º 3
0
coordinate levelMap::levelGen(){
	//number_of_rooms =  new int(20);  //CHANGE TO ADD ROOMS
	x = new int[number_of_rooms];
	y = new int[number_of_rooms];

	//pick center of rooms
	for( int a = 0; a < number_of_rooms; a++){

		x[a] = (rand() % (x_dim - 6)) + 3;

		y[a] = (rand() % (x_dim - 6)) + 3;

	}
	//splash rooms
	for( int a = 0; a < number_of_rooms; a++){
	
		Map[y[a]][x[a]].Floor = 0x101;


	}
	for (int b = 0; b <number_of_rooms; b++){
		splash(x[b] , y[b], 5);
		
	}
	//connect rooms

		corridorLink(x[0], y[0], x[1], y[1]);
		for(int g = 1; g< number_of_rooms; g++){
			corridorLink(x[g-1], y[g-1], x[g], y[g]);
		}
		
		return( coordinate(x[0], y[0]) );

}
/*
 This is _only_ called when QGeoPositionInfoValidator::valid() returns true for the position.
 This means that it is implied that:
 - (data.dwValidFields & GPS_VALID_LATITUDE) != 0
 - (data.dwValidFields & GPS_VALID_LONGITUDE) != 0
 - (data.dwValidFields & GPS_VALID_UTC_TIME) != 0

 This guarantees that the newly created position will be valid.
 If the code is changed such that this is no longer guaranteed then this method will need to be
 updated to test for those conditions.
*/
void QGeoPositionInfoSourceWinCE::dataUpdated(GPS_POSITION data)
{
    QGeoCoordinate coordinate(data.dblLatitude, data.dblLongitude);

    // The altitude is optional in QGeoCoordinate, so we do not strictly require that the
    // GPS_POSITION structure has valid altitude data in order to trigger an update.
    if ((data.dwValidFields & GPS_VALID_ALTITUDE_WRT_SEA_LEVEL) != 0)
        coordinate.setAltitude(data.flAltitudeWRTSeaLevel);

    QDate date(data.stUTCTime.wYear, data.stUTCTime.wMonth, data.stUTCTime.wDay);
    QTime time(data.stUTCTime.wHour, data.stUTCTime.wMinute, data.stUTCTime.wSecond,
               data.stUTCTime.wMilliseconds);

    QDateTime dateTime(date, time, Qt::UTC);

    QGeoPositionInfo pos(coordinate, dateTime);

    // The following properties are optional, and so are set if the data is present and valid in
    // the GPS_POSITION structure.
    if ((data.dwValidFields & GPS_VALID_SPEED) != 0)
        pos.setAttribute(QGeoPositionInfo::GroundSpeed, data.flSpeed);

    if ((data.dwValidFields & GPS_VALID_HEADING) != 0)
        pos.setAttribute(QGeoPositionInfo::Direction, data.flHeading);

    if ((data.dwValidFields & GPS_VALID_MAGNETIC_VARIATION) != 0)
        pos.setAttribute(QGeoPositionInfo::MagneticVariation, data.dblMagneticVariation);

    lastPosition = pos;
    emit positionUpdated(pos);
}
Exemplo n.º 5
0
void parse_resource_data(sexp_t* resources, myAI& ai) {

	sexp_t* cur = resources->list;
	deque<resource> resourceNodes;
	int x_loc = 0;
	int y_loc = 0;
	
	while(cur != NULL) {
	
		float myMult, enemyMult;
		if(ai.playerNumber == 1) {
			myMult    = (float)atof(cur->list->next->next->next->next->val);
			enemyMult = (float)atof(cur->list->next->next->next->next->next->val);
		} else {
			myMult    = atof(cur->list->next->next->next->next->next->val);
			enemyMult = atof(cur->list->next->next->next->next->val);		
		}
	
		x_loc = atoi(cur->list->next->next->val);
		y_loc = atoi(cur->list->next->next->next->val);
	
		resource res(
			atoi(cur->list->next->val), // remaining juice
			coordinate(x_loc,y_loc), // x,y location
			myMult,      // my multiplier
			enemyMult // enemy multiplier
		);
		resourceNodes.push_back(res);
	
		cur = cur->next;
	}
	ai.resourceNodes = resourceNodes;

}
Exemplo n.º 6
0
int Castle::Unblock() {
	vector<int> coordinate(3);
	for(int i = min_.x ; i <= max_.x; i++)
		for(int j = min_.y ; j <= max_.y; j++)
			for(int k = min_.z ; k <= max_.z; k++) {
				coordinate[0] = i;
				coordinate[1] = j;
				coordinate[2] = k;
				int jj;
				if(!room_index_[coordinate] && (jj = OneNeighbor(i, j, k)) != -1) {
					int nn = room_.size();
					room_index_[coordinate] = nn;
					switch(jj) {
						case 0: coordinate[1] = j + 1; break;
						case 1: coordinate[1] = j - 1; break;
						case 2: coordinate[0] = i - 1; break;
						case 3: coordinate[0] = i + 1; break;
						case 4: coordinate[2] = k + 1; break;
						case 5: coordinate[2] = k - 1; break;
					}
					int n = room_index_[coordinate];
					room_[n].door(jj ^ 1, nn);
					room_[n].k_door(room_[n].k_door() + 1);
					Room room(i, j, k, rand() % MaxDoor(i, j, k) + 1);
					room.door(jj, n);
					room_.push_back(room);
//					cout << "                        Unblock: " << nn << " " << i << " " << j << " " << k << endl;
					return nn;
				}
			}
	return 0;
}
Exemplo n.º 7
0
int Castle::OneNeighbor(int x, int y, int z) {
	vector<int> coordinate(3);
	int a[7] = {0, 1, 2, 3, 4, 5};
	int j;

	for(int i = 0; i < 6; i++) {
		j = rand() % 6;
		a[6] = a[i];
		a[i] = a[j];
		a[j] = a[6];
	}
	for(j = 0; j < 6; j++) {
		coordinate[0] = x;
		coordinate[1] = y;
		coordinate[2] = z;
		switch(a[j]) {
			case 0: coordinate[1] = y + 1; break;
			case 1: coordinate[1] = y - 1; break;
			case 2: coordinate[0] = x - 1; break;
			case 3: coordinate[0] = x + 1; break;
			case 4: coordinate[2] = z + 1; break;
			case 5: coordinate[2] = z - 1; break;
		}
		if(room_index_[coordinate]) return a[j];
	}

	return -1;
}
Exemplo n.º 8
0
coordinate coordinate::operator+(const coordinate &other){
	double x = this->x + other.x;
	double y = this->y + other.y;
	double z = this->z + other.z;
	double theta = this->theta + other.theta;
return coordinate(x,y,z,theta);
};
Exemplo n.º 9
0
void CityList::readCityList(const TQString &fname)
{
  TQFile f(fname);

  if (f.open(IO_ReadOnly))
    {
      TQTextStream is(&f);

      TQString line;
      TQStringList tags;
      TQRegExp coord("[+-]\\d+[+-]\\d+");
      TQRegExp name("[^\\s]+/[^\\s]+");
      int pos;
      while (!is.eof())
	{
	  line = is.readLine().stripWhiteSpace();
	  if (line.isEmpty() || line.left(1) == "#")
	    continue;

	  TQString c, n;
	  
	  pos = coord.search(line, 0);
	  if (pos >= 0)
	    c = line.mid(pos, coord.matchedLength());
	  
	  pos = name.search(line, pos);
	  if (pos > 0)
	    n = line.mid(pos, name.matchedLength()).stripWhiteSpace();

	  if (!c.isEmpty() && !n.isEmpty())
	    {
	      double la, lo;
	      pos = c.find("+", 1);
	      if (pos < 0)
		pos = c.find("-", 1);
	      if (pos > 0)
		{
		  la = coordinate(c.left(pos));
		  lo = coordinate(c.mid(pos));
		  _cities.append(new City(n.latin1(), la, lo));
		}
	    }
	}

      f.close();
    }
}
Exemplo n.º 10
0
 /// Gets elevation for given geocoordinate using specific elevation provider.
 double getElevationByQuadKey(int tileX, int tileY, int levelOfDetail, // quadkey info
                              int eleDataType,                         // elevation data type
                              double latitude, double longitude) const {
   utymap::QuadKey quadKey(levelOfDetail, tileX, tileY);
   auto eleProviderType = static_cast<ElevationDataType>(eleDataType);
   utymap::GeoCoordinate coordinate(latitude, longitude);
   return context_.getElevationProvider(quadKey, eleProviderType).getElevation(quadKey, coordinate);
 }
Exemplo n.º 11
0
void PaintWidget::setDestination(qint16 x, quint16 y) {
	IRenderer* renderer = MapData::instance()->renderer();
	if ( renderer == NULL )
		return;

	UnsignedCoordinate coordinate(renderer->PointToCoordinate(x - width() / 2, y - height() / 2, m_request));
	RoutingLogic::instance()->setWaypoint( 0, coordinate ); //0 should be real current waypoint
}
Exemplo n.º 12
0
void PaintWidget::setSource(qint16 x, quint16 y) {
	IRenderer* renderer = MapData::instance()->renderer();
	if ( renderer == NULL )
		return;

	UnsignedCoordinate coordinate(renderer->PointToCoordinate(x - width() / 2, y - height() / 2, m_request));
	RoutingLogic::instance()->setSource( coordinate );
}
Exemplo n.º 13
0
//mossa giocatore vivente
void mossavivente(int m[DIM][DIM],int g)
{
	int x,y,cod;
	cod=coordinate(m);
	x=dex(cod);
	y=dey(cod);
    m[x-1][y-1]=g;
}
Exemplo n.º 14
0
void dungeons::hallwaymaker()
{
    std::default_random_engine generator(time(0));
    std::stack<coordinate> mazetracker;
    std::vector<int>directionsToCheck;
    std::uniform_int_distribution<int> roomDirection(1,4);
    int direction;
    int temp;
    bool timeToBreak;
    mazetracker.push(mazebegin);
    while (true)
    {
        directionsToCheck=adjacencyCheck(mazetracker.top(), dungeon_grid);
        if (directionsToCheck.size()==0)
        {
            std::cout << mazetracker.top().x << "," << mazetracker.top().y << std::endl;
            break;
        }
        while (timeToBreak==false)
        {
            temp=roomDirection(generator);
            for (int i=0;i<4;i++)
            {
                if (directionsToCheck[i]==temp)
                {
                    direction=temp;
                    timeToBreak=true;
                }
            }
        }
        timeToBreak=false;
        if (dungeon_grid[mazetracker.top().y+directions[direction-1].y][mazetracker.top().x+directions[direction-1].x]==false and mazetracker.top().y+directions[direction-1].y>0 and mazetracker.top().y+directions[direction-1].y<h and mazetracker.top().y+directions[direction-1].y>0 and mazetracker.top().x+directions[direction-1].x<w)
        {
            mazetracker.push(coordinate(mazetracker.top().x+directions[direction-1].x,mazetracker.top().y+directions[direction-1].y));
            dungeon_grid[mazetracker.top().y][mazetracker.top().x]=true;
            mazetracker.push(coordinate(mazetracker.top().x+directions[direction-1].x,mazetracker.top().y+directions[direction-1].y));
            dungeon_grid[mazetracker.top().y][mazetracker.top().x]=true;
        }
        else
        {
            mazetracker.pop();
            //mazetracker.pop();
        }
    }
}
Exemplo n.º 15
0
void Simulation::init() {
	window.create(sf::VideoMode(height, width),
	              "Fireflies",
	              sf::Style::Close | sf::Style::Titlebar);
	window.setPosition(sf::Vector2i(700, 100));
	window.setVerticalSyncEnabled(true);
	
	intDistribution rgb{0, 255};
	for (auto fly=fireflies.begin(), end=fireflies.end()-1; fly != end; ++fly) {
		fly->color = turnToHSL(sf::Color(rgb(mt), rgb(mt), rgb(mt)));
		fly->color.luminance = luminance(mt);
		fly->position = {coordinate(mt), coordinate(mt), coordinate(mt)};
		fly->velocity = {velComponent(mt), velComponent(mt), velComponent(mt)};
	}

	fireflies.back().color = turnToHSL(sf::Color::Red);
	fireflies.back().velocity = {0.f, 0.f, 0.f};
}
Exemplo n.º 16
0
void Castle::GenerateLobby() {
	Room room(0, 0, 0, (k_room_ > 1 ? rand() % MaxDoor(0, 0, 0) + 1 : 0));
	room.k_door(0);
	room_.push_back(room);
	room_.push_back(room);
	room_count_[1] = 1;
	vector<int> coordinate(3, 0);
	room_index_[coordinate] = 1;
}
//
// This funtion will test MaxDistance function of CPosLmNearestCriteria class. 	 
//	
void CTestPosLmNearestCriteria::TestMaxDistanceL()
	{
	TCoordinate coordinate(31.6,62.3);
	CPosLmNearestCriteria* nearestCriteria=CPosLmNearestCriteria::NewLC(coordinate);
	if(!Math::IsNaN(nearestCriteria->MaxDistance()))
		{
		User::Leave(KErrGeneral);
		}
	CleanupStack::PopAndDestroy(nearestCriteria);
	}
Exemplo n.º 18
0
void
QcViewport::set_projection(const QcProjection * projection)
{
  if (!m_projection or *projection != *m_projection) {
    m_projection = projection; // Fixme: passing ‘const QcProjection’ as ‘this’ argument discards qualifiers
    m_is_web_mercator = *projection == QcWebMercatorCoordinate().cls_projection;
    QcWgsCoordinate coordinate(projection->wgs84_origin());
    set_center(coordinate);
  }
}
//
// This funtion will test GetCoordinate function of CPosLmNearestCriteria class. 	 
//
void CTestPosLmNearestCriteria::TestGetCoordinateL()
	{
	TCoordinate coordinate(31.6,62.3);
	CPosLmNearestCriteria* nearestCriteria=CPosLmNearestCriteria::NewLC(coordinate);
	TCoordinate getCoordinate;
	nearestCriteria->GetCoordinate(getCoordinate);
	if((getCoordinate.Latitude()!=31.6)||(getCoordinate.Longitude()!=62.3))
		{
		User::Leave(KErrGeneral);
		}
	CleanupStack::PopAndDestroy(nearestCriteria);
	}
Exemplo n.º 20
0
void GPSSpeedData::locationUpdated(const DeviceLocation &location) {
    if(location.m_positionLog.size() < 2)
        return;
    auto currentPos = location.m_positionLog.at(location.m_positionLog.length()-1);
    auto prevPos = location.m_positionLog.at(location.m_positionLog.length()-2);
    if(!currentPos.isValid() && !prevPos.isValid())
        return;

    qreal delta_s = currentPos.coordinate().distanceTo(prevPos.coordinate());
    qreal delta_t = (currentPos.timestamp().toMSecsSinceEpoch() - prevPos.timestamp().toMSecsSinceEpoch())/1000.0f;
    if(delta_t > 0) {
        m_speedData = delta_s/delta_t * 3600.0 / 1000.0;
        m_deltat = delta_t;
        m_deltas = delta_s;
    }
    m_smoothedSpeedData = MathUtils::exponentialFilter(m_speedData, m_prevSpeedData, m_alpha);
    m_prevSpeedData = m_smoothedSpeedData;
    m_avgSpeedData = m_avgSpeedData + (m_speedData - m_avgSpeedData) / ++m_pointsCount;

    emit speedChanged();
}
Exemplo n.º 21
0
void QGoogleMap::reply(QNetworkReply *rep) {

    QString replyStr( rep->readAll() );
    QStringList coordinateStrList = replyStr.split(",");

    if( coordinateStrList.size() == 4) {
        QPointF coordinate( coordinateStrList[2].toFloat(),coordinateStrList[3].toFloat() );
        coord << coordinate;
    }
    --pendingReq;
    if( pendingReq<1 )
        emit( reloadMap());
}
Exemplo n.º 22
0
void GoogleMapChart::replyFinished(QNetworkReply *reply){
    QString replyStr( reply->readAll() );
    QStringList coordinateStrList = replyStr.split(",");

    if(coordinateStrList.size() == 4){
        QPointF coordinate( coordinateStrList[2].toFloat(),coordinateStrList[3].toFloat() );
        coordinates << coordinate;
    }

    --pendingRequests;
    if(pendingRequests < 1)
        emit(reloadMap());
}
Exemplo n.º 23
0
void GisMapWidget::zoomOutSlot()
{
	long int h, w;
	this->GetMapHW( &h, &w);
	QPoint mousePos = mapFromGlobal( QCursor::pos());
	DOUBLEPOINT coordinate( this->pictureToGeo( mousePos.x(), mousePos.y()));
	this->SetViewScale( this->GetViewScale() / ScaleFactor_);

//	if( sender() != zoomOutAction_)
//	{
		DOUBLEPOINT dPoint = this->geoToPicture( coordinate);
		this->SetMapLeftTop( dPoint.x - mousePos.x(), dPoint.y - mousePos.y());
//	}
}
Exemplo n.º 24
0
// --------------------------
//  描画
// --------------------------
void DrawGL::draw()
{
    glClearColor(0.92, 0.92, 0.92, 0.0);
    glClearDepth(1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    float Diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};         //拡散反射
    float DiffuseLight[] = { 0.2f, 0.2f, 0.2f, 1.0f};   //拡散光
    float specular[]= {1.0f, 1.0f, 1.0f, 1.0f};         //鏡面反射
    float SpecularLight[] = {0.3, 0.3, 0.3, 1.0};       //鏡面光
    float lightpos[] = {-700, 900, 1200};

    glMaterialfv(GL_FRONT,GL_DIFFUSE,Diffuse);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, DiffuseLight);
    glMaterialfv(GL_FRONT,GL_SPECULAR,specular);
    glLightfv(GL_LIGHT0, GL_SPECULAR, SpecularLight);
    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

    glPushMatrix();

        // Polar Trans
        glTranslatef(0.0, 0.0, -_polar.distance);
        glRotatef(-_polar.twist, 0.0, 0.0, 1.0);
        glRotatef(-_polar.elevation, 1.0, 0.0, 0.0);
        glRotatef(-_polar.azimuth, 0.0, 1.0, 0.0);

        // 逆運動学の時、目標点を描画
        if(_kinematics_number == INV_KINEMATICS) {
            glPushMatrix();
                _model.target_point(_target.x, _target.y, _target.z);
            glPopMatrix();
        }

        glPushMatrix();
            // 地面
            coordinate(1500, 50);
            _model.xyz_axis();
        glPopMatrix();

        glPushMatrix();

            // 台車
            _model.truck(_model.theta0(), _model.r());
            // マニピュレータ
            _model.manipulator(_model.theta1(), _model.theta2(), _model.d());
        glPopMatrix();

    glPopMatrix();

}
Exemplo n.º 25
0
void gradient_xy(double *map,double *grad_map_x,double *grad_map_y,long map_size,int Npoints,int *x_points,int *y_points){
	
	long i,j;
	double grad_x,grad_y;

	if(Npoints<0){
	
		for(i=0;i<map_size;i++){
			for(j=0;j<map_size;j++){
			
			
				grad_x=(map[coordinate(i+1,j,map_size)]-map[coordinate(i-1,j,map_size)])/2.0;
				grad_y=(map[coordinate(i,j+1,map_size)]-map[coordinate(i,j-1,map_size)])/2.0;
			
				grad_map_x[coordinate(i,j,map_size)]=grad_x;
				grad_map_y[coordinate(i,j,map_size)]=grad_y;
			
			
			}
		}
	

	} else{

		for(i=0;i<Npoints;i++){

			grad_x=(map[coordinate(x_points[i]+1,y_points[i],map_size)]-map[coordinate(x_points[i]-1,y_points[i],map_size)])/2.0;
			grad_y=(map[coordinate(x_points[i],y_points[i]+1,map_size)]-map[coordinate(x_points[i],y_points[i]-1,map_size)])/2.0;
			
			grad_map_x[i]=grad_x;
			grad_map_y[i]=grad_y;

		}


	}
}
Exemplo n.º 26
0
long PAlgebra::addCoord(long i, long k, long offset) const
{
  if (isDryRun()) return 0;
  assert(k >= 0 && k < (long) nSlots);
  assert(i >= 0 && i < (long) gens.size());
  
  offset = offset % ((long) OrderOf(i));
  if (offset < 0) offset += OrderOf(i);
  
  long k_i = coordinate(i, k);
  long k_i1 = (k_i + offset) % OrderOf(i);
  
  long k1 = k + (k_i1 - k_i) * prods[i+1];
  
  return k1;
}
Exemplo n.º 27
0
void Castle::Print() {
	vector<int> coordinate(3);
/*	cout << room_.size() - 1 << endl;
	for(vector<Room>::iterator it = room_.begin() + 1; it != room_.end(); it++)
		cout << it->k_door_max() - it->k_door() << " " << it->k_door() << " " << it->coordinate_x() << " " << it->coordinate_y() << " " << it->coordinate_z() << endl;
	cout << room_.size() - 1 << endl;*/
	cout << room_[1].k_door() << " " << room_[1].k_door_max() << endl;
/*	for(int i = min_.x; i <= max_.x; i++)
		for(int j = min_.y; j <= max_.y; j++)
			for(int k = min_.z; k <= max_.z; k++) {
				coordinate[0] = i;
				coordinate[1] = j;
				coordinate[2] = k;
				if(!room_index_[coordinate]) cout << i << " " << j << " " << k << endl;
			}*/
}
Exemplo n.º 28
0
void model1()
{
    /* clear all pixels */
    glClearColor (0.0, 0.0, 0.0, 0.0);//default background for white
    glClear (GL_COLOR_BUFFER_BIT);
    
    /* print coordinate */
    grid();
    coordinate();
    function_1();
    function_2();
    function_3();
    function_4();
    /* buffer */
    glFlush();
}
Exemplo n.º 29
0
std::vector<node> getNeighbors(node Node, bool test_map[][20], coordinate goal, int costSoFar)
{
    std::vector<node> neighbors;
    for (int x=-1;x<=1;x++){
        for (int y=-1;y<=1;y++){
            if (x==0 and y==0){
                continue;
            }
            int checkX=Node.position.x+x, checkY=Node.position.y+y;
            if (checkX>=0 and checkX<20 and checkY>=0 and checkY<20 and test_map[Node.position.x+x][Node.position.y+y]==0)
            {
                neighbors.push_back(node(coordinate(checkX,checkY), goal, costSoFar+(abs((x)+abs(y))+1)));
                neighbors[0].parent=Node.position;
            }
        }
    }

    return neighbors;
}
Exemplo n.º 30
0
void MemoryPacketModel::launchUpdate(TransformAbstract *transform, int row, int column, int length)
{
//   qDebug() << "update row" << row << "column" << column << "length" << length;
    if (transform == nullptr || packetsList.size() == 0)
        return; // nothing to do here

    if (row < 0 || row >= packetsList.size()) {
        qCritical() << tr("[MemoryPacketModel::launchUpdate] Row value out-of-bound: %1 T_T").arg(row);
        return;
    }
    if (length < 0) { // all to the end of the list
        length = packetsList.size() - row;
    }

    if (row > packetsList.size() - length) {
        qCritical() << tr("[MemoryPacketModel::launchUpdate] Row (%1) + length (%2) value is out-of-bound T_T").arg(row).arg(length);
        return;
    }

    TransformAbstract * ta = transformFactory->cloneTransform(transform);
    if (ta != nullptr) {
        QList<QByteArray> dataList;
        for (int i = row; i < row + length; i++) {
            dataList.append(packetsList.at(i)->getData());
        }

        TransformRequest *tr = new(std::nothrow) TransformRequest(
                    ta,
                    dataList,
                    0);

        if (tr == nullptr) {
            qFatal("Cannot allocate memory for TransformRequest X{");
        }

        connect(tr,SIGNAL(finishedProcessing(QList<QByteArray>,Messages)), this, SLOT(transformRequestFinished(QList<QByteArray>,Messages)));
        QPair<int,int> coordinate(row, column);
        transformRequests.insert((quintptr)tr, coordinate);
        emit readOnlyStateChanged(true);
        emit sendRequest(tr);
    }
}