Пример #1
0
void solvingSudoku(field_t **field)
{
    if (settingValue(field, 0, 0)) {
        printf("No solution\n");
        exit(1);
    }
}
Пример #2
0
int settingValue(field_t **field, int x, int y)
{
    int number, nextX, nextY, isLastCell;
    ((x + 1) == NUM_OF_VALUES) ? (nextX = 0, nextY = y + 1) : (nextX = x + 1, nextY = y);
    (nextY == NUM_OF_VALUES) ? (isLastCell = 1) : (isLastCell = 0);

    if (field[y][x].isBasic) {
        if (isLastCell) {
            return 0;
        } else {
            if (settingValue(field, nextX , nextY)) {
                return 1;
            } else {
                return 0;
            }
        }
    }
    
    for (number = 1; number < (NUM_OF_VALUES + 1); number++) {
        if (checkCellSquare(field, x, y, number)) {
            continue;
        }
        if (checkCellX(field, x, y, number)) {
            continue;
        }
        if (checkCellY(field, x, y, number)) {
            continue;
        }
        field[y][x].cell = number;
        if (isLastCell) {
            return 0;
        } else {
            if (settingValue(field, nextX , nextY)) {
                field[y][x].cell = 0;
                continue;
            } else {
                return 0;
            }
        }
    }
    return 1;
}
Пример #3
0
// if the key is not found create one with a default value
QString CSMSettings::UserSettings::setting(const QString &viewKey, const QString &value)
{
    if(mSettingDefinitions->contains(viewKey))
        return settingValue(viewKey);
    else if(value != QString())
    {
        mSettingDefinitions->setValue (viewKey, QStringList() << value);
        return value;
    }

    return QString();
}