/**funcion que valida numeros ingresados*/ void sudoku::correccionInGame(){ QTextEdit *numberTextTemp = ( QTextEdit *) sender(); int contador=0; long inputNumber = numberTextTemp->toPlainText().toLong(); if ((inputNumber>9 || inputNumber<1)&& inputNumber!=NULL){ QMessageBox::information(this, "Advertencia", "El numero ingresado no es valido esta fuera del rango"); numberTextTemp->setText(""); } for(int i = 0; i < 9; i++){ for(int j = 0; j < 9; j++){ if(getDisplayValue(i,j)!=0){ contador++; } if(contador==81){ on_comprobar_clicked(); } if(((getDisplayValue(i,j)!=0) && numbertext[i][j]->isEnabled())){ CorreccionFila(i,j); CorreccionColumna(i,j); CorreccionCuadrante(i,j); } } } }
QVariant LocalsTreeItem::data(int column, int role) const { switch (role) { case Qt::DisplayRole: switch (column) { case 0: return getDisplayName(); case 1: return getDisplayType(); case 2: return getDisplayValue(); default: break; } case Qt::ToolTipRole: switch (column) { case 0: return getDisplayName(); case 1: return getDisplayType(); case 2: return getDisplayValue(); default: break; } case Qt::BackgroundRole: return valueChanged() ? QColor(Qt::yellow) : QVariant(); default: break; } return QVariant(); }
/**funcion para hacer trampa comparar valores con la solucion y marcar los que no coincidan*/ void sudoku::on_verificar_clicked() { int k=0; QStringList valores; QString niveles = ui->textNivel->text(); k=0; if(niveles == "Juvenil") valores = plantilla1.split(","); if(niveles == "Profesional") valores = plantilla2.split(","); if(niveles == "Experto") valores = plantilla3.split(","); for(int i = 0; i < 9; i++){ for(int j = 0; j < 9; j++){ /**si coincide la respuesta se pintara verde sino coincide se pintara de rojo el cuadro*/ if((numbertext[i][j]->isEnabled()) && (getDisplayValue(i,j)!=0) && (getDisplayValue(i,j)!=valores[k].toLong())){ QPalette p = numbertext[i][j]->palette(); p.setColor(QPalette::Base, QColor(255, 150, 150)); numbertext[i][j]->setPalette(p); } if((numbertext[i][j]->isEnabled()) && (getDisplayValue(i,j)!=0) && (getDisplayValue(i,j)==valores[k].toLong())){ QPalette p = numbertext[i][j]->palette(); p.setColor(QPalette::Base, QColor(120, 255, 120)); numbertext[i][j]->setPalette(p); } k++; } } }
void sudoku::CorreccionFila(int i,int j){ /**validacion in game para filas*/ for(int k = 0; k < 9; k++){ if(k!=j){ if(getDisplayValue(i,j)==getDisplayValue(i,k)){ QPalette p = numbertext[i][j]->palette(); p.setColor(QPalette::Base, QColor(255, 150, 150)); numbertext[i][j]->setPalette(p); numbertext[i][k]->setPalette(p); QMessageBox::information(this, "Advertencia", "Este numero ya fue ingresado en la fila"); return; }else pintarTablero(); } } }
void sudoku::CorreccionCuadrante(int i,int j){ int despy=(i/3) *3; int despx=(j/3) *3; /**validacion in game para cuadrantes*/ for(int y = despy; y < despy+3; y++){ for(int x =despx ; x < despx+3; x++){ if(((y!=i) && (x!=j))){ if(getDisplayValue(i,j)==getDisplayValue(y,x)){ QPalette p = numbertext[i][j]->palette(); p.setColor(QPalette::Base, QColor(255, 150, 150)); numbertext[i][j]->setPalette(p); numbertext[y][x]->setPalette(p); QMessageBox::information(this, "Advertencia", "Este numero ya fue ingresado en el cuadrante"); return; }else pintarTablero(); } } } }
QVariant LocalsTreeItem::data(int column, int role) const { switch (role) { case Qt::DisplayRole: switch (column) { case 0: return getDisplayName(); case 1: return getDisplayType(); case 2: // display the string type with quotes. if (getDisplayType().compare(Helper::STRING) == 0) { return QString("\"%1\"").arg(getDisplayValue()); } else { return getDisplayValue(); } default: break; } case Qt::ToolTipRole: switch (column) { case 0: return getDisplayName(); case 1: return getDisplayType(); case 2: return getDisplayValue(); default: break; } case Qt::BackgroundRole: return valueChanged() ? QColor(Qt::yellow) : QVariant(); default: break; } return QVariant(); }
void LocalsTreeItem::setValue(QString value) { if (mpModelicaValue) { QString previousValue = mpModelicaValue->getValueString(); mpModelicaValue->setValue(value); setDisplayValue(mpModelicaValue->getValueString()); /* if value is changed then set the value changed flag. */ if (getDisplayValue().compare(previousValue) == 0) { setValueChanged(false); } else { setValueChanged(true); } } else if (isCoreType()) { mpModelicaValue = new ModelicaCoreValue(this); mpModelicaValue->setValue(value); setDisplayValue(mpModelicaValue->getValueString()); } else if (getDisplayType().startsWith(Helper::RECORD)) { mpModelicaValue = new ModelicaRecordValue(this); mpModelicaValue->setValue(value); setDisplayValue(mpModelicaValue->getValueString()); /* get the record elements size */ mpModelicaValue->retrieveChildrenSize(); } else if (getDisplayType().startsWith(Helper::LIST)) { mpModelicaValue = new ModelicaListValue(this); setDisplayValue(mpModelicaValue->getValueString()); /* get the list items size */ mpModelicaValue->retrieveChildrenSize(); } else if (getDisplayType().startsWith(Helper::OPTION)) { mpModelicaValue = new ModelicaOptionValue(this); setDisplayValue(mpModelicaValue->getValueString()); /* get the option item elements size */ mpModelicaValue->retrieveChildrenSize(); } else if (getDisplayType().startsWith(Helper::TUPLE)) { mpModelicaValue = new ModelicaTupleValue(this); setDisplayValue(mpModelicaValue->getValueString()); /* get the tuple elements size */ mpModelicaValue->retrieveChildrenSize(); } else if (getDisplayType().startsWith(Helper::ARRAY)) { mpModelicaValue = new MetaModelicaArrayValue(this); setDisplayValue(mpModelicaValue->getValueString()); /* get the tuple elements size */ mpModelicaValue->retrieveChildrenSize(); } /* invalidate the view so that the items show the updated values. */ mpLocalsTreeModel->getLocalsWidget()->getLocalsTreeProxyModel()->invalidate(); }
/**COMPRUEBA SI EL JUEGO ES CORRECTO*/ void sudoku::on_comprobar_clicked(){ long sumatoriah = 0; long productoh = 1; long sumatoriav = 0; long productov = 1; long sumatoriacuad = 0; long productocuad = 1; int despx=0,despy=0; int banderavalida=1; /**Validacion numeros del 1 al 9 en las filas*/ for(int i = 0;i < 9; i++){ sumatoriah=0; productoh=1; for(int j = 0; j < 9; j++){ sumatoriah+=getDisplayValue(i,j); productoh*=getDisplayValue(i,j); } if ((sumatoriah==45) && (productoh==362880)) banderavalida=1; else banderavalida=0,i=10;/**linea que rompe el ciclo en caso de no cumplir condicion*/ } /**Validacion numeros del 1 al 9 en las columnas*/ for(int j = 0;j < 9; j++){ sumatoriav=0; productov=1; for(int i = 0; i < 9; i++){ sumatoriav+=getDisplayValue(i,j); productov*=getDisplayValue(i,j); } if ((sumatoriav==45) && (productov==362880) ) banderavalida=1; else banderavalida=0,j=10;/**linea que rompe el ciclo en caso de no cumplir condicion*/ } for(int x = 0;x < 9; x++){ sumatoriacuad=0; productocuad=1; despy=(x/3) *3; despx=(x%3) *3; for(int i = 0;i < 3; i++){ for(int j = 0; j < 3; j++){ sumatoriacuad+=getDisplayValue(i+despy,j+despx); productocuad*=getDisplayValue(i+despy,j+despx); } } if ((sumatoriacuad==45) && (productocuad==362880) ) banderavalida=1; else banderavalida=0,x=10;/**linea que rompe el ciclo en caso de no cumplir condicion*/ } /**comprobacion de validacion en general*/ if (banderavalida==1) QMessageBox::information(this, "Respuesta", "La solucion es valida"); else QMessageBox::information(this, "Respuesta", "La solucion no es valida"); }
void Dictionary::mapToJSON(const PCF& pcf, Poco::JSON::Object::Ptr& json, bool alwaysCreate) const { std::vector<MQLONG> parameters = pcf.getParameters(); for(std::vector<MQLONG>::iterator it = parameters.begin(); it != parameters.end(); ++it) { std::string name = getName(*it); if ( name.empty() ) { if ( alwaysCreate ) { name = "id_" + Poco::NumberFormatter::format(*it); } else { continue; } } if ( json->has(name) ) continue; // Don't overwrite already added properties Poco::JSON::Object::Ptr field = new Poco::JSON::Object(); json->set(name, field); field->set("id", *it); if ( pcf.isNumber(*it) ) { MQLONG value = pcf.getParameterNum(*it); field->set("value", value); if ( hasDisplayMap(*it) ) { std::string displayValue = getDisplayValue(*it, value); if ( displayValue.empty() ) { displayValue = "Unknown value " + Poco::NumberFormatter::format(value) + " for " + Poco::NumberFormatter::format(*it); } field->set("display", displayValue); } } else if ( pcf.isString(*it) ) { field->set("value", pcf.getParameterString(*it)); } else if ( pcf.isNumberList(*it) ) { std::vector<MQLONG> values = pcf.getParameterNumList(*it); Poco::JSON::Array::Ptr jsonValues = new Poco::JSON::Array(); field->set("value", jsonValues); if ( hasDisplayMap(*it) ) { for(std::vector<MQLONG>::iterator vit = values.begin(); vit != values.end(); ++vit) { Poco::JSON::Object::Ptr jsonValueObject = new Poco::JSON::Object(); std::string displayValue = getDisplayValue(*it, *vit); if ( displayValue.empty() ) { displayValue = "Unknown value " + Poco::NumberFormatter::format(*vit) + " for " + Poco::NumberFormatter::format(*it); } jsonValueObject->set("value", *vit); jsonValueObject->set("display", displayValue); jsonValues->add(jsonValueObject); } } else { for(std::vector<MQLONG>::iterator vit = values.begin(); vit != values.end(); ++vit) { jsonValues->add(*vit); } } } else if ( pcf.isStringList(*it) ) { Poco::JSON::Array::Ptr jsonValues = new Poco::JSON::Array(); field->set("value", jsonValues); std::vector<std::string> strings = pcf.getParameterStringList(*it); for(std::vector<std::string>::iterator vit = strings.begin(); vit != strings.end(); ++vit) { jsonValues->add(*vit); } } else { poco_assert_dbg(false); } } }