// Test that uniform_int<> can be used with std::random_shuffle
// Author: Jos Hickson
void test_random_shuffle()
{
    typedef boost::uniform_int<> distribution_type;
    typedef boost::variate_generator<boost::mt19937 &, distribution_type> generator_type;

    boost::mt19937 engine1(1234);
    boost::mt19937 engine2(1234);

    rand_for_random_shuffle<boost::mt19937> referenceRand(engine1);

    distribution_type dist(0,10);
    generator_type testRand(engine2, dist);

    std::vector<int> referenceVec;

    for (int i = 0; i < 200; ++i)
    {
      referenceVec.push_back(i);
    }

    std::vector<int> testVec(referenceVec);

    std::random_shuffle(referenceVec.begin(), referenceVec.end(), referenceRand);
    std::random_shuffle(testVec.begin(), testVec.end(), testRand);

    typedef std::vector<int>::iterator iter_type;
    iter_type theEnd(referenceVec.end());

    for (iter_type referenceIter(referenceVec.begin()), testIter(testVec.begin());
         referenceIter != theEnd;
         ++referenceIter, ++testIter)
    {
      BOOST_CHECK_EQUAL(*referenceIter, *testIter);
    }
}
예제 #2
0
void Task::init()
{
  L_FUNC("");

  L_INFO("+++ test Logger");
  L_FATAL("L_FATAL");
  L_ERROR("L_ERROR");
  L_WARN("L_WARN");
  L_INFO("L_INFO");
  L_DEBUG("L_DEBUG");
  L_INFO("--- test Logger");

  L_INFO(QString()); // --> "?"
  L_INFO(" \n Trimmed \n\n"); // --> whitespace removed from start and end
  L_INFO("UTF-8 Unicode text: äöü àéè");

  QString formattedOutput1 = "JSON output 1:\n"
    "{\n"
    "  \"firstName\": \"Mario\",\n"
    "  \"age\": 44\n"
    "}"
  ;
  L_INFO(formattedOutput1);

  QString formattedOutput2 = "{<br>  \"firstName\": \"Mario\",<br>  \"age\": 44<br>}";
  L_INFO(formattedOutput2.prepend("JSON output 2:<br>").replace("<br>", "\n"));

  QTimer::singleShot(1000, this, SLOT(slotRun()));
  QTimer::singleShot(1000, this, SLOT(slotRun()));
  QTimer::singleShot(3000, this, SLOT(slotRun()));
  QTimer::singleShot(6000, this, SLOT(theEnd()));
}
예제 #3
0
void MainWindow::generateGame(int level)
{
	if (gameBoard != NULL)
		delete gameBoard;
	
	gameBoard = new Board(level);
	generateBoard();
	connect(gameBoard, SIGNAL(theEnd()), this, SLOT(gameFinished()));
	counter->setText("Number of moves: " + QString::number(gameBoard->previousMoves.size()));
}
예제 #4
0
void trim( std::string& s )
{
    while ( s.begin() != s.end() && isSpace( * (s.begin()) ) )
    {
        s.erase( s.begin() );
    }

    std::string::reverse_iterator   theEnd  ( s.rbegin() ), 
                                    theStart( s.rend()   ),
                                    lastNonWhitespaceChar;

    lastNonWhitespaceChar = std::find_if( theEnd, theStart, notSpace );

    int offTheEnd = std::distance( theEnd, lastNonWhitespaceChar );

    s.resize( s.size() - offTheEnd );
}
예제 #5
0
Textes::Textes() {
    int currentIndex;
    char *currentPosInTextes;
    int textCounter;
    int stringIndex;
    char *stringPtr;
    int textLength;

    _tabTextes = new textEntryStruct[NUM_MAX_TEXT_ENTRY]; // 2000 = 250 * 8

    ASSERT_PTR(_tabTextes);

    if(!_tabTextes) {
        theEnd(1, "TabTextes");
    }

    // setup languageNameString
    if(g_fitd->getGameType() == GType_AITD3) {
        strcpy(languageNameString, "TEXTES");
    } else {
        int i = 0;

        while(languageNameTable[i]) {
            char tempString[20];

            strcpy(tempString, languageNameTable[i]);
            strcat(tempString, ".PAK");

            if(g_resourceLoader->getFileExists(tempString)) {
                strcpy(languageNameString, languageNameTable[i]);
                break;
            }

            i++;
        }
    }

    if(!languageNameString[0]) {
        error("Unable to detect language file..\n");
    }

    char *systemTextes = g_resourceLoader->loadPakSafe(languageNameString, 0); // todo: use real language name
    textLength = getPakSize(languageNameString, 0);

    for(currentIndex = 0; currentIndex < NUM_MAX_TEXT_ENTRY; currentIndex++) {
        _tabTextes[currentIndex].index = -1;
        _tabTextes[currentIndex].textPtr = NULL;
        _tabTextes[currentIndex].width = 0;
    }

    currentPosInTextes = systemTextes;

    textCounter = 0;

    while(currentPosInTextes < systemTextes + textLength) {
        currentIndex = *(currentPosInTextes++);

        if(currentIndex == 26)
            break;

        if(currentIndex == '@') { // start of string marker
            stringIndex = 0;

            while((currentIndex = *(currentPosInTextes++)) >= '0' && currentIndex <= '9') { // parse string number
                stringIndex = stringIndex * 10 + currentIndex - 48;
            }

            if(currentIndex == ':') { // start of string
                stringPtr = currentPosInTextes;

                do {
                    currentPosInTextes ++;
                } while((unsigned char)*(currentPosInTextes - 1) >= ' '); // detect the end of the string

                *(currentPosInTextes - 1) = 0; // add the end of string

                _tabTextes[textCounter].index = stringIndex;
                _tabTextes[textCounter].textPtr = stringPtr;
                _tabTextes[textCounter].width = computeStringWidth(stringPtr);

                textCounter++;
            }

            if(currentIndex == 26) {
                return;
            }
        }
    }
}
예제 #6
0
void MainWidget::check()
{

    //    qDebug() << "check";
    isEmitter = false;
    TGbutton *button = (TGbutton*)sender();
    if (button->curState != TGbutton::First)
        return;

    if (isNewGame == false)
    {
        isNewGame = true;
        emit newGame();
    }
    cur++;
    if(cur == all)
    {        
        type = true;
        for (int i=0; i < row; i++)
        {
            for(int j=0;j<col;j++)
            {
                if (fields[i][j].curState == TGbutton::First)
                {
                    if (mat[i][j]==-1)
                        fields[i][j].setIcon(QIcon(":/bomb.png"));
                    else
                        fields[i][j].click();
                }
                else if (fields[i][j].curState == TGbutton::Flag && mat[i][j] != -1)
                {
                    type = false;
                    QPalette pal = fields[i][j].palette();
                    pal.setColor(QPalette::Button,QColor(249,123,126,128));
                    fields[i][j].setPalette(pal);
                }
            }
        }

        emit progress(100);

        QTimer::singleShot(1,this,SLOT(theEnd()));
        return;
    }
    int a,b;
    button->GetAB(a,b);
    qDebug() << "click" << a << b;

    if (isNotSend == false)
    {
        isEmitter = true;
        emit sendClient("CLICK", a, b);
    }


    presses << "CLICK";
    QPair <int,int> pair;
    pair.first = a;
    pair.second = b;
    pressBut << pair;

    QColor color;
    if(mat[a][b] == -1)
    {
        type = false;

        for (int i=0; i < row; i++)
        {
            for(int j=0;j<col;j++)
            {

                if(mat[i][j] == -1 && fields[i][j].curState == TGbutton::First)
                    fields[i][j].setIcon(QIcon(":/bomb.png"));
                else if ((mat[i][j] == -1 && fields[i][j].curState != TGbutton::Flag) ||
                         (mat[i][j] != -1 && fields[i][j].curState == TGbutton::Flag))
                {
                    QPalette pal = fields[i][j].palette();
                    pal.setColor(QPalette::Button,QColor(249,123,126,128));
                    fields[i][j].setPalette(pal);
                }
            }
        }

        QTimer::singleShot(100,this,SLOT(theEnd()));
        return;
    }
    else if(mat[a][b] == 1)
        color.setRgb(50,205,80,255);
    else if(mat[a][b] == 2)
        color.setRgb(220,160,40,255);
    else if(mat[a][b] == 0)
        color.setRgb(0,0,0,255);
    else
        color.setRgb(255,0,0,255);

    button->curState = TGbutton::Click;

    QFont font("Sans",10,10,false);
    button->setFont(font);
    button->setMaximumWidth(button->width());
    QPalette p=button->palette();
    p.setColor(QPalette::ButtonText,color);
    p.setColor(QPalette::Button,QColor(182,214,220,128));
    button->setPalette(p);       
    if (mat[a][b] != 0)
        button->setText(QString::number(mat[a][b]));
    else
        clickRound(a,b);    

    isNotSend = false;
    emit progress((int)(((float)cur/(float)all)*100));
}