Example #1
0
//--------------------------------------------------------------
void testApp::update(){
int loop = 0;
    while (loop < 1000){
        int randomRow = rand() % neighborhood.size();
        int randomCol = rand() % neighborhood[randomRow].size();
        //cout << "Row: " << randomRow << endl;
        //cout << "Col: " << randomCol << endl;
        int bestSwitchRow = 0;
        int bestSwitchCol = 0;
        for(int i=-1; i<=1; i++){
            for(int j=-1; j<=1; j++){
                //cout << "i: " << i << " j: " << j << endl;
                if(utility(randomRow, randomCol, bestSwitchRow, bestSwitchCol) < utility(randomRow, randomCol, i, j)){
                    //cout << "In if statement" << endl;
                    bestSwitchRow = i;
                    bestSwitchCol = j;
                }
                //cout << "Through if statement" << endl;
            }
        }
        if(bestSwitchRow == 0 && bestSwitchCol == 0){
            int randomRowDirection = (rand() % 3)-1;
            int randomColDirection = (rand() % 3)-1;
            switchType(randomRow, randomCol, randomRowDirection, randomColDirection);
        }else{
            switchType(randomRow, randomCol, bestSwitchRow, bestSwitchCol);
        }
        //cout << "Switched!" << endl;
        loop++;
    }
}
Example #2
0
void AbstractStageMenuWidget::dealPressed(QPointF mousePos,
        Qt::MouseButton button)
{
    if (button == Qt::RightButton)
    {
        emit giveControlTo(NULL, true);
        delete this;
        return;
    }

    for (int i = 0; i < stageCount; ++i)
    {
        if (!(stageItem[i]->getLocked()) &&
                stageItem[i]->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
        {
            emit giveControlTo(PuzzleGameInit::initRotatePuzzleGame(i, getType()), true);
            delete this;
            return;
        }
    }
    if (stageItem[stageCount]->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
    {
        emit giveControlTo(switchType(type), true);
        delete this;
        return;
    }
    else if (stageItem[stageCount + 1]->in(mousePos, LOGICAL_WIDTH, LOGICAL_HEIGHT))
    {
        emit giveControlTo(NULL, true);
        delete this;
        return;
    }
}
Example #3
0
Foam::Switch::switchType Foam::Switch::asEnum
(
    const std::string& str,
    const bool allowInvalid
)
{
    for (int sw = 0; sw < Switch::INVALID; sw++)
    {
        if (str == names[sw])
        {
            // convert n/y to no/yes (perhaps should deprecate y/n)
            if (sw == Switch::NO_1 || sw == Switch::NONE)
            {
                return Switch::NO;
            }
            else if (sw == Switch::YES_1)
            {
                return Switch::YES;
            }
            else
            {
                return switchType(sw);
            }
        }
    }

    if (!allowInvalid)
    {
        FatalErrorIn("Switch::asEnum(const std::string&)")
            << "unknown switch word " << str << nl
            << abort(FatalError);
    }

    return INVALID;
}
Example #4
0
Foam::Switch::switchType Foam::Switch::asEnum
(
    const std::string& str,
    const bool allowInvalid
)
{
    for (switchType sw=switchType::False; sw<switchType::invalid; ++sw)
    {
        if (str == names[toInt(sw)])
        {
            // Handle aliases
            switch (sw)
            {
                case switchType::n:
                case switchType::none:
                {
                    return switchType::no;
                    break;
                }

                case switchType::y:
                case switchType::any:
                {
                    return switchType::yes;
                    break;
                }

                case switchType::f:
                {
                    return switchType::False;
                    break;
                }

                case switchType::t:
                {
                    return switchType::True;
                    break;
                }

                default:
                {
                    return switchType(sw);
                    break;
                }
            }
        }
    }

    if (!allowInvalid)
    {
        FatalErrorInFunction
            << "unknown switch word " << str << nl
            << abort(FatalError);
    }

    return switchType::invalid;
}
Example #5
0
Foam::Switch::switchType Foam::Switch::asEnum
(
    const std::string& str,
    const bool allowInvalid
)
{
    for (int sw = 0; sw < Switch::INVALID; ++sw)
    {
        if (str == names[sw])
        {
            // handle aliases
            switch (sw)
            {
                case Switch::NO_1:
                case Switch::NONE:
                {
                    return Switch::NO;
                    break;
                }

                case Switch::YES_1:
                {
                    return Switch::YES;
                    break;
                }

                case Switch::FALSE_1:
                {
                    return Switch::FALSE;
                    break;
                }

                case Switch::TRUE_1:
                {
                    return Switch::TRUE;
                    break;
                }

                default:
                {
                    return switchType(sw);
                    break;
                }
            }
        }
    }

    if (!allowInvalid)
    {
        FatalErrorIn("Switch::asEnum(const std::string&, const bool)")
            << "unknown switch word " << str << nl
            << abort(FatalError);
    }

    return Switch::INVALID;
}
void KisHSVConfigWidget::setConfiguration(const KisPropertiesConfiguration * config)
{
    m_page->cmbType->setCurrentIndex(config->getInt("type", 1));
    m_page->hue->setValue(config->getInt("h", 0));
    m_page->saturation->setValue(config->getInt("s", 0));
    m_page->value->setValue(config->getInt("v", 0));
    m_page->chkColorize->setChecked(config->getBool("colorize", false));

    switchType(m_page->cmbType->currentIndex());
}
void KisHSVConfigWidget::switchColorize(bool toggle)
{
    if (toggle) {
        m_page->hue->setMinimum(0);
        m_page->hue->setMaximum(360);
        m_page->saturation->setMinimum(0);
        m_page->saturation->setMaximum(100);
        m_page->saturation->setValue(50);
        switchType(1);
    }
    else {
        m_page->hue->setMinimum(-180);
        m_page->hue->setMaximum(180);
        m_page->saturation->setMinimum(-100);
        m_page->saturation->setMaximum(100);

    }
    emit sigConfigurationItemChanged();
}