void BattleCommunicator::startBattle(Player *p1, Player *p2, const ChallengeInfo &c, int id, int team1, int team2)
{
    if (!valid()) {
        qFatal("Starting a battle when no valid connections");
    }

    QString tier = p1->team(team1).tier == p2->team(team2).tier ? p1->team(team1).tier : QString("Mixed %1").arg(GenInfo::Version(p1->team(team1).gen));

    mybattles.insert(id, new FullBattleConfiguration(id, p1->id(), p2->id(), tier, c));
    mybattles[id]->name[0] = p1->name();
    mybattles[id]->name[1] = p2->name();

    if (TierMachine::obj()->exists(tier)) {
        Tier & t = TierMachine::obj()->tier(tier);

        BattlePlayer pb1(p1->name(), p1->id(), p1->rating(p1->team(team1).tier), p1->avatar(), p1->winningMessage(), p1->losingMessage(),
                         p1->tieMessage(), t.getMaxLevel(), t.restricted(p1->team(team1)), t.maxRestrictedPokes, t.numberOfPokemons);
        BattlePlayer pb2(p2->name(), p2->id(), p2->rating(p2->team(team2).tier), p2->avatar(), p2->winningMessage(), p2->losingMessage(),
                         p2->tieMessage(), t.getMaxLevel(), t.restricted(p2->team(team2)), t.maxRestrictedPokes, t.numberOfPokemons);

        relay->startBattle(id, pb1, pb2, c, p1->team(team1), p2->team(team2));
    } else {
        BattlePlayer pb1(p1->name(), p1->id(), p1->rating(p1->team(team1).tier), p1->avatar(), p1->winningMessage(), p1->losingMessage(),
                         p1->tieMessage());
        BattlePlayer pb2(p2->name(), p2->id(), p2->rating(p2->team(team2).tier), p2->avatar(), p2->winningMessage(), p2->losingMessage(),
                         p2->tieMessage());

        relay->startBattle(id, pb1, pb2, c, p1->team(team1), p2->team(team2));
    }

    p1->addBattle(id);
    p2->addBattle(id);
}
示例#2
0
void RandomModel::surfacesAndEdges(double margin[2], 
								   double bH[2],
								   double bL[2], 
								   double bInterval[2]) {
    double totalLength = -bInterval[1];
	// 道路右侧情况,x>0
	while (totalLength <= this->length) {
	    double x0 = (width / 2) + this->randomNum(margin);
	    double y0 = totalLength + this->randomNum(bInterval);
	    double z0 = this->randomNum(bH);
	    Point p0(x0, y0, z0);
        
		// 面
		double length = this->randomNum(bL);
		Surface s = this->surfaceProduce(p0, length, this->materials);
		s.init();
	    this->surfaces.push_back(s);

        // 刃形,p2p0,p1p3
		Point p1 = s.getP1();
		Point p2 = s.getP2();
		Point p3 = s.getP3();
        Point pb0(p0.x + BUILDING_WIDTH, p0.y, p0.z);
		Point pb1(p3.x + BUILDING_WIDTH, p3.y, p3.z);

		Edge e0(p2, p0, pb0, p3);
		Edge e1(p1, p3, pb1, p0);
		this->edges.push_back(e0);
		this->edges.push_back(e1);
		totalLength = y0 + length ;
	}
	// 道路左侧情况,x<0
	totalLength = -bInterval[1];
	while (totalLength <= this->length) {
	    double x0 = -((width / 2) + this->randomNum(margin));
	    double y0 = totalLength + this->randomNum(bInterval);
	    double z0 = this->randomNum(bH);
	    Point p0(x0, y0, z0);
        
		// 面
		double length = this->randomNum(bL);
		Surface s = this->surfaceProduce(p0, length, this->materials);
		s.init();
	    this->surfaces.push_back(s);

        // 刃形,p2p0,p1p3
		Point p1 = s.getP1();
		Point p2 = s.getP2();
		Point p3 = s.getP3();
        Point pb0(p0.x - BUILDING_WIDTH, p0.y, p0.z);
		Point pb1(p3.x - BUILDING_WIDTH, p3.y, p3.z);

		Edge e0(p2, p0, pb0, p3);
		Edge e1(p1, p3, pb1, p0);
		this->edges.push_back(e0);
		this->edges.push_back(e1);
		totalLength = y0 + length;
	}
}
void CTest_Phonebook1::testLargeChanges2()
{
  auto_ptr<phonebook> pb1(new (ELeave) phonebook(AppContext(), 0, 0));
  pb1->ConstructL();
  auto_ptr<CStopActive> stop(0);
  
  {
	RThread runner;
  	TestUtils::RunInSeparateThreadL(ChangeThread2, runner, TestUtils::ENoWaitForExit);
  	CleanupClosePushL(runner);
  	stop.reset( new (ELeave) CStopActive(runner) );
  	stop->ConstructL();
  	runner.Resume();
    
  	// first wait for the thread to finish its work
  	TestUtils::WaitForActiveSchedulerStopL(10);
  	CleanupStack::PopAndDestroy();
  }
  
  // then let the phonebook pick up the changes
  TestUtils::WaitForActiveSchedulerStopL(2);
  auto_ptr<phonebook> pb2(new (ELeave) phonebook(AppContext(), 0, 0));
  pb2->ConstructL();
  TS_ASSERT(TestEqualPhoneBooks(pb1.get(), pb2.get()));
}
void CTest_Phonebook1::testLargeChanges()
{
  auto_ptr<phonebook> pb1(new (ELeave) phonebook(AppContext(), 0, 0));
  pb1->ConstructL();
  auto_ptr<CStopActive> stop(0);
  
  {
	RThread runner;
  	TestUtils::RunInSeparateThreadL(ChangeThread, runner, TestUtils::ENoWaitForExit);
  	CleanupClosePushL(runner);
  	stop.reset( new (ELeave) CStopActive(runner) );
  	stop->ConstructL();
  	runner.Resume();
    
  	// first wait for the thread to finish its work
#ifdef __WINS__
  	TS_ASSERT(TestUtils::WaitForActiveSchedulerStopL(15));
#else
  	TS_ASSERT(TestUtils::WaitForActiveSchedulerStopL(45));
#endif
  	CleanupStack::PopAndDestroy();
  }
  
  // then let the phonebook pick up the changes
  TestUtils::WaitForActiveSchedulerStopL(4);
  auto_ptr<phonebook> pb2(new (ELeave) phonebook(AppContext(), 0, 0));
  pb2->ConstructL();
  TS_ASSERT_EQUALS(pb1->Count(), NO_OF_CONTACTS_NOT_DELETED);
  TS_ASSERT(TestEqualPhoneBooks(pb1.get(), pb2.get()));
}
示例#5
0
LAVar::LAVar( Enode * e_orig, Enode * e_var, const Real & v, bool revert )
{
  column_id = column_count++;
  row_id = -1;

  skip = false;

  // zero as default model
  m1 = new Delta( Delta::ZERO );
  m2 = new Delta( Delta::ZERO );
  model_local_counter = 0;

  Enode * e_null = NULL;
  LAVarBound pb1( &minus_inf_bound, e_null, false, false );
  LAVarBound pb2( &plus_inf_bound, e_null, true, false );
  all_bounds.push_back( pb1 );
  all_bounds.push_back( pb2 );
  u_bound = 1;
  l_bound = 0;

  e = e_var;

  // set original bounds from Enode
  setBounds( e_orig, v, revert );

}
示例#6
0
//
// Reads the type of the bounds from enode type
//
void LAVar::setBounds( Enode * e, const Real & v, bool revert )
{

  assert( e->isLeq( ) );

  Delta * bound = NULL;
  Delta * boundRev = NULL;

  Delta::deltaType bound_type = Delta::UPPER;

  bound = new Delta( v );

  if( revert )
  {
    boundRev = new Delta( v, 1 );
  }
  else
  {
    boundRev = new Delta( v, -1 );
    bound_type = Delta::LOWER;
  }

  assert( bound );
  assert( boundRev );
  assert( bound != boundRev );

  LAVarBound pb1( bound, e, ( bound_type == Delta::UPPER ), false );
  LAVarBound pb2( boundRev, e, ( bound_type != Delta::UPPER ), true );

  addBoundsAndUpdateSorting( pb1, pb2 );
}
示例#7
0
void CodeEditor::blacklistfuncSlot()
{
    QObject* pSender = sender();
    QString aux;
    QString pkt,time,repeat;
    bool fSucceeded;
    if(pSender == blacklistFunc->actions()[0])
    {
        QScopedPointer<QMessageBox> mb(new QMessageBox(this));
        QScopedPointer<QPushButton> pb1 (mb->addButton("Out", QMessageBox::ButtonRole::ActionRole));
        QScopedPointer<QPushButton> pb2 (mb->addButton("In", QMessageBox::ButtonRole::ActionRole));
        mb->setWindowTitle("Packet Type");
        mb->setText("Please select the packet type (In or Out).");
        mb->setIcon(QMessageBox::Icon::Information);
        mb->exec();
        bool type = (mb->clickedButton() == pb1.take() ? true : false);
        QString stype = type == type ? "In" : "Out";
        pkt = QInputDialog::getText(this, "Header", "Please enter a valid Header to block.");
        this->insertPlainText("BlackList.Block(\""+stype+"\",0x"+pkt+");");
    }

    if(pSender == blacklistFunc->actions()[1])
    {
        QScopedPointer<QMessageBox> mb(new QMessageBox(this));
        QScopedPointer<QPushButton> pb1 (mb->addButton("Out", QMessageBox::ButtonRole::ActionRole));
        QScopedPointer<QPushButton> pb2 (mb->addButton("In", QMessageBox::ButtonRole::ActionRole));
        mb->setWindowTitle("Packet Type");
        mb->setText("Please select the packet type (In or Out).");
        mb->setIcon(QMessageBox::Icon::Information);
        mb->exec();

        bool type = (mb->clickedButton() == pb1.take() ? true : false);
        QString stype = type == type ? "In" : "Out";


        pkt = QInputDialog::getText(this, "Header", "Please enter a valid Header to unblock.");


        this->insertPlainText("BlackList.UnBlock(\""+stype+"\",0x"+pkt+");");
    }

    if(pSender == blacklistFunc->actions()[2])
    {
        this->insertPlainText("BlackList.UnBlockAll();");
    }
}
示例#8
0
//
// Default constructor
//
LAVar::LAVar( Enode * e_orig = NULL )
{
  column_id = column_count++;
  row_id = -1;
  skip = false;

  // zero as default model
  m1 = new Delta( Delta::ZERO );
  m2 = new Delta( Delta::ZERO );
  model_local_counter = 0;

  Enode * e_null = NULL;
  LAVarBound pb1( &minus_inf_bound, e_null, false, false );
  LAVarBound pb2( &plus_inf_bound, e_null, true, false );
  all_bounds.push_back( pb1 );
  all_bounds.push_back( pb2 );
  u_bound = 1;
  l_bound = 0;

  e = e_orig;
}
示例#9
0
void CodeEditor::converterSlot()
{
    QObject* pSender = sender();
    QString aux, patt;
    QString pkt,time,repeat;
    bool fSucceeded;
    int offset;
    if(pSender == converterFunc->actions()[0])//ToHexString
    {
        patt = QInputDialog::getText(this, "Value", "Please enter the value you want to convert.");

        QScopedPointer<QMessageBox> mb(new QMessageBox(this));
        QScopedPointer<QPushButton> pb1 (mb->addButton("Byte", QMessageBox::ButtonRole::ActionRole));
        QScopedPointer<QPushButton> pb2 (mb->addButton("Word", QMessageBox::ButtonRole::ActionRole));
        QScopedPointer<QPushButton> pb3 (mb->addButton("Dword", QMessageBox::ButtonRole::ActionRole));
        mb->setWindowTitle("Output type");
        mb->setText("Please select the output type:");
        mb->setIcon(QMessageBox::Icon::Question);
        mb->exec();

        aux = mb->clickedButton()->text();

        this->insertPlainText("Converter.ToHexString("+patt+",\""+aux+"\");");
    }
    if(pSender == converterFunc->actions()[1])//ToMapleString
    {
        patt = QInputDialog::getText(this, "Text", "Please enter the text you want to convert.");
        this->insertPlainText("Converter.ToMapleString(\""+patt+"\");");
    }
    if(pSender == converterFunc->actions()[2])//ToLittleEndian"
    {
        patt = QInputDialog::getText(this, "Text", "Please enter the text you want to convert.");
        this->insertPlainText("Converter.ToLittleEndian(\""+patt+"\");");
    }
    if(pSender == converterFunc->actions()[3])//Format
    {
        patt = QInputDialog::getText(this, "Format", "Please enter the text you want to format.\nYou need to enter the arguments manually after this!");
        this->insertPlainText("Format(\""+patt+"\",/*Args Here*/);");
    }
}
示例#10
0
bool hitboxCollision(int a_x,int a_y,int a_width,int a_height,float a_angle,
              int b_x,int b_y,int b_width,int b_height,float b_angle)
{
    Point pa1(a_x,
              a_y);

    Point pa2(a_x + cos (a_angle*PI/180) * a_width
             ,a_y - sin (a_angle*PI/180) * a_width);

    Point pa3(a_x + cos (a_angle*PI/180) * a_width + sin (a_angle*PI/180) * a_height,
              a_y - sin (a_angle*PI/180) * a_width + cos (a_angle*PI/180) * a_height);

    Point pa4(a_x + sin (a_angle*PI/180) * a_height,
              a_y + cos (a_angle*PI/180) * a_height);


    Point pb1(b_x,
              b_y);

    Point pb2(b_x + cos (b_angle*PI/180) * b_width
             ,b_y - sin (b_angle*PI/180) * b_width);

    Point pb3(b_x + cos (b_angle*PI/180) * b_width + sin (b_angle*PI/180) * b_height,
              b_y - sin (b_angle*PI/180) * b_width + cos (b_angle*PI/180) * b_height);

    Point pb4(b_x + sin (b_angle*PI/180) * b_height,
              b_y + cos (b_angle*PI/180) * b_height);

    Line la1(pa1,pa2);
    Line la2(pa2,pa3);
    Line la3(pa3,pa4);
    Line la4(pa4,pa1);

    Line lb1(pb1,pb2);
    Line lb2(pb2,pb3);
    Line lb3(pb3,pb4);
    Line lb4(pb4,pb1);

    if(segmentIntersection(la1,lb1))
        return true;
    if(segmentIntersection(la1,lb2))
        return true;
    if(segmentIntersection(la1,lb3))
        return true;
    if(segmentIntersection(la1,lb4))
        return true;

    if(segmentIntersection(la2,lb1))
        return true;
    if(segmentIntersection(la2,lb2))
        return true;
    if(segmentIntersection(la2,lb3))
        return true;
    if(segmentIntersection(la2,lb4))
        return true;

    if(segmentIntersection(la3,lb1))
        return true;
    if(segmentIntersection(la3,lb2))
        return true;
    if(segmentIntersection(la3,lb3))
        return true;
    if(segmentIntersection(la3,lb4))
        return true;

    if(segmentIntersection(la4,lb1))
        return true;
    if(segmentIntersection(la4,lb2))
        return true;
    if(segmentIntersection(la4,lb3))
        return true;
    if(segmentIntersection(la4,lb4))
        return true;

    return false;


/*

    vector<Point*>intersections;
    intersections.push_back(lineIntersection(la1,lb1));
    intersections.push_back(lineIntersection(la1,lb2));
    intersections.push_back(lineIntersection(la1,lb3));
    intersections.push_back(lineIntersection(la1,lb4));

    intersections.push_back(lineIntersection(la2,lb1));
    intersections.push_back(lineIntersection(la2,lb2));
    intersections.push_back(lineIntersection(la2,lb3));
    intersections.push_back(lineIntersection(la2,lb4));

    intersections.push_back(lineIntersection(la3,lb1));
    intersections.push_back(lineIntersection(la3,lb2));
    intersections.push_back(lineIntersection(la3,lb3));
    intersections.push_back(lineIntersection(la3,lb4));

    intersections.push_back(lineIntersection(la4,lb1));
    intersections.push_back(lineIntersection(la4,lb2));
    intersections.push_back(lineIntersection(la4,lb3));
    intersections.push_back(lineIntersection(la4,lb4));


    int x_min=0;int x_max=0;
    int y_max=0;int y_min=0;

    if(a_width*a_height>b_width*b_height)
    {
        x_min = pa1.x;
        x_min=min(x_min,pa2.x);
        x_min=min(x_min,pa3.x);
        x_min=min(x_min,pa4.x);
        x_max = pa1.x;
        x_max=max(x_max,pa2.x);
        x_max=max(x_max,pa3.x);
        x_max=max(x_max,pa4.x);

        y_min = pa1.y;
        y_min=min(y_min,pa2.y);
        y_min=min(y_min,pa3.y);
        y_min=min(y_min,pa4.y);
        y_max = pa1.y;
        y_max=max(y_max,pa2.y);
        y_max=max(y_max,pa3.y);
        y_max=max(y_max,pa4.y);
    }else
    {
        x_min = pb1.x;
        x_min=min(x_min,pb2.x);
        x_min=min(x_min,pb3.x);
        x_min=min(x_min,pb4.x);
        x_max = pb1.x;
        x_max=max(x_max,pb2.x);
        x_max=max(x_max,pb3.x);
        x_max=max(x_max,pb4.x);

        y_min = pb1.y;
        y_min=min(y_min,pb2.y);
        y_min=min(y_min,pb3.y);
        y_min=min(y_min,pb4.y);
        y_max = pb1.y;
        y_max=max(y_max,pb2.y);
        y_max=max(y_max,pb3.y);
        y_max=max(y_max,pb4.y);
    }

    int cont=0;

    for(int i=0;i<(int)intersections.size();i++)
    {
        Point* point=intersections[i];
        if(point!=NULL)
        {
            if(point->x > x_min
               && point->x < x_max
               && point->y > y_min
               && point->y < y_max)
            {
                cont++;
            }
        }
    }

    vector<Point*>::iterator i;
    for ( i = intersections.begin() ; i < intersections.end(); i++ )
    {
        delete * i;
    }


    if(cont>=8)
        return true;
*/
    return false;
}
bool LocalErrorHistogramManager::buildHistograms(int numBins) {
    LINFO("Build histograms with " << numBins << " bins each");
    _numBins = numBins;

    _file = &(_tsp->file());
    if (!_file->is_open()) {
        return false;
    }
    _minBin = 0.0; // Should be calculated from tsp file
    _maxBin = 1.0; // Should be calculated from tsp file as (maxValue - minValue)

    unsigned int numOtLevels = _tsp->numOTLevels();
    unsigned int numOtLeaves = pow(8, numOtLevels - 1);
    unsigned int numBstLeaves = pow(2, _tsp->numBSTLevels() - 1);

    _numInnerNodes = _tsp->numTotalNodes() - numOtLeaves * numBstLeaves;

    _spatialHistograms = std::vector<Histogram>(_numInnerNodes);
    _temporalHistograms = std::vector<Histogram>(_numInnerNodes);
    for (unsigned int i = 0; i < _numInnerNodes; i++) {
        _spatialHistograms[i] = Histogram(_minBin, _maxBin, numBins);
        _temporalHistograms[i] = Histogram(_minBin, _maxBin, numBins);
    }

    // All TSP Leaves
    int numOtNodes = _tsp->numOTNodes();
    int otOffset = (pow(8, numOtLevels - 1) - 1) / 7;

    int numBstNodes = _tsp->numBSTNodes();
    int bstOffset = numBstNodes / 2;

    int numberOfLeaves = numOtLeaves * numBstLeaves;

    LINFO("Building spatial histograms");
    ProgressBar pb1(numberOfLeaves);
    int processedLeaves = 0;
    pb1.print(processedLeaves);
    bool success = true;
    for (int bst = bstOffset; bst < numBstNodes; bst++) {
        for (int ot = otOffset; ot < numOtNodes; ot++) {
            success &= buildFromOctreeChild(bst, ot);
            if (!success) LERROR("Failed in buildFromOctreeChild");
            if (!success) return false;
            pb1.print(processedLeaves++);
        }
    }
    //pb1.stop();


    LINFO("Building temporal histograms");
    ProgressBar pb2(numberOfLeaves);
    processedLeaves = 0;
    pb2.print(processedLeaves);
    for (int ot = otOffset; ot < numOtNodes; ot++) {
        for (int bst = bstOffset; bst < numBstNodes; bst++) {
            success &= buildFromBstChild(bst, ot);
            if (!success) LERROR("Failed in buildFromBstChild");
            if (!success) return false;
            pb2.print(processedLeaves++);
        }
    }
    //pb2.stop();

    return success;
}