| 1 | /*********************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2010-2017 Innocent De Marchi <[email protected]> |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | ***********************************************************************/ |
| 19 | //#include <QAction> |
| 20 | #include <QApplication> |
| 21 | //#include <QtGui> |
| 22 | //#include <QtCore> |
| 23 | #include <QtWidgets/QMessageBox> |
| 24 | #include <QtWidgets/QStatusBar> |
| 25 | #include <QtWidgets/QMenuBar> |
| 26 | #include <QtWidgets/QProgressDialog> |
| 27 | |
| 28 | #include "frmprincipal.h" |
| 29 | #include "constants.h" |
| 30 | #include "funcions.h" |
| 31 | #include "moviment.h" |
| 32 | |
| 33 | /* |
| 34 | * Per actualitzar les cadenes de traducció |
| 35 | * lupdate -verbose peg-solitaire.pro |
| 36 | * al terminal |
| 37 | */ |
| 38 | |
| 39 | extern QTranslator *qt_translator; |
| 40 | extern QTranslator *appTranslator; |
| 41 | |
| 42 | const int numeroLiniesDadesJoc=4; |
| 43 | |
| 44 | const int alcadaMenuBarraTasques=60; |
| 45 | |
| 46 | QString localePrograma; |
| 47 | |
| 48 | int jocResolt; |
| 49 | |
| 50 | //Contador dels intents de trobar una solució |
| 51 | //Evita els casos en què no es troba la solució |
| 52 | //d'un problema que en té |
| 53 | int intentsSolucio=0; |
| 54 | /* Controla si s'està cercant una solució a partir |
| 55 | * d'uns moviments inicials ja fets*/ |
| 56 | bool cercaSolucioAPartirDeMovimentsInicials=false; |
| 57 | |
| 58 | |
| 59 | /**************************************** |
| 60 | * |
| 61 | *16/12/10: canviat el sistema per mostrar les |
| 62 | * marques personals (void veureRecordsPersonals()) |
| 63 | * Ara es fa amb un diàleg per evitar els problemes |
| 64 | * de la finestra flotant. |
| 65 | * |
| 66 | *16/12/10: canviat el sistema per mostrar les |
| 67 | *solucions. Ara es fa a un Tab i s'ha eliminat |
| 68 | *l'opció de menú |
| 69 | *****************************************/ |
| 70 | |
| 71 | |
| 72 | frmPrincipal::frmPrincipal() |
| 73 | { |
| 74 | localePrograma=QLocale::system().name(); |
| 75 | qsrand(QTime::currentTime().msec()); |
| 76 | //jocResolt=false; |
| 77 | |
| 78 | setWindowIcon(QIcon(":/peg-solitaire.png")); |
| 79 | setWindowTitle( tr("Solitari")); |
| 80 | setMinimumSize (QSize(600,330+alcadaMenuBarraTasques)); |
| 81 | this->move(300,100); |
| 82 | //Recuperam les dimensions del formulari |
| 83 | restoreGeometry(QSettings().value(QString("General/geometry")).toByteArray()); |
| 84 | |
| 85 | jocFram=new QFrame(this); |
| 86 | jocFram->setGeometry(0,alcadaMenuBarraTasques,300,300); |
| 87 | jocFram->setFrameStyle(QFrame::WinPanel | QFrame::Raised); |
| 88 | jocFram->setMinimumSize(QSize(300,300)); |
| 89 | |
| 90 | //rellotge |
| 91 | rellotgeLabel = new Rellotge(jocFram); |
| 92 | rellotgeLabel->setMinimumSize(QSize(300,10)); |
| 93 | rellotgeLabel->move(QPoint(0,10)); |
| 94 | rellotgeLabel->setAlignment(Qt::AlignHCenter); |
| 95 | rellotgeLabel->estableixTemps("00:00:00"); |
| 96 | |
| 97 | |
| 98 | |
| 99 | //Tabs |
| 100 | tabArbres= new QTabWidget(jocFram); |
| 101 | tabArbres->setMinimumSize(QSize(290,250)); |
| 102 | tabArbres->move(QPoint(0,50)); |
| 103 | connect(tabArbres,SIGNAL(currentChanged(int)), |
| 104 | this,SLOT(canviTabSeleccionat( int))); |
| 105 | //arbre dels jocs |
| 106 | arbreModalitatsJocTreeWidget= new QTreeWidget(jocFram); |
| 107 | arbreModalitatsJocTreeWidget->setMinimumSize(QSize(280,210)); |
| 108 | // arbreModalitatsJocTreeWidget->move(QPoint(0,70)); |
| 109 | arbreModalitatsJocTreeWidget->expandAll(); |
| 110 | // connect(arbreModalitatsJocTreeWidget,SIGNAL(itemClicked(QTreeWidgetItem*, int)), |
| 111 | // this,SLOT(seleccioModalitatJoc(QTreeWidgetItem*, int))); |
| 112 | connect(arbreModalitatsJocTreeWidget,SIGNAL(itemSelectionChanged()), |
| 113 | this,SLOT(seleccioModalitatJoc())); |
| 114 | connect(arbreModalitatsJocTreeWidget, SIGNAL(itemClicked ( QTreeWidgetItem *, int)), |
| 115 | this, SLOT(seleccioModalitatJoc())); |
| 116 | connect(arbreModalitatsJocTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), |
| 117 | this, SLOT(canviItemArbreJoc(QTreeWidgetItem*,QTreeWidgetItem*))); |
| 118 | connect(arbreModalitatsJocTreeWidget, SIGNAL(itemDoubleClicked ( QTreeWidgetItem*, int)), |
| 119 | this, SLOT(dobleClickArbreJoc(QTreeWidgetItem*, int))); |
| 120 | |
| 121 | //S'afegeix a un tab |
| 122 | tabArbres->addTab(arbreModalitatsJocTreeWidget,""); |
| 123 | tabArbres->setTabToolTip(0,tr("Modalitats del joc")); |
| 124 | tabArbres->setTabIcon(0, |
| 125 | QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/peg-solitaire.png")); |
| 126 | |
| 127 | //Visualitzador de solucions |
| 128 | arbreSolucionsTreeWidget= new QTreeWidget(this); |
| 129 | arbreSolucionsTreeWidget->setMinimumSize(QSize(280,220)); |
| 130 | arbreSolucionsTreeWidget->setColumnCount(2) ; |
| 131 | arbreSolucionsTreeWidget->setColumnHidden(1,true); |
| 132 | connect(arbreSolucionsTreeWidget,SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), |
| 133 | this,SLOT(carregaSolucio(QTreeWidgetItem*, int))); |
| 134 | /* |
| 135 | solucionsDockWidget = new QDockWidget(tr("Solucions")); |
| 136 | solucionsDockWidget->setWidget(arbreSolucionsTreeWidget); |
| 137 | */ |
| 138 | //S'afegeix a un tab |
| 139 | tabArbres->addTab(arbreSolucionsTreeWidget, ""); |
| 140 | tabArbres->setTabToolTip(1,tr("Solucions")); |
| 141 | tabArbres->setTabIcon(1, |
| 142 | QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/soluciona.png")); |
| 143 | |
| 144 | |
| 145 | arbreModalitatsJocPersonalitzatsTreeWidget= new QTreeWidget(jocFram); |
| 146 | arbreModalitatsJocPersonalitzatsTreeWidget->setMinimumSize(QSize(280,210)); |
| 147 | arbreModalitatsJocPersonalitzatsTreeWidget->expandAll(); |
| 148 | connect(arbreModalitatsJocPersonalitzatsTreeWidget, |
| 149 | SIGNAL(itemSelectionChanged()),this,SLOT(seleccioModalitatJocPersonalitzat())); |
| 150 | connect(arbreModalitatsJocPersonalitzatsTreeWidget, SIGNAL(itemClicked ( QTreeWidgetItem *, int)), |
| 151 | this, SLOT(seleccioModalitatJocPersonalitzat())); |
| 152 | //S'afegeix a un tab |
| 153 | tabArbres->addTab(arbreModalitatsJocPersonalitzatsTreeWidget,""); |
| 154 | tabArbres->setTabToolTip(2,tr("Jocs personalitzats")); |
| 155 | tabArbres->setTabIcon(2, |
| 156 | QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/peg-solitaire-per.png")); |
| 157 | |
| 158 | |
| 159 | |
| 160 | movimentsUndoStack = new QUndoStack(this); |
| 161 | taulerJoc= new Tauler (movimentsUndoStack,rellotgeLabel,this,this); |
| 162 | /* 26/12/12 S'ha afegit el +8 per evitar que les fitxes |
| 163 | * s'aferrin als marges |
| 164 | */ |
| 165 | taulerJoc->move(QPoint(300,alcadaMenuBarraTasques+8)); |
| 166 | |
| 167 | //Rellotge per a les eleccions a l'atzar |
| 168 | /* 21/08/16 Eliminada la següent linia: |
| 169 | * l'objecte ja està declarat a .h |
| 170 | * S'ha afegit la llavors a tots els qrand |
| 171 | * (llevat dels de la generació de jocs a l'atzar) |
| 172 | */ |
| 173 | //QTime rellotgeQTime (0,0,0); |
| 174 | rellotgeQTime.currentTime(); |
| 175 | rellotgeQTime.start(); |
| 176 | qsrand((QTime::currentTime().msecsSinceStartOfDay())); |
| 177 | |
| 178 | comprovaDirectoriHome(); |
| 179 | actualitzaCodisArxiusDeSolucio(); |
| 180 | //inicialment, el tipus de joc serà del programa |
| 181 | tipusJocActual=0; |
| 182 | creaAcccions(); |
| 183 | creaMenus(); |
| 184 | creaBarraTasques(); |
| 185 | |
| 186 | /* 19/01/13 Incorporat al procediment |
| 187 | * de càrrega dels jocs |
| 188 | */ |
| 189 | //llegeixArxiuData(); |
| 190 | /* 17/08/16 |
| 191 | * Eliminats degut a què ja estan a tradueixGUI() i |
| 192 | * s'executaven dues vegades |
| 193 | */ |
| 194 | // carregaArbreModalitatsJoc(); |
| 195 | setArbreJocsActual(0); |
| 196 | //carregaArbreModalitatsJocPersonalitzats(); |
| 197 | /* 18/01/11 |
| 198 | Eliminat (a Debian) per considerar-ho contrari a les |
| 199 | "llibertats" |
| 200 | */ |
| 201 | comprovaRegistre(); |
| 202 | } |
| 203 | |
| 204 | |
| 205 | /* |
| 206 | Carrega el contingut de l'arxiu data.sol a la |
| 207 | llista dadesArxiuData |
| 208 | */ |
| 209 | void frmPrincipal::llegeixArxiuData(){ |
| 210 | //obrim l'arxiu de jocs |
| 211 | QString nomArxiu=directoriLinux()+DIRECTORI_ARXIU_GAMES_SOL; |
| 212 | QFile arxiuData(nomArxiu); |
| 213 | if (!arxiuData.open(QIODevice::ReadOnly | QIODevice::Text)){ |
| 214 | QMessageBox::critical(this, tr("Solitari"), |
| 215 | QString(tr("No s'ha trobat l'arxiu %1")).arg(nomArxiu) ); |
| 216 | return ; |
| 217 | } |
| 218 | QTextStream entrada(&arxiuData); |
| 219 | QString linia0 = entrada.readLine(); |
| 220 | dadesArxiuData.clear(); |
| 221 | while (!linia0.isNull()) { |
| 222 | if ( ! (linia0.mid(0,1)=="#") ){ |
| 223 | dadesArxiuData.append(linia0); //tipus de joc |
| 224 | for(int dades=0 ; dades<numeroLiniesDadesJoc-1;++dades){ |
| 225 | dadesArxiuData.append(entrada.readLine()); |
| 226 | } |
| 227 | } |
| 228 | linia0 = entrada.readLine(); |
| 229 | } //final del while de la lectura de l'arxiu |
| 230 | } |
| 231 | |
| 232 | void frmPrincipal::carregaArbreModalitatsJoc(){ |
| 233 | |
| 234 | QApplication::setOverrideCursor(Qt::WaitCursor); |
| 235 | /* 19/01/13 Amb els joc personalitzats, ara això és |
| 236 | * impresindible per actualitzar les dades dels jocs |
| 237 | */ |
| 238 | llegeixArxiuData(); |
| 239 | if (dadesArxiuData.size()>0){ |
| 240 | //netejam |
| 241 | arbreModalitatsJocTreeWidget->clear(); |
| 242 | arbreModalitatsJocTreeWidget->setColumnCount(numeroLiniesDadesJoc+1); |
| 243 | //Codi del joc, tipus de moviment |
| 244 | arbreModalitatsJocTreeWidget->setColumnHidden(1,true); |
| 245 | //files i columnes |
| 246 | arbreModalitatsJocTreeWidget->setColumnHidden(2,true); |
| 247 | //dades de les fitxes |
| 248 | arbreModalitatsJocTreeWidget->setColumnHidden(3,true); |
| 249 | //Codi de la cadena amb el nom del solitari |
| 250 | arbreModalitatsJocTreeWidget->setColumnHidden(4,true); |
| 251 | |
| 252 | //posam la capçalera de l'arbre |
| 253 | QTreeWidgetItem *item=new QTreeWidgetItem(); |
| 254 | //07/01/12 Això no serveix per res! |
| 255 | //item->setIcon(0,QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/hi_q.png")); |
| 256 | // item->setText(0,tr(nomModalitatsJoc[0])); |
| 257 | item->setText(0,nomDelJoc(0)); |
| 258 | arbreModalitatsJocTreeWidget->setHeaderItem(item); |
| 259 | |
| 260 | //Això per controlar la numeració dels jocs que tenen |
| 261 | //la mateixa cadena de nom |
| 262 | QSettings *controlArxiu; |
| 263 | controlArxiu=new QSettings( |
| 264 | QSettings::IniFormat, |
| 265 | QSettings::UserScope,"De Marchi", "nomsSol"); |
| 266 | controlArxiu->clear(); |
| 267 | int numSolMateixNom; |
| 268 | |
| 269 | QList<QTreeWidgetItem *> itemsArbre; |
| 270 | for(int llista=0 ; llista<dadesArxiuData.size()/numeroLiniesDadesJoc;++llista){ |
| 271 | QTreeWidgetItem *item=new QTreeWidgetItem(); |
| 272 | |
| 273 | /* QString nomJoc=(tr(nomModalitatsJoc[ |
| 274 | dadesArxiuData.value( |
| 275 | llista*numeroLiniesDadesJoc+3).toInt()]));*/ |
| 276 | |
| 277 | |
| 278 | QStringList codi=dadesArxiuData.value(llista*numeroLiniesDadesJoc).split(" "); |
| 279 | QString nomJoc=nomDelJoc( |
| 280 | dadesArxiuData.value( |
| 281 | llista*numeroLiniesDadesJoc+3))+ |
| 282 | afageixTipusMovimentNomJoc(QString(" %1 ").arg(codi.value(1))); |
| 283 | |
| 284 | numSolMateixNom=controlArxiu->value(nomJoc,"1").toInt(); |
| 285 | QString cadenaNomNumero; |
| 286 | cadenaNomNumero=QString::number(numSolMateixNom); |
| 287 | while (cadenaNomNumero.length()<3){cadenaNomNumero=" "+cadenaNomNumero;} |
| 288 | //Comprovam si és una modalitat amb final marcat |
| 289 | //per afegir un * al nom |
| 290 | //12/01/13 Nova funció |
| 291 | //if( (dadesArxiuData.value(llista*numeroLiniesDadesJoc+2).contains("11")) |
| 292 | // ||(dadesArxiuData.value(llista*numeroLiniesDadesJoc+2).contains("10")) ){ |
| 293 | if(esSolitariAmbFinalMarcat( |
| 294 | dadesArxiuData.value(llista*numeroLiniesDadesJoc+2))){ |
| 295 | cadenaNomNumero=cadenaNomNumero+" *" ; |
| 296 | } |
| 297 | // cadenaNomNumero=cadenaNomNumero+" ("+codi.value(0)+")"; |
| 298 | /* 16/01/13 Nova funció que retorna el nom |
| 299 | * del tipus de moviment (diagonal/invers) per |
| 300 | * simplificar les cadenes de traducció |
| 301 | */ |
| 302 | item->setText(0,nomJoc+cadenaNomNumero); |
| 303 | item->setToolTip(0,item->text(0)); |
| 304 | //linea 0: codi joc, tipus moviment |
| 305 | item->setText(1,dadesArxiuData.value(llista*numeroLiniesDadesJoc)); |
| 306 | //linea 1: files i columnes |
| 307 | item->setText(2,dadesArxiuData.value(llista*numeroLiniesDadesJoc+1)); |
| 308 | //linea 2: estat de les fitxes |
| 309 | if(solitariPersonalitzat_esPersonalitzat(dadesArxiuData.value(llista*numeroLiniesDadesJoc))){ |
| 310 | QString dadesFitxes; |
| 311 | while(dadesFitxes.length()<144*2){ |
| 312 | dadesFitxes=dadesFitxes+"6 "; |
| 313 | } |
| 314 | dadesFitxes.simplified(); |
| 315 | item->setText(3,dadesFitxes); |
| 316 | } |
| 317 | else item->setText(3,dadesArxiuData.value(llista*numeroLiniesDadesJoc+2)); |
| 318 | //Codi del nom del solitari |
| 319 | item->setText(4,dadesArxiuData.value( |
| 320 | llista*numeroLiniesDadesJoc+3) ); |
| 321 | //posam l'icone OK si hi ha un rècord |
| 322 | item->setIcon(0,QIcon(posaIconeOK(codi.value(0)))); |
| 323 | |
| 324 | // item->setText(4,dadesArxiuData.value(llista*numeroLiniesDadesJoc+3)); |
| 325 | numSolMateixNom++; |
| 326 | controlArxiu->setValue(nomJoc,numSolMateixNom++); |
| 327 | itemsArbre.append(item); |
| 328 | } |
| 329 | arbreModalitatsJocTreeWidget->insertTopLevelItems(0,itemsArbre); |
| 330 | arbreModalitatsJocTreeWidget->expandAll(); |
| 331 | arbreModalitatsJocTreeWidget->sortItems(0,Qt::AscendingOrder); |
| 332 | //Seleccionam el darrer joc jugat en tancar el programa |
| 333 | QSettings tipusJoc; |
| 334 | bool trobat=false; |
| 335 | int modalidadJoc=tipusJoc.value( QString("General/modalidadJoc"),1).toInt(); |
| 336 | for(int i=0 ; i<arbreModalitatsJocTreeWidget->topLevelItemCount();++i){ |
| 337 | QStringList modJoc= arbreModalitatsJocTreeWidget->topLevelItem(i)->text(1).split(" "); |
| 338 | if (modJoc.value(0).toInt()==modalidadJoc){ |
| 339 | arbreModalitatsJocTreeWidget->topLevelItem(i)->setSelected(true); |
| 340 | //Aquesta linia posa en marxa la càrrega de les solucions a l'arbre de solucions |
| 341 | arbreModalitatsJocTreeWidget->setCurrentItem(arbreModalitatsJocTreeWidget->topLevelItem(i)); |
| 342 | trobat=true; |
| 343 | break; |
| 344 | } |
| 345 | } |
| 346 | if ((! trobat) && ( arbreModalitatsJocTreeWidget->topLevelItemCount()>0)) { |
| 347 | arbreModalitatsJocTreeWidget->topLevelItem(0)->setSelected(true); |
| 348 | tipusJocActual=0; |
| 349 | arbreModalitatsJocTreeWidget->setCurrentItem(arbreModalitatsJocTreeWidget->topLevelItem(0)); |
| 350 | } |
| 351 | item->setText(0,item->text(0)+" ("+QString::number( |
| 352 | arbreModalitatsJocTreeWidget->topLevelItemCount()) +")"); |
| 353 | } |
| 354 | QApplication::setOverrideCursor(Qt::ArrowCursor); |
| 355 | } |
| 356 | |
| 357 | /* Gestiona a quin arbre de jocs |
| 358 | * (del programa o personalitzats) |
| 359 | * cal seleccionar |
| 360 | */ |
| 361 | void frmPrincipal::gestioTipusDeJocASeleccionar(){ |
| 362 | solucionsTrobades.clear(); |
| 363 | switch (tipusJocActual) { |
| 364 | case 0: //joc del programa |
| 365 | seleccioModalitatJoc(); |
| 366 | break; |
| 367 | case 1: //joc personalitzat |
| 368 | //primer eliminan els arxius .sol i .txt de joc anterior |
| 369 | //solitariPersonalitzat_eliminaArxiuSolucio(); |
| 370 | seleccioModalitatJocPersonalitzat(); |
| 371 | break; |
| 372 | } |
| 373 | |
| 374 | } |
| 375 | |
| 376 | /* |
| 377 | Gestiona la selecció de la modalitat de joc |
| 378 | quan es clica sobre l'arbre de modalitats |
| 379 | */ |
| 380 | void frmPrincipal::seleccioModalitatJoc(){ |
| 381 | statusBar()->clearMessage(); |
| 382 | /*Necessari per controlar les solucions distintes*/ |
| 383 | retrocedeixMoviment=0; |
| 384 | if (arbreModalitatsJocTreeWidget->selectedItems().count()==1){ |
| 385 | QTreeWidgetItem *item; |
| 386 | item=arbreModalitatsJocTreeWidget->selectedItems().first(); |
| 387 | //No s'ha clicat el nus arrel |
| 388 | if (item->childCount()==0){ |
| 389 | movimentsUndoStack->clear(); |
| 390 | iniciSolucioAction->setEnabled(movimentsUndoStack->canUndo()); |
| 391 | //Reinciam el número d'intents de trobar |
| 392 | //la solució |
| 393 | intentsSolucio=0; |
| 394 | jocResolt=0; |
| 395 | /* Tractament de la modalitat |
| 396 | * generació a l'atzar |
| 397 | */ |
| 398 | if(item->text(3).length()==1){ |
| 399 | //És l'ítem de solitari a l'atzar |
| 400 | solitariAtzar_generaJoc(); |
| 401 | //06/02/13 nou prod. |
| 402 | actualitzaConfiguracionsInicials(); |
| 403 | //solucioJocActual_configuracioInicial.clear(); |
| 404 | //solucioJocActual_configuracioInicial.append(taulerJoc->configuracioActual(true)); |
| 405 | } |
| 406 | else { |
| 407 | taulerJoc->joc_CarregaJoc(item->text(1),item->text(2),item->text(3)); |
| 408 | taulerJoc->setCodiNomJocActual(item->text(4)); |
| 409 | setArbreJocsActual(0); |
| 410 | taulerJoc->setSolitariModificat(false); |
| 411 | taulerJoc->setSolitariPersonalitzat(false); |
| 412 | //es tracta d'un joc del programa |
| 413 | tipusJocActual=0; |
| 414 | //30/12/12 Nova funció hihaRecord() |
| 415 | // QSettings records; |
| 416 | QStringList tipusJoc = item->text(1).split(" "); |
| 417 | QString record=hihaRecordJoc(tipusJoc.value(0)); |
| 418 | // records.value( QString("%1/record").arg(tipusJoc.value(0)) , |
| 419 | // QString("0")).toString(); |
| 420 | //No mostrarem els records en els solitaris generats a l'atzar |
| 421 | if ( (record != "0") && |
| 422 | !(solitariAtzar_esAtzar(item->text(1))) ){ |
| 423 | statusBar()->showMessage( |
| 424 | QString(tr("Joc carregat. El vostre record actual és: %1")).arg(record)); |
| 425 | } |
| 426 | else statusBar()->clearMessage(); |
| 427 | |
| 428 | seguentCodiSolitariPersonalitzat.clear(); |
| 429 | seguentCodiSolitariPersonalitzat.append( |
| 430 | solitariPersonalitzat_nouCodiJoc(false)); |
| 431 | //06/02/13 nou prod. |
| 432 | actualitzaConfiguracionsInicials(); |
| 433 | //Comprovam l'arxiu de solucions |
| 434 | comprovaArxiuSolucions(); |
| 435 | } |
| 436 | qApp->processEvents(); |
| 437 | //Si les solucions estan visibles, actualitzam |
| 438 | veureSolucionsSlot(); |
| 439 | taulerJoc->numeroDeMovimentsJoc(); |
| 440 | mostraMissatge(4); |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | /* Retorna la cadena de la ruta de l'arxiu d'imatge OK |
| 446 | * per marcar els joc que ja ha resolt l'usuari |
| 447 | */ |
| 448 | QString frmPrincipal::posaIconeOK(QString codiJoc){ |
| 449 | //Comprovam si hi ha un rècord |
| 450 | if(hihaRecordJoc(codiJoc) != "0"){ |
| 451 | return directoriLinux()+QDir().separator()+"images"+QDir().separator()+"ok.png";} |
| 452 | else return ""; |
| 453 | } |
| 454 | /* Comprova si hi ha un record pel joc |
| 455 | * i el retorna |
| 456 | */ |
| 457 | QString frmPrincipal::hihaRecordJoc(QString codiJoc){ |
| 458 | QSettings records; |
| 459 | return records.value( QString("%1/record").arg(codiJoc) , |
| 460 | QString("0")).toString(); |
| 461 | } |
| 462 | |
| 463 | void frmPrincipal:: tradueixGUI(){ |
| 464 | surtAction->setText(tr("&Surt")); |
| 465 | veureRecordsPersonalsAction->setText(tr("Veure records")); |
| 466 | ajudaAction->setText(tr("Ajuda")); |
| 467 | creditsPrograma->setText(tr("Credits")); |
| 468 | agraiment->setText(tr("Agraïments")); |
| 469 | webProgramaAction->setText(tr("Web del programa")); |
| 470 | webProgramaPecesAction->setText(tr("Web del tangram")); |
| 471 | |
| 472 | //undoAction->setToolTip(tr("Retrocedeix")); |
| 473 | undoAction->setText(tr("Retrocedeix")); |
| 474 | redoAction->setText(tr("Avança")); |
| 475 | |
| 476 | solucionaJocActual->setText(tr("Resol")); |
| 477 | //29/05/17 Només per estudiat el joc |
| 478 | // solucionaJocActualForcaBruta->setText(tr("Calcula el joc complet")); |
| 479 | |
| 480 | |
| 481 | aplicacioMenu->setTitle(tr("Programa")); |
| 482 | movimentsMenu->setTitle(tr("&Moviments joc")); |
| 483 | idiomaMenu->setTitle(tr("Idioma")); |
| 484 | ajudaMenu->setTitle(tr("Ajuda")); |
| 485 | |
| 486 | setWindowTitle( tr("Solitari")); |
| 487 | |
| 488 | veureRecordsPersonalsAction->setText(tr("Veure marques personals")); |
| 489 | eliminaRecordsPersonalsAction->setText(tr("Elimina marques personals")); |
| 490 | reiniciaJocActual->setText(tr("Reinicia el joc actual")); |
| 491 | iniciSolucioAction->setText(tr("Inici solució")); |
| 492 | solucionaJocActual->setText(tr("Resol")); |
| 493 | /* 16/10/12 Eliminats |
| 494 | veureSolucions->setText(tr("Veure solucions")); |
| 495 | */ |
| 496 | |
| 497 | // tabArbres->setTabText(0,"");//tr("Modalitats del joc")); |
| 498 | // tabArbres->setTabText(1,tr("Solucions")); |
| 499 | tabArbres->setTabToolTip(0,tr("Modalitats del joc")); |
| 500 | tabArbres->setTabToolTip(1,tr("Solucions")); |
| 501 | tabArbres->setTabToolTip(2,tr("Jocs personalitzats")); |
| 502 | //Això és necessari per eliminar l'arxiu de |
| 503 | //solucions de les modalitats generades a l'atzar |
| 504 | solitariAtzar_eliminaArxiuSolucio(); |
| 505 | carregaArbreModalitatsJoc(); |
| 506 | carregaArbreModalitatsJocPersonalitzats(); |
| 507 | tabArbres->setCurrentIndex(0); |
| 508 | } |
| 509 | |
| 510 | |
| 511 | void frmPrincipal::creaAcccions() |
| 512 | { |
| 513 | /* Les noves accions que tenguin text, cal posar-les |
| 514 | * a tradueixGUI(). |
| 515 | */ |
| 516 | surtAction = new QAction(tr("&Surt"), this); |
| 517 | surtAction->setShortcut(tr("Ctrl+S")); |
| 518 | surtAction->setIcon(QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/quit.png")); |
| 519 | connect(surtAction, SIGNAL(triggered()), this, SLOT(close())); |
| 520 | |
| 521 | veureRecordsPersonalsAction = new QAction(tr("Veure marques personals"), this); |
| 522 | connect(veureRecordsPersonalsAction, SIGNAL(triggered()), this, SLOT(veureRecordsPersonals())); |
| 523 | |
| 524 | eliminaRecordsPersonalsAction = new QAction(tr("Elimina marques personals"), this); |
| 525 | connect(eliminaRecordsPersonalsAction, SIGNAL(triggered()), this, SLOT(eliminaRecordsPersonals())); |
| 526 | |
| 527 | reiniciaJocActual = new QAction(tr("Reinicia el joc actual"), this); |
| 528 | reiniciaJocActual->setShortcut(tr("Ctrl+R")); |
| 529 | reiniciaJocActual->setIcon(QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/view-refresh.png")); |
| 530 | connect(reiniciaJocActual, SIGNAL(triggered()), this, SLOT(gestioTipusDeJocASeleccionar())); |
| 531 | |
| 532 | pausaAction= new QAction(tr("Pausa"), this); |
| 533 | pausaAction->setShortcut(tr("Ctrl+P")); |
| 534 | pausaAction->setIcon(QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/atura.png")); |
| 535 | connect(pausaAction, SIGNAL(triggered()), this, SLOT(pausaJocSlot())); |
| 536 | |
| 537 | /* 07/02/11 Per ara, aixó queda aturat. Cal tenir més garanties |
| 538 | sobre la seva efectivitat |
| 539 | sugereixMovimentAction= new QAction(tr("Suggereix moviment"), this); |
| 540 | sugereixMovimentAction->setShortcut(tr("Ctrl+M")); |
| 541 | sugereixMovimentAction->setIcon(QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/sugereix.png")); |
| 542 | connect(sugereixMovimentAction, SIGNAL(triggered()), this, SLOT(sugereixMovimentSlot())); |
| 543 | */ |
| 544 | |
| 545 | |
| 546 | |
| 547 | //Això és degut al tema de les traduccions |
| 548 | //25/07/12 |
| 549 | //Quan carrega moviments, torna la traducció enrera!! |
| 550 | //undoAction=movimentsUndoStack->createUndoAction(this,tr("Retrocedeix")); |
| 551 | undoAction=movimentsUndoStack->createUndoAction(this); |
| 552 | // undoAction->setText(tr("Retrocedeix")); |
| 553 | // undoAction->setToolTip(tr("Retrocedeix")); |
| 554 | undoAction->setShortcut(tr("Ctrl+Z")); |
| 555 | undoAction->setIcon(QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/edit-undo.png")); |
| 556 | |
| 557 | //redoAction=movimentsUndoStack->createRedoAction(this,tr("Avança")); |
| 558 | redoAction=movimentsUndoStack->createRedoAction(this); |
| 559 | redoAction->setShortcut(tr("Shift+Ctrl+Z")); |
| 560 | redoAction->setIcon(QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/edit-redo.png")); |
| 561 | |
| 562 | iniciSolucioAction= new QAction(tr("Inici solució"), this); |
| 563 | connect(iniciSolucioAction, SIGNAL(triggered()), this, SLOT(iniciSolucioSlot())); |
| 564 | iniciSolucioAction->setIcon(QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/go-first.png")); |
| 565 | iniciSolucioAction->setEnabled(false); |
| 566 | |
| 567 | |
| 568 | creditsPrograma= new QAction(tr("Credits"), this); |
| 569 | connect(creditsPrograma, SIGNAL(triggered()), this, SLOT(creditsProgramaSlot())); |
| 570 | |
| 571 | ajudaAction= new QAction(tr("Ajuda"), this); |
| 572 | connect(ajudaAction, SIGNAL(triggered()), this, SLOT(ajudaSlot())); |
| 573 | |
| 574 | webProgramaAction= new QAction(tr("Web del programa"), this); |
| 575 | connect(webProgramaAction, SIGNAL(triggered()), this, SLOT(webProgramaSlot())); |
| 576 | |
| 577 | webProgramaPecesAction= new QAction(tr("Web del tangram"), this); |
| 578 | connect(webProgramaPecesAction, SIGNAL(triggered()), this, SLOT(webProgramaPecesSlot())); |
| 579 | |
| 580 | solucionaJocActual = new QAction(tr("Resol"), this); |
| 581 | solucionaJocActual->setIcon(QIcon(directoriLinux()+QDir().separator()+DIRECTORI_IMATGES+"/soluciona.png")); |
| 582 | //connect(solucionaJocActual, SIGNAL(triggered()), this, SLOT(solucionaJocActual_Inicia())); |
| 583 | connect(solucionaJocActual, SIGNAL(triggered()), this, SLOT(solucionaJocRapid())); |
| 584 | |
| 585 | //29/05/17 |
| 586 | //Només per analitzar el joc |
| 587 | // solucionaJocActualForcaBruta = new QAction(tr("Calcula el joc complet"), this); |
| 588 | // solucionaJocActualForcaBruta->setIcon(QIcon(directoriLinux()+QDir().separator()+ |
| 589 | // DIRECTORI_IMATGES+"/forca-bruta.png")); |
| 590 | // connect(solucionaJocActualForcaBruta, SIGNAL(triggered()), this, SLOT(solucionaJoc_ForcaBruta())); |
| 591 | |
| 592 | agraiment= new QAction(tr("Agraïments"), this); |
| 593 | connect(agraiment, SIGNAL(triggered()), this, SLOT(agraimentSlot())); |
| 594 | |
| 595 | |
| 596 | /* 16/10/12 Eliminats |
| 597 | veureSolucions= new QAction(tr("Veure solucions"), this); |
| 598 | connect(veureSolucions, SIGNAL(triggered()), this, SLOT(veureSolucionsSlot())); |
| 599 | */ |
| 600 | } |
| 601 | |
| 602 | |
| 603 | void frmPrincipal::creaBarraTasques() |
| 604 | { |
| 605 | |
| 606 | aplicacioToolBar = addToolBar("Solitari"); |
| 607 | aplicacioToolBar->setIconSize(QSize(22,22)); |
| 608 | aplicacioToolBar->addAction(surtAction); |
| 609 | |
| 610 | aplicacioToolBar->addAction(reiniciaJocActual); |
| 611 | aplicacioToolBar->addAction(pausaAction); |
| 612 | /* 07/02/11 |
| 613 | aplicacioToolBar->addAction(sugereixMovimentAction); |
| 614 | */ |
| 615 | aplicacioToolBar->addSeparator(); |
| 616 | aplicacioToolBar->addAction(iniciSolucioAction); |
| 617 | aplicacioToolBar->addAction(undoAction); |
| 618 | aplicacioToolBar->addAction(redoAction); |
| 619 | aplicacioToolBar->addSeparator(); |
| 620 | aplicacioToolBar->addAction(solucionaJocActual); |
| 621 | aplicacioToolBar->addSeparator(); |
| 622 | //29/05/17 El métode de força bruta només es fa servir |
| 623 | //per analitzar el joc |
| 624 | // aplicacioToolBar->addAction(solucionaJocActualForcaBruta); |
| 625 | // aplicacioToolBar->addAction(solucionaJocActualRapid); |
| 626 | } |
| 627 | |
| 628 | |
| 629 | void frmPrincipal::creaMenus() |
| 630 | { |
| 631 | aplicacioMenu = menuBar()->addMenu(tr("Programa")); |
| 632 | aplicacioMenu->addAction(veureRecordsPersonalsAction); |
| 633 | aplicacioMenu->addAction(eliminaRecordsPersonalsAction); |
| 634 | |
| 635 | /* 16/10/12 Eliminats |
| 636 | aplicacioMenu->addSeparator(); |
| 637 | aplicacioMenu->addAction(veureSolucions); |
| 638 | */ |
| 639 | |
| 640 | aplicacioMenu->addSeparator(); |
| 641 | aplicacioMenu->addAction(surtAction); |
| 642 | |
| 643 | movimentsMenu= menuBar()->addMenu(tr("&Moviments joc")); |
| 644 | movimentsMenu->addAction(undoAction); |
| 645 | movimentsMenu->addAction(redoAction); |
| 646 | |
| 647 | idiomaMenu = new QMenu(tr("Idioma")); |
| 648 | menuBar()->addMenu(idiomaMenu); |
| 649 | |
| 650 | ajudaMenu= new QMenu(tr("Ajuda")); |
| 651 | menuBar()->addMenu(ajudaMenu); |
| 652 | ajudaMenu->addAction(ajudaAction); |
| 653 | ajudaMenu->addAction(creditsPrograma); |
| 654 | ajudaMenu->addAction(agraiment); |
| 655 | ajudaMenu->addAction(webProgramaAction); |
| 656 | ajudaMenu->addAction(webProgramaPecesAction); |
| 657 | |
| 658 | |
| 659 | creaIdiomaMenu(); |
| 660 | } |
| 661 | |
| 662 | |
| 663 | /* |
| 664 | Suggereix el següent moviment a l'usuari |
| 665 | No es fa servir!! És només una idea |
| 666 | */ |
| 667 | void frmPrincipal::sugereixMovimentSlot(){ |
| 668 | // if(rellotgeLabel->rellotgeEnMarxa()){ |
| 669 | QStringList movimentsAnteriors; |
| 670 | QString darrerMoviment; |
| 671 | QStringList movimentsSuggerits; |
| 672 | /* for(int j=0;j<movimentsUndoStack->count();j++){ |
| 673 | movimentsAnteriors.append(QString("%1 %2"). |
| 674 | arg(j+1). |
| 675 | arg(coordenadesAMoviment(movimentsUndoStack->text(j)))) ; |
| 676 | }*/ |
| 677 | darrerMoviment.append(coordenadesAMoviment(movimentsUndoStack->text( |
| 678 | movimentsUndoStack->index()-1))); |
| 679 | carregaConfiguracionsEliminades(); |
| 680 | //Cal carregar els moviments possibles de les fitxes |
| 681 | taulerJoc->solucionaJocActual_CalculaMovimentsPosibles(); |
| 682 | movimentsSuggerits.append( |
| 683 | taulerJoc->solucionaJocActual_CarregaMovimentsArbre1(solucioJocActual_configuracionsEliminades, |
| 684 | darrerMoviment)); |
| 685 | /* |
| 686 | qDebug("movimentsSuggerits %d", movimentsSuggerits.count()); |
| 687 | qDebug("darrerMoviment %d", darrerMoviment.length()); |
| 688 | qCritical("darrerMoviment %s", qPrintable(darrerMoviment)); |
| 689 | |
| 690 | qDebug("movimentsSuggerits.count() %d", movimentsSuggerits.count()); |
| 691 | qCritical("movimentsSuggerits.value(0) %s", qPrintable(movimentsSuggerits.value(0))); |
| 692 | */ |
| 693 | qDebug("Moviments suggerits %d",movimentsSuggerits.count()); |
| 694 | for (int i = 0; i < movimentsSuggerits.count(); ++i) { |
| 695 | qCritical("%s", qPrintable(movimentsSuggerits.value(i))); |
| 696 | } |
| 697 | if (movimentsSuggerits.count()>0){ |
| 698 | darrerMoviment.clear(); |
| 699 | darrerMoviment.append(movimentsSuggerits.value(qrand() % movimentsSuggerits.count())); |
| 700 | //Marcam el moviment seleccionat en el tauler de joc |
| 701 | taulerJoc->marcaMoviment(darrerMoviment); |
| 702 | qCritical("darrerMoviment %s", qPrintable(darrerMoviment)); |
| 703 | } |
| 704 | //} |
| 705 | } |
| 706 | |
| 707 | |
| 708 | /* |
| 709 | Manté el joc en pausa |
| 710 | */ |
| 711 | void frmPrincipal::pausaJocSlot(){ |
| 712 | //Si s'està jugant, s'atura el joc |
| 713 | if(rellotgeLabel->rellotgeEnMarxa()){ |
| 714 | QProgressDialog pausaProgres(tr("Pausa"), tr("Continua"),0,0 ,this); |
| 715 | rellotgeLabel->aturaRellotge(); |
| 716 | pausaProgres.setWindowModality(Qt::WindowModal); |
| 717 | pausaProgres.setVisible(true); |
| 718 | |
| 719 | // QString configuracioJoc= taulerJoc->configuracioActual(); |
| 720 | qApp->processEvents(); |
| 721 | bool continua=true; |
| 722 | taulerJoc->setVisible(false); |
| 723 | /*18/03/17 Canviat degut als problemes dels fotosensibles*/ |
| 724 | while (continua){ |
| 725 | // taulerJoc->estatFitxesAtzar(); |
| 726 | if (pausaProgres.wasCanceled()){ |
| 727 | continua=false; |
| 728 | taulerJoc->setVisible(true); |
| 729 | // taulerJoc->carregaConfiguracio(configuracioJoc); |
| 730 | } |
| 731 | qApp->processEvents(); |
| 732 | } |
| 733 | pausaProgres.close(); |
| 734 | rellotgeLabel->iniciaRellotge(); |
| 735 | } |
| 736 | } |
| 737 | |
| 738 | /* |
| 739 | * Retorna totes les fitxes a la posició inicial del joc |
| 740 | * (o fins el moviment passat per paràmetre) |
| 741 | */ |
| 742 | void frmPrincipal::iniciSolucioSlot(int pmoviment){ |
| 743 | /*qDebug("movimentsUndoStack.count() %d",movimentsUndoStack->count()); |
| 744 | qDebug("Reinicia*******");*/ |
| 745 | if (pmoviment>0){ |
| 746 | int contador=0; |
| 747 | //while (movimentsUndoStack->canUndo() && movimentsUndoStack->index()> pmoviment ){ |
| 748 | while (movimentsUndoStack->canUndo() && contador<= pmoviment ){ |
| 749 | movimentsUndoStack->undo(); |
| 750 | contador++; |
| 751 | } |
| 752 | qDebug("retroces iniciSolucio %d",contador); |
| 753 | } |
| 754 | else{ |
| 755 | while (movimentsUndoStack->canUndo() ){ |
| 756 | movimentsUndoStack->undo(); |
| 757 | } |
| 758 | } |
| 759 | //Cal assegurar-se que totes les fitxes actives |
| 760 | //queden en color blau. |
| 761 | taulerJoc->eliminaFitxesVerdes(); |
| 762 | taulerJoc->eliminaFitxesVermelles(); |
| 763 | statusBar()->clearMessage(); |
| 764 | //qDebug("Numero moviments %d", movimentsUndoStack->count()); |
| 765 | //iniciSolucioAction->setEnabled(movimentsUndoStack->canUndo()); |
| 766 | } |
| 767 | |
| 768 | void frmPrincipal::iniciSolucioSlotIndex(int index){ |
| 769 | |
| 770 | while (movimentsUndoStack->canUndo() && movimentsUndoStack->index()> index){ |
| 771 | movimentsUndoStack->undo(); |
| 772 | } |
| 773 | |
| 774 | //Cal assegurar-se que totes les fitxes actives |
| 775 | //queden en color blau. |
| 776 | taulerJoc->eliminaFitxesVerdes(); |
| 777 | taulerJoc->eliminaFitxesVermelles(); |
| 778 | statusBar()->clearMessage(); |
| 779 | //qDebug("Numero moviments %d", movimentsUndoStack->count()); |
| 780 | //iniciSolucioAction->setEnabled(movimentsUndoStack->canUndo()); |
| 781 | } |
| 782 | |
| 783 | |
| 784 | /* Carrega una solució a partir de la |
| 785 | * pila de moviments |
| 786 | * (es fa servir en els solitaris personalitzats) |
| 787 | */ |
| 788 | void frmPrincipal::finalSolucioSlot(bool marcaFinal){ |
| 789 | while (movimentsUndoStack->canRedo() ){ |
| 790 | movimentsUndoStack->redo();} |
| 791 | taulerJoc->marcaFinalDeJoc(taulerJoc->p_tipusMoviment,marcaFinal); |
| 792 | // if (marcaFinal){taulerJoc->marcaFinalDeJoc(taulerJoc->p_tipusMoviment,marcaFinal);} |
| 793 | } |
| 794 | |
| 795 | |
| 796 | /* Genera el menú de selecció d'idioma de l'aplicació */ |
| 797 | void frmPrincipal::creaIdiomaMenu(){ |
| 798 | |
| 799 | idiomaActionGroup = new QActionGroup(this); |
| 800 | connect(idiomaActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(canviaIdioma(QAction *))); |
| 801 | |
| 802 | QDir dir(directoriLinux()+QDir().separator()+DIRECTORI_LOCALES); |
| 803 | QStringList arxiusIdioma = dir.entryList(QStringList("solitari_*.qm")); |
| 804 | /* 02/06/12 v. 1.3 |
| 805 | * Afegit la càrrega del idioma ja seleccionat |
| 806 | */ |
| 807 | QString localeSys= |
| 808 | QSettings().value("General/idioma",QLocale::system().name()).toString(); |
| 809 | |
| 810 | for (int i = 0; i < arxiusIdioma.size(); ++i) { |
| 811 | QString locale = arxiusIdioma[i]; |
| 812 | locale.remove(0, locale.indexOf('_') + 1); |
| 813 | locale.truncate(locale.lastIndexOf('.')); |
| 814 | |
| 815 | QTranslator translator; |
| 816 | translator.load(arxiusIdioma[i], directoriLinux()+QDir().separator()+DIRECTORI_LOCALES); |
| 817 | QString language =translator.translate("Traduccio","English"); |
| 818 | // QAction *action = new QAction(QString("&%1 %2").arg(i + 1).arg(language), this); |
| 819 | QAction *action = new QAction(tr("&%1 %2").arg(i + 1).arg(language), this); |
| 820 | action->setCheckable(true); |
| 821 | action->setData(locale); |
| 822 | |
| 823 | idiomaMenu->addAction(action); |
| 824 | idiomaActionGroup->addAction(action); |
| 825 | |
| 826 | //if (locale == QLocale::system().name()){ |
| 827 | if (locale == localeSys){ |
| 828 | action->setChecked(true); |
| 829 | //a debian, sense això es carregan les cadenes |
| 830 | //originals enlloc de les traduïdes |
| 831 | canviaIdioma(action); |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | |
| 837 | void frmPrincipal::canviaIdioma(QAction *action){ |
| 838 | localePrograma = action->data().toString(); |
| 839 | appTranslator->load("solitari_" + localePrograma, directoriLinux()+QDir().separator()+DIRECTORI_LOCALES); |
| 840 | qt_translator->load(QLatin1String("qt_") + localePrograma, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); |
| 841 | |
| 842 | tradueixGUI(); |
| 843 | /* 1.3 |
| 844 | * Desam el idioma seleccionat |
| 845 | */ |
| 846 | QSettings().setValue("General/idioma",localePrograma); |
| 847 | } |
| 848 | |
| 849 | void frmPrincipal::resizeEvent ( QResizeEvent * event ){ |
| 850 | QSize augment=this->size()-this->minimumSize(); |
| 851 | jocFram->resize(QSize(jocFram->minimumSize().width(), jocFram->minimumSize().height()+augment.height())); |
| 852 | tabArbres->resize(QSize(tabArbres->minimumSize().width(), |
| 853 | tabArbres->minimumSize().height()+augment.height())); |
| 854 | arbreModalitatsJocTreeWidget->resize( |
| 855 | QSize(arbreModalitatsJocTreeWidget->minimumSize().width(), |
| 856 | arbreModalitatsJocTreeWidget->minimumSize().height()+augment.height())); |
| 857 | taulerJoc->resize(QSize(taulerJoc->minimumSize()+augment)); |
| 858 | } |
| 859 | |
| 860 | void frmPrincipal::closeEvent(QCloseEvent* event){ |
| 861 | QStringList tipusJoc = arbreModalitatsJocTreeWidget->selectedItems().first()->text(1).split(" "); |
| 862 | QSettings().setValue("General/modalidadJoc",tipusJoc.value(0)); |
| 863 | /*12/03/12 |
| 864 | Desam la disposició del formulari |
| 865 | */ |
| 866 | QSettings().setValue(QString("General/geometry"),saveGeometry()); |
| 867 | //Eliminan els arxius de solucions dels solitaris |
| 868 | //generats a l'atzar |
| 869 | solitariAtzar_eliminaArxiuSolucio(); |
| 870 | event->accept(); |
| 871 | } |
| 872 | |
| 873 | void frmPrincipal::creditsProgramaSlot(){ |
| 874 | QDate avui=QDate::currentDate () ; |
| 875 | QString missatge=QString("<h2>"+tr("Solitari")+ |
| 876 | QString(" v. %1</h2>").arg(qApp->applicationVersion())); |
| 877 | if (avui.year()==2010){ |
| 878 | missatge.append(QString("<p> © "+QString("2010")+" I. De Marchi <br/>" )); |
| 879 | } |
| 880 | else { |
| 881 | missatge.append(QString("<p> © "+QString("2010-%1").arg(avui.year())+" I. De Marchi<br/>" )); |
| 882 | } |
| 883 | missatge.append(QString(tr("Sota llicència GPL 2.0 o posterior")+"<br/>")); |
| 884 | |
| 885 | missatge.append(QString("<a href=\"%1\">%1</a><br/>").arg(ADRECA_WEB_PROGRAMA_1)); |
| 886 | missatge.append(QString("<a href=\"%1\">%1</a><br/>").arg(ADRECA_WEB_PROGRAMA_2)); |
| 887 | missatge.append(QString("<a href=mailto:%1>%1</a><br/>").arg(ADRECA_CORREU)); |
| 888 | |
| 889 | QMessageBox::about(this, |
| 890 | QString(tr("Credits del %1").arg(qApp->applicationName())),missatge); |
| 891 | } |
| 892 | |
| 893 | void frmPrincipal::webProgramaSlot(){ |
| 894 | QDesktopServices::openUrl(ADRECA_WEB_PROGRAMA_1); |
| 895 | } |
| 896 | |
| 897 | void frmPrincipal::webProgramaPecesSlot(){ |
| 898 | QDesktopServices::openUrl(ADRECA_WEB_PROGRAMA_PECES); |
| 899 | } |
| 900 | |
| 901 | |
| 902 | void frmPrincipal::veureRecordsPersonals(){ |
| 903 | if (arbreModalitatsJocTreeWidget->topLevelItemCount()==0){ return;} |
| 904 | /* 08/12/2012 |
| 905 | *Substituït per un arxiu html: els rècords no hi cabem en |
| 906 | *un formulari about |
| 907 | * |
| 908 | |
| 909 | QString missatge=QString("<h2>"+ tr("Marques personals")+"</h2>"); |
| 910 | QSettings records; |
| 911 | for(int i=0;i<=arbreModalitatsJocTreeWidget->topLevelItemCount()-1;i++){ |
| 912 | QStringList tipusJoc = arbreModalitatsJocTreeWidget->topLevelItem(i)->text(1).split(" "); |
| 913 | QString record=records.value( QString("%1/record"). |
| 914 | arg(tipusJoc.value(0)) , |
| 915 | QString("--")).toString(); |
| 916 | if( !(record.compare("--")==0)){ |
| 917 | missatge.append(QString("<br>"+arbreModalitatsJocTreeWidget->topLevelItem(i)->text(0)+ |
| 918 | " -> "+record)); |
| 919 | } |
| 920 | // missatge.append(QString("<p>"+arbreModalitatsJocTreeWidget->topLevelItem(i)->text(0)+ |
| 921 | // " -> "+record )) ; |
| 922 | } |
| 923 | QMessageBox::about(this,QString(tr("Marques personals")),missatge); |
| 924 | */ |
| 925 | |
| 926 | /* Versió HTML |
| 927 | * 08/12/12 |
| 928 | */ |
| 929 | comprovaDirectoriHome(); |
| 930 | QString nomArxiu=QDir::homePath (); |
| 931 | nomArxiu.append (QDir().separator()); |
| 932 | nomArxiu.append (qApp->applicationName()); |
| 933 | nomArxiu.append (QDir().separator()); |
| 934 | nomArxiu.append (QString("records.html")); |
| 935 | QFile arxiu(nomArxiu); |
| 936 | QTextStream entrada(&arxiu); |
| 937 | //capçalera de l'arxiu |
| 938 | if (!arxiu.open(QIODevice::WriteOnly)){return;} |
| 939 | entrada<<(QString("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">")); |
| 940 | entrada<<(QString("\n")); |
| 941 | entrada<<(QString("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />")); |
| 942 | entrada<<(QString("\n")); |
| 943 | entrada<<(QString("<html><head><br>")); |
| 944 | entrada<<(QString("\n")); |
| 945 | entrada<<(QString("<title>%1</title>").arg(tr("Marques personals"))); |
| 946 | entrada<<(QString("\n")); |
| 947 | entrada<<(QString("</head>")); |
| 948 | entrada<<(QString("\n")); |
| 949 | entrada<<(QString("<body>")); |
| 950 | entrada<<(QString("\n")); |
| 951 | entrada<<(QString("<h2>"+ tr("Marques personals")+"</h2>")); |
| 952 | //Ara començam a escriure els rècords |
| 953 | QSettings records; |
| 954 | int contador=1; |
| 955 | for(int i=0;i<=arbreModalitatsJocTreeWidget->topLevelItemCount()-1;i++){ |
| 956 | QStringList tipusJoc = arbreModalitatsJocTreeWidget->topLevelItem(i)->text(1).split(" "); |
| 957 | QString record=records.value( QString("%1/record"). |
| 958 | arg(tipusJoc.value(0)) , |
| 959 | QString("--")).toString(); |
| 960 | if( !(record.compare("--")==0)){ |
| 961 | entrada<<(QString("<br> %1 "+arbreModalitatsJocTreeWidget->topLevelItem(i)->text(0)+ |
| 962 | " -> "+record).arg(contador)); |
| 963 | contador++; |
| 964 | entrada<<(QString("\n")); |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | for(int j=0;j<=arbreModalitatsJocPersonalitzatsTreeWidget->topLevelItemCount()-1;j++){ |
| 969 | QStringList tipusJoc = arbreModalitatsJocPersonalitzatsTreeWidget->topLevelItem(j)->text(1).split(" "); |
| 970 | QString record=records.value( QString("%1/record"). |
| 971 | arg(tipusJoc.value(0)) , |
| 972 | QString("--")).toString(); |
| 973 | if( !(record.compare("--")==0)){ |
| 974 | entrada<<(QString("<br> %1 "+arbreModalitatsJocPersonalitzatsTreeWidget->topLevelItem(j)->text(0)+ |
| 975 | " -> "+record).arg(contador)); |
| 976 | contador++; |
| 977 | entrada<<(QString("\n")); |
| 978 | } |
| 979 | } |
| 980 | //tancam l'arxiu |
| 981 | entrada<<(QString("</div>")); |
| 982 | entrada<<(QString("</body></html>")); |
| 983 | arxiu.close(); |
| 984 | //Mostram l'arxiu |
| 985 | QDesktopServices::openUrl(QUrl("file:///"+nomArxiu, QUrl::TolerantMode)); |
| 986 | |
| 987 | |
| 988 | /* |
| 989 | QTextEdit *texte = new QTextEdit (missatge ); |
| 990 | texte->setReadOnly(true); |
| 991 | QDockWidget *recordsPersonalsDockWidget = new QDockWidget(tr("Marques personals")); |
| 992 | recordsPersonalsDockWidget->setWidget(texte); |
| 993 | recordsPersonalsDockWidget->setMinimumSize(400,300); |
| 994 | recordsPersonalsDockWidget->move(QPoint(this->pos().x()+50,this->pos().y()+200)); |
| 995 | //solucionsDockWidget->setAllowedAreas(Qt::NoDockWidgetArea); |
| 996 | addDockWidget(Qt::BottomDockWidgetArea, recordsPersonalsDockWidget); |
| 997 | //addDockWidget(Qt::NoDockWidgetArea, solucionsDockWidget); |
| 998 | recordsPersonalsDockWidget->setFloating(false); |
| 999 | */ |
| 1000 | } |
| 1001 | |
| 1002 | /* |
| 1003 | Elimina tots els records personals |
| 1004 | */ |
| 1005 | void frmPrincipal::eliminaRecordsPersonals(){ |
| 1006 | QMessageBox missatgeBox; |
| 1007 | missatgeBox.setText(tr("Elimina les marques personals")); |
| 1008 | missatgeBox.setInformativeText(tr("De debó voleu eliminar les vostres marques?")); |
| 1009 | missatgeBox.setIcon(QMessageBox::Question); |
| 1010 | missatgeBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); |
| 1011 | missatgeBox.setDefaultButton(QMessageBox::No); |
| 1012 | if(missatgeBox.exec()==QMessageBox::Yes){ |
| 1013 | /* 21/09/16 Aqui es mantenia el sistema antic amb els rècords |
| 1014 | * a l'arxiu .ini i eliminava tota la informació de l'arxiu |
| 1015 | * No estava actualitzat al nou sistema amb l'arxiu .html |
| 1016 | */ |
| 1017 | comprovaDirectoriHome(); |
| 1018 | QString nomArxiu=QDir::homePath (); |
| 1019 | nomArxiu.append (QDir().separator()); |
| 1020 | nomArxiu.append (qApp->applicationName()); |
| 1021 | nomArxiu.append (QDir().separator()); |
| 1022 | nomArxiu.append (QString("records.html")); |
| 1023 | QFile arxiu(nomArxiu); |
| 1024 | arxiu.remove(); |
| 1025 | qApp->processEvents(); |
| 1026 | /* Eliminan les marques de l'arxiu de configuració |
| 1027 | El 100000 és una mica passat */ |
| 1028 | for(int i=0 ; i<50000;++i){ |
| 1029 | QSettings records; |
| 1030 | records.remove(QString("%1/record").arg(i)); |
| 1031 | } |
| 1032 | /*Recarregam els arbres de jocs per eliminar els |
| 1033 | *icones de marques*/ |
| 1034 | carregaArbreModalitatsJoc(); |
| 1035 | carregaArbreModalitatsJocPersonalitzats(); |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | void frmPrincipal::ajudaSlot(){ |
| 1042 | QDir dirArxiu; |
| 1043 | QString directori=directoriLinux()+ |
| 1044 | QDir().separator()+ |
| 1045 | DIR_HELP+ |
| 1046 | QDir().separator()+ |
| 1047 | "index.html";//això no funciona "#es_ES";//+QLocale::system().name(); |
| 1048 | //qCritical("%s", qPrintable(directori)); |
| 1049 | if (dirArxiu.exists(directori)){ |
| 1050 | //Això evita problemes amb els espais als noms dels directoris |
| 1051 | QDesktopServices::openUrl(QUrl("file:///"+directori+"#"+localePrograma, QUrl::TolerantMode)); |
| 1052 | } |
| 1053 | else QDesktopServices::openUrl(QUrl("file:///"+directoriLinux()+ |
| 1054 | QDir().separator()+ |
| 1055 | DIR_HELP+ |
| 1056 | QDir().separator()+ |
| 1057 | "index.html", QUrl::TolerantMode)); |
| 1058 | } |
| 1059 | |
| 1060 | |
| 1061 | /* 01/12/12 |
| 1062 | Mostra l'arxiu html amb els agraïments |
| 1063 | */ |
| 1064 | void frmPrincipal::agraimentSlot(){ |
| 1065 | QDesktopServices::openUrl(QUrl("file:///"+directoriLinux()+ |
| 1066 | QDir().separator()+ |
| 1067 | DIR_HELP+ |
| 1068 | QDir().separator()+ |
| 1069 | "index.html", QUrl::TolerantMode)); |
| 1070 | } |
| 1071 | |
| 1072 | /* Comprova si existeixen moviments possibles */ |
| 1073 | bool frmPrincipal::comprovaExisteixenMovimentsPossibles(){ |
| 1074 | |
| 1075 | taulerJoc->solucionaJocActual_CalculaMovimentsPosibles(); |
| 1076 | solucionaJocActual_movimentsPosiblesActuals.clear(); |
| 1077 | solucionaJocActual_movimentsPosiblesActuals.append( |
| 1078 | taulerJoc->solucionaJocActual_CarregaMovimentsArbre1(solucionaJocActual_movimentsEliminats, |
| 1079 | solucionaJocActual_darrerMoviment)); |
| 1080 | return solucionaJocActual_movimentsPosiblesActuals.count()>0; |
| 1081 | } |
| 1082 | |
| 1083 | void frmPrincipal::solucionaJocActual_Inicia(){ |
| 1084 | /*if (!rellotgeLabel->rellotgeEnMarxa()){ |
| 1085 | rellotgeLabel->estableixTemps(QString("00:00:00")); |
| 1086 | rellotgeLabel->iniciaRellotge(); |
| 1087 | }*/ |
| 1088 | QApplication::setOverrideCursor(Qt::WaitCursor); |
| 1089 | statusBar()->clearMessage(); |
| 1090 | solucionaJocActual_ControlJocPersonalitzatModificat(); |
| 1091 | |
| 1092 | jocResolt=0; |
| 1093 | taulerJoc->solucionaJocActual_CalculaMovimentsPosibles(); |
| 1094 | if(taulerJoc->solucionaJocActual_MovimentsPosiblesActuals()<0){ |
| 1095 | return; |
| 1096 | } |
| 1097 | /*Si ja hi ha moviments fets, llavors es "conservan" i es busca |
| 1098 | la solució a partir de la situació actual*/ |
| 1099 | if(movimentsUndoStack->count()>0){ |
| 1100 | retrocedeixMoviment=movimentsUndoStack->index(); |
| 1101 | //cercaSolucioAPartirDeMovimentsInicials=true; |
| 1102 | solucionaJocActual_movimentsJaRealitzats.clear(); |
| 1103 | iniciSolucioSlot(); |
| 1104 | // solucioJocActual_configuracioInicial.append(taulerJoc->configuracioActual(true)); |
| 1105 | while (movimentsUndoStack->canRedo()){ |
| 1106 | solucionaJocActual_darrerMoviment=QString("%1 ").arg(movimentsUndoStack->index()+1); |
| 1107 | solucionaJocActual_darrerMoviment.append( |
| 1108 | coordenadesAMoviment(movimentsUndoStack->text(movimentsUndoStack->index()))); |
| 1109 | solucionaJocActual_movimentsJaRealitzats.append(solucionaJocActual_darrerMoviment); |
| 1110 | movimentsUndoStack->redo(); |
| 1111 | } |
| 1112 | } |
| 1113 | else { |
| 1114 | //06/02/13 nou prod. |
| 1115 | actualitzaConfiguracionsInicials(); |
| 1116 | //solucioJocActual_configuracioInicial.clear(); |
| 1117 | //solucioJocActual_configuracioInicial.append( |
| 1118 | // taulerJoc->configuracioActual(true)); |
| 1119 | retrocedeixMoviment=0; |
| 1120 | movimentsUndoStack->clear(); |
| 1121 | } |
| 1122 | // solucioJocActual_configuracioInicial.append(taulerJoc->configuracioActual(true)); |
| 1123 | |
| 1124 | solucioJocActual_configuracionsEliminades.clear(); |
| 1125 | solucioJocActual_configuracionsEliminadesPerDesar.clear(); |
| 1126 | solucionaJocActual_movimentsPosiblesActuals.clear(); |
| 1127 | carregaConfiguracionsEliminades(); |
| 1128 | // movimentsUndoStack->clear(); |
| 1129 | solucionaJocActual_CarregaMovimentsInicialsArbre(); |
| 1130 | // qApp->processEvents(); |
| 1131 | } |
| 1132 | |
| 1133 | |
| 1134 | void frmPrincipal::solucionaJocActual_ControlJocPersonalitzatModificat(){ |
| 1135 | if( (taulerJoc->solitariPersonalitzat() ) || |
| 1136 | (taulerJoc->solitariModificat() )){ |
| 1137 | /* S'eliminen les solucions de l'arbre per evitar que |
| 1138 | * s'afegeixin a l'arxiu de solucions del nou |
| 1139 | * solitari (personal o modificat) |
| 1140 | */ |
| 1141 | // arbreSolucionsTreeWidget->clear(); |
| 1142 | solucionsTrobades.clear(); |
| 1143 | carregaSolucions(); |
| 1144 | // veureSolucionsSlot(); |
| 1145 | taulerJoc->setModalitatJocActual(seguentCodiSolitariPersonalitzat); |
| 1146 | } |
| 1147 | } |
| 1148 | |
| 1149 | void frmPrincipal::solucionaJocActual_CarregaMovimentsInicialsArbre(){ |
| 1150 | rellotgeLabel->iniciaRellotge(); |
| 1151 | solucionaJocActual_comencaRecerca(); |
| 1152 | QApplication::setOverrideCursor(Qt::ArrowCursor); |
| 1153 | } |
| 1154 | |
| 1155 | |
| 1156 | void frmPrincipal::solucionaJocActual_comencaRecerca(){ |
| 1157 | // qDebug("sistema versio 2.1"); |
| 1158 | /*Això és pel problema a windows en què si es mou |
| 1159 | * la finestra de diàleg, llavors s'atura la cerca però |
| 1160 | * no el rellotge*/ |
| 1161 | //int numeroDeMovimentsJocInicial=taulerJoc->numeroDeMovimentsJoc(); |
| 1162 | //qDebug("numeroDeMovimentsJocInicial %d", numeroDeMovimentsJocInicial); |
| 1163 | |
| 1164 | //11/06/17 Eliminat tot i què quan es mou el diàleg a windows |
| 1165 | //s'atura el joc però no el rellotge |
| 1166 | // #if defined(Q_OS_WIN32) |
| 1167 | // QProgressDialog progres(tr("Cercant solució"), tr("Atura"), 0, |
| 1168 | // taulerJoc->numeroDeMovimentsJoc(),this, |
| 1169 | // Qt::FramelessWindowHint); |
| 1170 | // #else |
| 1171 | //S'ha posat aquest +1 al num.màx. per evitar problemes amb |
| 1172 | //els jocs que tenen el final marcat |
| 1173 | QProgressDialog progres(tr("Cercant solució"), tr("Atura"), 0, |
| 1174 | //taulerJoc->numeroDeMovimentsJoc(),this); |
| 1175 | taulerJoc->numeroDeMovimentsJoc()+1,this); |
| 1176 | //taulerJoc->comptadorFitxesJoc,this); |
| 1177 | /* 21/06/12 |
| 1178 | * Posar això altra (per les modalitats amb final marcat) |
| 1179 | * causa problemes amb el progress |
| 1180 | */ |
| 1181 | // taulerJoc->numeroDeMovimentsJoc() ,this); |
| 1182 | // #endif |
| 1183 | progres.setWindowModality(Qt::WindowModal); |
| 1184 | //Això quasi sempre és cert degut a què |
| 1185 | //s'ha carregat (parcialment) alguna solució |
| 1186 | if (movimentsUndoStack->index()>0){ |
| 1187 | progres.setValue(movimentsUndoStack->index()-1);} |
| 1188 | //qDebug("movimentsUndoStack if %d",movimentsUndoStack->index()-1);} |
| 1189 | //return;} |
| 1190 | //qDebug("movimentsUndoStack inici %d",movimentsUndoStack->index()-1); |
| 1191 | //progres.setValue(0); |
| 1192 | progres.setVisible(true); |
| 1193 | progres.setLabelText(missatgeNumeroMoviments()); |
| 1194 | qApp->processEvents(); |
| 1195 | |
| 1196 | int numMovimentsPerReiniciar=taulerJoc->numeroDeMovimentsJoc()*3; |
| 1197 | int numeroFitxesMajorConfigEliminada=0; |
| 1198 | int numeroMovimentsProvats=0; |
| 1199 | |
| 1200 | int contadorSenseMoviments=0; |
| 1201 | int maximNombreIntentsSenseMoviment=400;//qMin(taulerJoc->numeroDeMovimentsJoc()*4,200); |
| 1202 | bool reinicia=false; |
| 1203 | //int contador=0; |
| 1204 | while (jocResolt !=2){ |
| 1205 | /*Calcul i selecció dels moviments que es poden realitzar |
| 1206 | * segons la seva prioritat i els conserva a solucionaJocActual_movimentsPosiblesActuals */ |
| 1207 | if (comprovaExisteixenMovimentsPossibles()){ |
| 1208 | // qDebug("Hi ha moviments possibles"); |
| 1209 | } |
| 1210 | //contador++; |
| 1211 | //qDebug("contador %d", contador); |
| 1212 | QString configAct=taulerJoc->configuracioActual(); |
| 1213 | /*Aquesta condició és decisiva en el sistema de recerca de sol. |
| 1214 | *Afegida la condició del número de moviments del joc |
| 1215 | *degut a les modalitats amb un número de fitxes finals |
| 1216 | *major a 1 |
| 1217 | */ |
| 1218 | if (solucionaJocActual_movimentsPosiblesActuals.count()==0){contadorSenseMoviments++; |
| 1219 | //qDebug("contadorSenseMoviments %d",contadorSenseMoviments); |
| 1220 | } |
| 1221 | /* Si es compleixen les condicions per fer un moviment, es fa*/ |
| 1222 | if ((solucionaJocActual_movimentsPosiblesActuals.count()>0) && (jocResolt ==0) |
| 1223 | && !(solucioJocActual_configuracionsEliminades.contains(configAct)) |
| 1224 | /*aquest procediment no és eficient |
| 1225 | amb les modalitats inverses. Es retorna sempre false en aquestes |
| 1226 | modalitats 25/01/13 */ |
| 1227 | && !(taulerJoc->solucionaJocActual_FitxesAillades2()) |
| 1228 | && ( (movimentsUndoStack->index()-1)<taulerJoc->numeroDeMovimentsJoc()) |
| 1229 | && ( taulerJoc->ocuparFitxesFinalJoc() ) |
| 1230 | ){ |
| 1231 | int numeroItem=0; |
| 1232 | // qDebug("solucionaJocActual_movimentsPosiblesActuals %d",solucionaJocActual_movimentsPosiblesActuals.count()); |
| 1233 | /*Si hi ha més d'un moviment propossat, elegim un a l'atzar*/ |
| 1234 | if (solucionaJocActual_movimentsPosiblesActuals.count()>1){ |
| 1235 | //rellotgeQTime s'ha posat al principi del programa. És vigent per cada fil! |
| 1236 | qsrand(rellotgeQTime.msecsTo(QTime::currentTime())); |
| 1237 | numeroItem=qrand() % (solucionaJocActual_movimentsPosiblesActuals.count()); |
| 1238 | } |
| 1239 | /*Executam el moviment seleccionat*/ |
| 1240 | QStringList movimentsItem= |
| 1241 | QStringList(solucionaJocActual_movimentsPosiblesActuals.value( |
| 1242 | numeroItem).split(" ")); |
| 1243 | taulerJoc->ferMoviment(movimentsItem.value(0).toInt() |
| 1244 | ,movimentsItem.value(1).toInt(),movimentsItem.value(2).toInt()); |
| 1245 | // qDebug("executat moviment! %d", numeroMovimentsProvats); |
| 1246 | ++numeroMovimentsProvats; |
| 1247 | progres.setValue(movimentsUndoStack->index()-1); |
| 1248 | progres.setLabelText(missatgeNumeroMoviments(taulerJoc->numeroDeMovimentsJoc())); |
| 1249 | qApp->processEvents(); |
| 1250 | |
| 1251 | solucionaJocActual_darrerMoviment=QString("%1 ").arg(movimentsUndoStack->index()); |
| 1252 | solucionaJocActual_darrerMoviment.append( |
| 1253 | solucionaJocActual_movimentsPosiblesActuals.value(numeroItem)); |
| 1254 | solucionaJocActual_movimentsJaRealitzats.append( |
| 1255 | solucionaJocActual_darrerMoviment); |
| 1256 | //qCritical("%s", qPrintable(solucionaJocActual_darrerMoviment)); |
| 1257 | |
| 1258 | } |
| 1259 | /* No es compleixen les condicions per fer un moviment*/ |
| 1260 | else { |
| 1261 | /* Hi ha moviments fets*/ |
| 1262 | if (movimentsUndoStack->index() !=0 ){ |
| 1263 | jocResolt=0; |
| 1264 | taulerJoc->eliminaFitxesVermelles(); |
| 1265 | // QString configAct=taulerJoc->configuracioActual(); |
| 1266 | numeroFitxesMajorConfigEliminada=qMax(numeroFitxesMajorConfigEliminada, |
| 1267 | numeroConfiguracio(configAct)); |
| 1268 | /* 09/02/13 Afegida la condició del 5 degut a què |
| 1269 | * s'afegien configuracions de final de joc |
| 1270 | */ |
| 1271 | /* S'afageix la posició actual de les fitxes en les configuracions eliminades |
| 1272 | * i es farà reiniciar el joc */ |
| 1273 | if ( (!solucioJocActual_configuracionsEliminades.contains(configAct)) && |
| 1274 | !configAct.contains("5")){ |
| 1275 | /* Aqui cal eliminar les configuracions posteriors de |
| 1276 | * solucioJocActual_configuracionsEliminades */ |
| 1277 | solucionaJocActual_eliminaConfiguracionsPosteriors(configAct); |
| 1278 | if( !solucioJocActual_configuracionsEliminadesPerDesar.contains(configAct)){ |
| 1279 | solucioJocActual_configuracionsEliminadesPerDesar.append(configAct); |
| 1280 | } |
| 1281 | solucioJocActual_configuracionsEliminades.prepend(configAct); |
| 1282 | reinicia=true; |
| 1283 | } |
| 1284 | |
| 1285 | if ( (solucionaJocActual_movimentsEliminats.indexOf(solucionaJocActual_darrerMoviment)==-1 ) && |
| 1286 | !(solucionaJocActual_darrerMoviment.isEmpty()) ){ |
| 1287 | solucionaJocActual_eliminaMovimentsPosteriors(); |
| 1288 | solucionaJocActual_movimentsEliminats.append(solucionaJocActual_darrerMoviment); |
| 1289 | } |
| 1290 | |
| 1291 | /* Es tornen enrrera el nombre de moviments seleccionats a l'atzar */ |
| 1292 | int contadorMovimentsRevertits=0; |
| 1293 | int movimentsARevertir=qrand() % 4; //(qMin(taulerJoc->comptadorFitxesJoc,4)); |
| 1294 | // qrand() % 5; |
| 1295 | while (contadorMovimentsRevertits< movimentsARevertir){ |
| 1296 | movimentsUndoStack->undo(); |
| 1297 | contadorMovimentsRevertits++; |
| 1298 | /* qDebug("contadorMovimentsRevertits %d", contadorMovimentsRevertits);*/ |
| 1299 | /* qDebug("movimentsUndoStack %d", movimentsUndoStack->count());*/ |
| 1300 | progres.setValue(movimentsUndoStack->index()-1); |
| 1301 | progres.setLabelText(missatgeNumeroMoviments(taulerJoc->numeroDeMovimentsJoc())); |
| 1302 | if (solucionaJocActual_movimentsJaRealitzats.size()>0){ |
| 1303 | solucionaJocActual_movimentsJaRealitzats.removeAt |
| 1304 | (solucionaJocActual_movimentsJaRealitzats.size()-1); |
| 1305 | } |
| 1306 | qApp->processEvents(); |
| 1307 | } |
| 1308 | solucionaJocActual_darrerMoviment=solucionaJocActual_movimentsJaRealitzats.value( |
| 1309 | solucionaJocActual_movimentsJaRealitzats.size()-contadorMovimentsRevertits); |
| 1310 | |
| 1311 | /* S'aplica el procediment més lent de la versió 2.0*/ |
| 1312 | if (cercaSolucioAPartirDeMovimentsInicials && |
| 1313 | // (contadorSenseMoviments>maximNombreIntentsSenseMoviment) && |
| 1314 | ( reinicia ) && |
| 1315 | retrocedeixMoviment != 0 |
| 1316 | && ((numeroMovimentsProvats % numMovimentsPerReiniciar) == 0) |
| 1317 | ){ |
| 1318 | contadorSenseMoviments=0; |
| 1319 | maximNombreIntentsSenseMoviment--; |
| 1320 | /* Es retorna a la posició de fitxes inicials*/ |
| 1321 | int contadorRetroces=0; |
| 1322 | while (movimentsUndoStack->canRedo() && contadorRetroces<retrocedeixMoviment){ |
| 1323 | movimentsUndoStack->undo(); |
| 1324 | contadorRetroces++; |
| 1325 | progres.setValue(movimentsUndoStack->index()-1); |
| 1326 | progres.setLabelText(missatgeNumeroMoviments(taulerJoc->numeroDeMovimentsJoc())); |
| 1327 | if (solucionaJocActual_movimentsJaRealitzats.size()>0){ |
| 1328 | solucionaJocActual_movimentsJaRealitzats.removeAt |
| 1329 | (solucionaJocActual_movimentsJaRealitzats.size()-1); |
| 1330 | } |
| 1331 | qApp->processEvents(); |
| 1332 | } |
| 1333 | /* iniciSolucioSlot(); |
| 1334 | solucionaJocActual_movimentsJaRealitzats.clear(); |
| 1335 | solucionaJocActual_darrerMoviment.clear();*/ |
| 1336 | progres.setValue(0); |
| 1337 | progres.setLabelText(missatgeNumeroMoviments(taulerJoc->numeroDeMovimentsJoc())); |
| 1338 | reinicia=false; |
| 1339 | // qDebug("procediment 2.0"); |
| 1340 | } |
| 1341 | /*S'aplica el nou procediment més ràpid de la versió 2.1 |
| 1342 | *(que no conserva els moviments inicials)*/ |
| 1343 | else if ((!cercaSolucioAPartirDeMovimentsInicials) |
| 1344 | && (contadorSenseMoviments>maximNombreIntentsSenseMoviment) |
| 1345 | ){ |
| 1346 | //qDebug("/* Càrrega de nova solució */"); |
| 1347 | contadorSenseMoviments=0; |
| 1348 | /* Cada vegada que es carregui de nou una solució, |
| 1349 | * la pròxima es farà més aviat*/ |
| 1350 | maximNombreIntentsSenseMoviment--; |
| 1351 | maximNombreIntentsSenseMoviment=qMax(maximNombreIntentsSenseMoviment,30); |
| 1352 | // qDebug("maximNombreIntentsSenseMoviment %d", maximNombreIntentsSenseMoviment); |
| 1353 | iniciSolucioSlot(); |
| 1354 | solucionaJocActual_movimentsJaRealitzats.clear(); |
| 1355 | solucionaJocActual_darrerMoviment.clear(); |
| 1356 | progres.setValue(0); |
| 1357 | progres.setLabelText(missatgeNumeroMoviments(taulerJoc->numeroDeMovimentsJoc())); |
| 1358 | /* carrega d'una nova solució*/ |
| 1359 | solucionaJocActual_carregaSolucio1(); |
| 1360 | // qDebug("procediment 2.1"); |
| 1361 | //reinicia=false; |
| 1362 | } |
| 1363 | //} |
| 1364 | }//final if movimentsUndoStack->index() !=0 |
| 1365 | else{ //movimentsUndoStack->index() ==0 |
| 1366 | progres.cancel(); |
| 1367 | //27/01/11 |
| 1368 | //Això pot ésser que millori el tema dels problemes |
| 1369 | //en què el programa no aconsegueix trobar la solució |
| 1370 | solucionaJocActual_movimentsEliminats.clear(); |
| 1371 | statusBar()->showMessage(tr("No ha estat possible trobar una solució!")); |
| 1372 | /*04/02/11 |
| 1373 | Pareix que això disminueix la freqüència en què el programa |
| 1374 | no aconsegueix trobar la solució al joc |
| 1375 | */ |
| 1376 | eliminaArxiuConfgEliminades(); |
| 1377 | // desaConfiguracionsEliminades(); |
| 1378 | |
| 1379 | /* 06/02/11 |
| 1380 | Això evita que no es trobi una solució |
| 1381 | Continuam amb la recerca de solució |
| 1382 | */ |
| 1383 | if (intentsSolucio<4){ |
| 1384 | //qDebug("Intents de solució %d",intentsSolucio ); |
| 1385 | //Algunes vegades, el rellotge es queda aturat |
| 1386 | //Això ho soluciona? |
| 1387 | rellotgeLabel->reIniciaRellotge(); |
| 1388 | //qDebug("intentsSolucio %d", intentsSolucio); |
| 1389 | intentsSolucio++; |
| 1390 | movimentsUndoStack->clear(); |
| 1391 | //iniciSolucioSlot(); |
| 1392 | solucionaJocActual_movimentsEliminats.clear(); |
| 1393 | solucionaJocActual_Inicia(); |
| 1394 | } |
| 1395 | /*En el cas del solitaris generats a l'atzar |
| 1396 | *si no troba solució, forçam la càrrega de la solució |
| 1397 | *(la condició és necessària degut al plantejament de "problemes" |
| 1398 | *d'altres modalitats de solitari) |
| 1399 | */ |
| 1400 | else if ( solitariAtzar_esAtzar( |
| 1401 | arbreModalitatsJocTreeWidget->selectedItems().first()->text(1)) ){ |
| 1402 | //Seleccionam un ítem de solució a l'atzar |
| 1403 | qsrand(rellotgeQTime.msecsTo(QTime::currentTime())); |
| 1404 | int itemSeleccionat= |
| 1405 | qrand() % arbreSolucionsTreeWidget->topLevelItemCount(); |
| 1406 | QTreeWidgetItem *item= arbreSolucionsTreeWidget-> |
| 1407 | topLevelItem(itemSeleccionat); |
| 1408 | arbreSolucionsTreeWidget->setCurrentItem(item); |
| 1409 | carregaSolucio1(); |
| 1410 | rellotgeLabel->aturaRellotge(); |
| 1411 | } |
| 1412 | |
| 1413 | rellotgeLabel->aturaRellotge(); |
| 1414 | return; |
| 1415 | } |
| 1416 | } |
| 1417 | if (progres.wasCanceled()){ |
| 1418 | rellotgeLabel->aturaRellotge(); |
| 1419 | desaConfiguracionsEliminades(1); |
| 1420 | solucionaJocActual_movimentsJaRealitzats.clear(); |
| 1421 | solucionaJocActual_movimentsEliminats.clear(); |
| 1422 | break;} |
| 1423 | }//final while inicial |
| 1424 | |
| 1425 | |
| 1426 | /* S'ha trobat una solució*/ |
| 1427 | if (jocResolt==2){ |
| 1428 | rellotgeLabel->aturaRellotge(); |
| 1429 | //qDebug("contadorSenseMoviments %d",contadorSenseMoviments); |
| 1430 | progres.cancel(); |
| 1431 | desaSolucions(); |
| 1432 | // qDebug("num conf eliminades %d", solucioJocActual_configuracionsEliminades.count()); |
| 1433 | // qCritical("temps %s ", qPrintable(rellotgeLabel->retornaTemps(1))); |
| 1434 | desaConfiguracionsEliminades(1); |
| 1435 | solucionaJocActual_movimentsJaRealitzats.clear(); |
| 1436 | solucionaJocActual_movimentsEliminats.clear(); |
| 1437 | retrocedeixMoviment=0; |
| 1438 | veureSolucionsSlot(); |
| 1439 | intentsSolucio=0; |
| 1440 | /* Si es tracta d'un solitari personalitzat |
| 1441 | * o bé és un joc modificat (de l'arbre de jocs |
| 1442 | * del programa o de l'arbre de jocs personalitzats) |
| 1443 | * es desen les dades |
| 1444 | */ |
| 1445 | solucioJocActual_desarJocPersonalitzat(); |
| 1446 | // if( (solitariPersonalitzat_esPersonalitzat( |
| 1447 | // arbreModalitatsJocTreeWidget->selectedItems().first()->text(1)) |
| 1448 | // && arbreJocsActual()==0 ) |
| 1449 | // || ( taulerJoc->solitariPersonalitzat() ) || |
| 1450 | // ( taulerJoc->solitariModificat() ) ){ |
| 1451 | // //){ |
| 1452 | // // && (tipusJocActual==0 || arbreJocsActual()==1 ) ){ |
| 1453 | // solitariPersonalitzat_desarSolitari(); |
| 1454 | // } |
| 1455 | |
| 1456 | //Comentar les 3 següents linies per evitar la repetició de recerca de solució |
| 1457 | /* iniciSolucioSlot(); |
| 1458 | if(taulerJoc->estatDelJoc()==solucio){movimentsUndoStack->clear();} |
| 1459 | solucionaJocActual_Inicia();*/ |
| 1460 | return; |
| 1461 | }//final if jocResolt==2 |
| 1462 | } |
| 1463 | |
| 1464 | //Desa les dades del joc personalitzat/modificat a l'arxiu games_per.dat |
| 1465 | //i l'afageix a l'arbre de jocs personalitzats |
| 1466 | void frmPrincipal::solucioJocActual_desarJocPersonalitzat(){ |
| 1467 | if( (solitariPersonalitzat_esPersonalitzat( |
| 1468 | arbreModalitatsJocTreeWidget->selectedItems().first()->text(1)) |
| 1469 | && arbreJocsActual()==0 ) |
| 1470 | || ( taulerJoc->solitariPersonalitzat() ) || |
| 1471 | ( taulerJoc->solitariModificat() ) ){ |
| 1472 | //){ |
| 1473 | // && (tipusJocActual==0 || arbreJocsActual()==1 ) ){ |
| 1474 | solitariPersonalitzat_desarSolitari(); |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | void frmPrincipal::solucionaJocActual_eliminaMovimentsPosteriors(){ |
| 1479 | QStringList *darrerMoviment =new QStringList(solucionaJocActual_darrerMoviment.split(" ")); |
| 1480 | QStringList *darrerMovimentEliminat=new QStringList(solucionaJocActual_movimentsEliminats.value( |
| 1481 | solucionaJocActual_movimentsEliminats.size()-1).split(" ")); |
| 1482 | while (darrerMovimentEliminat->value(0).toInt()>darrerMoviment->value(0).toInt()){ |
| 1483 | solucionaJocActual_movimentsEliminats.removeAt(solucionaJocActual_movimentsEliminats.size()-1); |
| 1484 | darrerMovimentEliminat->clear(); |
| 1485 | darrerMovimentEliminat->append(solucionaJocActual_movimentsEliminats.value( |
| 1486 | solucionaJocActual_movimentsEliminats.size()-1).split(" ")); |
| 1487 | } |
| 1488 | delete(darrerMoviment); |
| 1489 | delete(darrerMovimentEliminat); |
| 1490 | } |
| 1491 | |
| 1492 | void frmPrincipal::solucionaJocActual_eliminaConfiguracionsPosteriors(QString config){ |
| 1493 | |
| 1494 | if (solucioJocActual_configuracionsEliminadesPerDesar.count()==0){ |
| 1495 | return;} |
| 1496 | int numConfiguracio=numeroConfiguracio(config); |
| 1497 | if(taulerJoc->p_tipusMoviment !=2){ |
| 1498 | while ( (numeroConfiguracio(solucioJocActual_configuracionsEliminadesPerDesar.value( |
| 1499 | solucioJocActual_configuracionsEliminadesPerDesar.count()-1))<numConfiguracio) && |
| 1500 | (solucioJocActual_configuracionsEliminadesPerDesar.count()>0) ){ |
| 1501 | solucioJocActual_configuracionsEliminadesPerDesar.removeLast();} |
| 1502 | } |
| 1503 | else{ |
| 1504 | while ( (numeroConfiguracio(solucioJocActual_configuracionsEliminadesPerDesar.value( |
| 1505 | solucioJocActual_configuracionsEliminadesPerDesar.count()-1))>numConfiguracio) && |
| 1506 | (solucioJocActual_configuracionsEliminadesPerDesar.count()>0) ){ |
| 1507 | solucioJocActual_configuracionsEliminadesPerDesar.removeLast();} |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | /*Retorna el nombre de fitxes del joc*/ |
| 1512 | int frmPrincipal::solucionaJocActual_numeroDeFitxesDelJoc(){ |
| 1513 | QString configActual=taulerJoc->configuracioActual(true); |
| 1514 | int numeroFitxesJoc; |
| 1515 | if (taulerJoc->p_tipusMoviment==2){ |
| 1516 | numeroFitxesJoc=configActual.count("0")+movimentsUndoStack->count(); |
| 1517 | } |
| 1518 | else numeroFitxesJoc=configActual.count("1")+movimentsUndoStack->count(); |
| 1519 | return numeroFitxesJoc; |
| 1520 | } |
| 1521 | |
| 1522 | void frmPrincipal::solucionaJocActual_RecercaIterativa_ExhaustivaInici(int numFitxesInicialsJoc, |
| 1523 | int mantenirMoviment){ |
| 1524 | // qDebug("RecercaIterativa_ExhaustivaInici 2.1"); |
| 1525 | |
| 1526 | //Cal saber si és un joc personalitzat |
| 1527 | solucionaJocActual_ControlJocPersonalitzatModificat(); |
| 1528 | |
| 1529 | /*eliminam l'arxiu de moviments .movi per fer el seguiment del joc*/ |
| 1530 | //eliminaArxiuMovimentsJoc(); |
| 1531 | qApp->processEvents(); |
| 1532 | QProgressDialog *progresRecercaExahustiva =new QProgressDialog(this);; |
| 1533 | progresRecercaExahustiva->setLabelText(tr("Cercant solució")); |
| 1534 | progresRecercaExahustiva->setCancelButtonText(tr("Atura")); |
| 1535 | progresRecercaExahustiva->setMinimum(0); |
| 1536 | // progresRecercaExahustiva->setMaximum(taulerJoc->numeroDeMovimentsJoc()+retrocedeixMoviment); |
| 1537 | progresRecercaExahustiva->setMaximum(numFitxesInicialsJoc); |
| 1538 | progresRecercaExahustiva->setParent(this); |
| 1539 | qApp->processEvents(); |
| 1540 | progresRecercaExahustiva->setWindowModality(Qt::WindowModal); |
| 1541 | progresRecercaExahustiva->setVisible(true); |
| 1542 | rellotgeLabel->iniciaRellotge(); |
| 1543 | qApp->processEvents(); |
| 1544 | int intentsSolucio=0; |
| 1545 | int numeroMaximDeIntents=500; |
| 1546 | |
| 1547 | |
| 1548 | while( (jocResolt !=2) && (!progresRecercaExahustiva->wasCanceled()) && |
| 1549 | (intentsSolucio<numeroMaximDeIntents) ){ |
| 1550 | intentsSolucio++; |
| 1551 | // qDebug("intentsSolucio++ %d", intentsSolucio); |
| 1552 | iniciSolucioSlotIndex(retrocedeixMoviment); |
| 1553 | //Jocs en diagonal |
| 1554 | if( taulerJoc->p_tipusMoviment==3){ |
| 1555 | //Especial Solitari Estrella |
| 1556 | if(numFitxesInicialsJoc==23 || numFitxesInicialsJoc<15){ |
| 1557 | // qDebug("diagonal"); |
| 1558 | progresRecercaExahustiva->setMaximum(numFitxesInicialsJoc); |
| 1559 | taulerJoc->solucionaJocActual_CalculaArbreJoc(progresRecercaExahustiva, numFitxesInicialsJoc, |
| 1560 | mantenirMoviment);} |
| 1561 | else { |
| 1562 | //Això és una mica estrany, però evita un problema amb el joc Anglès Antic |
| 1563 | //amb final marcat |
| 1564 | // qDebug("sdsds"); |
| 1565 | progresRecercaExahustiva->setMaximum(numFitxesInicialsJoc); |
| 1566 | solucionaJocActual_RecercaIterativa_Exhaustiva1(progresRecercaExahustiva, |
| 1567 | numFitxesInicialsJoc); |
| 1568 | } |
| 1569 | } |
| 1570 | //Jocs amb final marcat que no es poden resoldre sense carregar solucions |
| 1571 | //(només son un parell jocs!) |
| 1572 | else if (taulerJoc->jocAmbFinalMarcat()>10){ |
| 1573 | // qDebug("aqui 2"); |
| 1574 | taulerJoc->maximNombreDeProves=1000; |
| 1575 | progresRecercaExahustiva->setMaximum(numFitxesInicialsJoc); |
| 1576 | taulerJoc->solucionaJocActual_CalculaArbreJocComplet_Selectiu(progresRecercaExahustiva, |
| 1577 | numFitxesInicialsJoc, |
| 1578 | mantenirMoviment); |
| 1579 | taulerJoc->jocsRealitzats=0; |
| 1580 | taulerJoc->continuar=true; |
| 1581 | } |
| 1582 | //Jocs amb final marcat amb menys de 10 fitxes finals |
| 1583 | //i més d'una (no es fa servir) |
| 1584 | else if (taulerJoc->jocAmbFinalMarcat()<=10 && |
| 1585 | taulerJoc->jocAmbFinalMarcat()>1 ){ |
| 1586 | // qDebug("aqui 1"); |
| 1587 | progresRecercaExahustiva->setMaximum(numFitxesInicialsJoc); |
| 1588 | solucionaJocActual_RecercaIterativa_Exhaustiva1(progresRecercaExahustiva, |
| 1589 | numFitxesInicialsJoc); |
| 1590 | } |
| 1591 | else if ( |
| 1592 | ((numFitxesInicialsJoc>20 && numFitxesInicialsJoc<=28) //28 |
| 1593 | || (numFitxesInicialsJoc<16)) |
| 1594 | && (taulerJoc->jocAmbFinalMarcat()==0) |
| 1595 | ){ |
| 1596 | //això funciona! |
| 1597 | // qDebug("sense final marcat"); |
| 1598 | progresRecercaExahustiva->setMaximum(numFitxesInicialsJoc); |
| 1599 | taulerJoc->solucionaJocActual_CalculaArbreJoc(progresRecercaExahustiva, numFitxesInicialsJoc, |
| 1600 | mantenirMoviment); |
| 1601 | } |
| 1602 | //La majoria de jocs de tipus clàssic i europeu |
| 1603 | //Inclou els jocs amb 1 fitxa final marcada |
| 1604 | else if ( (numFitxesInicialsJoc>15 && numFitxesInicialsJoc<40) |
| 1605 | || (taulerJoc->jocAmbFinalMarcat()>0)){ |
| 1606 | // qDebug("aqui"); |
| 1607 | if(numFitxesInicialsJoc<=35){//25 |
| 1608 | taulerJoc->maximNombreDeProves=1000;} |
| 1609 | progresRecercaExahustiva->setMaximum(numFitxesInicialsJoc); |
| 1610 | taulerJoc->solucionaJocActual_CalculaArbreJocComplet_Selectiu(progresRecercaExahustiva, |
| 1611 | numFitxesInicialsJoc, |
| 1612 | mantenirMoviment); |
| 1613 | // qDebug("jocsRealitzats %d", taulerJoc->jocsRealitzats); |
| 1614 | taulerJoc->jocsRealitzats=0; |
| 1615 | taulerJoc->continuar=true; |
| 1616 | } |
| 1617 | //Jocs amb més de 40 moviments |
| 1618 | else solucionaJocActual_RecercaIterativa_Exhaustiva1(progresRecercaExahustiva, |
| 1619 | numFitxesInicialsJoc); |
| 1620 | }//final while |
| 1621 | |
| 1622 | if (jocResolt==2){ |
| 1623 | progresRecercaExahustiva->cancel(); |
| 1624 | progresRecercaExahustiva->setVisible(false); |
| 1625 | rellotgeLabel->aturaRellotge(); |
| 1626 | // qCritical("%s",qPrintable(rellotgeLabel->retornaTemps(1))); |
| 1627 | qApp->processEvents(); |
| 1628 | desaSolucions1(); |
| 1629 | // retrocedeixMoviment=0; |
| 1630 | veureSolucionsSlot(); |
| 1631 | /* Si es tracta d'un solitari personalitzat |
| 1632 | * o bé és un joc modificat (de l'arbre de jocs |
| 1633 | * del programa o de l'arbre de jocs personalitzats) |
| 1634 | * es desen les dades |
| 1635 | */ |
| 1636 | solucioJocActual_desarJocPersonalitzat(); |
| 1637 | } |
| 1638 | else { |
| 1639 | if(retrocedeixMoviment>0){ |
| 1640 | //Retorna las fitxes a la posició inicial |
| 1641 | movimentsUndoStack->setIndex(retrocedeixMoviment); |
| 1642 | } |
| 1643 | //Un darrer intent de resoldre el joc carregant solucions |
| 1644 | if(!progresRecercaExahustiva->wasCanceled()){ |
| 1645 | progresRecercaExahustiva->cancel(); |
| 1646 | if(comprovaArxiuDeSolucions()){ |
| 1647 | retrocedeixMoviment=0; |
| 1648 | solucionaJocActual_carregaSolucio(); |
| 1649 | solucionaJocActual_Inicia(); |
| 1650 | } |
| 1651 | else { |
| 1652 | rellotgeLabel->aturaRellotge(); |
| 1653 | statusBar()->showMessage(tr("No ha estat possible trobar una solució!")); |
| 1654 | } |
| 1655 | } |
| 1656 | else { |
| 1657 | rellotgeLabel->aturaRellotge(); |
| 1658 | progresRecercaExahustiva->cancel(); |
| 1659 | statusBar()->showMessage(tr("No ha estat possible trobar una solució!")); |
| 1660 | } |
| 1661 | |
| 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | // Finalment, no es fa servir |
| 1666 | //void frmPrincipal::solucionaJocActual_RecercaIterativa_Exhaustiva(QProgressDialog *progres, int profunditat, |
| 1667 | // int numeroInicialFitxesJoc, |
| 1668 | // variables_recerca_solucio variablesSolucio){ |
| 1669 | // /* Carregam els moviments inicials*/ |
| 1670 | // profunditat++; |
| 1671 | //// taulerJoc->solucionaJocActual_CalculaMovimentsPosibles(); |
| 1672 | // QStringList solucionaJocActual_movimentsPosiblesActuals1; |
| 1673 | // /* Carregam els moviments seleccionats per la posició actual de les fitxes*/ |
| 1674 | // if(taulerJoc->p_tipusMoviment==3 && taulerJoc->numeroDeMovimentsJoc()>30){ |
| 1675 | // solucionaJocActual_movimentsPosiblesActuals1.append( |
| 1676 | // taulerJoc->solucionaJocActual_CarregaMovimentsArbre4(numeroInicialFitxesJoc)); |
| 1677 | //// taulerJoc->solucionaJocActual_CarregaMovimentsArbre2(numeroInicialFitxesJoc,variablesSolucio)); |
| 1678 | // } |
| 1679 | // /*Solitari estrella*/ |
| 1680 | // else if(taulerJoc->p_tipusMoviment==3 && taulerJoc->numeroDeMovimentsJoc()<=30){ |
| 1681 | // solucionaJocActual_movimentsPosiblesActuals1.append( |
| 1682 | // taulerJoc->solucionaJocActual_CarregaMovimentsArbre3(numeroInicialFitxesJoc,variablesSolucio)); |
| 1683 | // } |
| 1684 | // else if (taulerJoc->numeroDeMovimentsJoc()<15){ |
| 1685 | // solucionaJocActual_movimentsPosiblesActuals1.append( |
| 1686 | // taulerJoc->solucionaJocActual_CarregaMovimentsArbre2(numeroInicialFitxesJoc,variablesSolucio)); |
| 1687 | // } |
| 1688 | // else solucionaJocActual_movimentsPosiblesActuals1.append( |
| 1689 | // taulerJoc->solucionaJocActual_CarregaMovimentsArbre2(numeroInicialFitxesJoc,variablesSolucio)); |
| 1690 | |
| 1691 | // if(jocResolt == 2){ |
| 1692 | // qDebug("El joc està resolt"); |
| 1693 | // progres->cancel(); |
| 1694 | // } |
| 1695 | // else { |
| 1696 | // /*Fins que el joc no estigui resolt o bé s'aturi la recerca, es repeteix el mateix |
| 1697 | // * procediment*/ |
| 1698 | // while ( (jocResolt != 2) |
| 1699 | // && (solucionaJocActual_movimentsPosiblesActuals1.count()>0) |
| 1700 | // && (!progres->wasCanceled()) |
| 1701 | // ){ |
| 1702 | |
| 1703 | // bool fetMoviment=false; |
| 1704 | // int contadorMoviments=0; |
| 1705 | // for(int i=0;i<solucionaJocActual_movimentsPosiblesActuals1.count();i++){ |
| 1706 | //// for(int i=0;i<nombreDeMoviments;i++){ |
| 1707 | // /*Seleccionam un dels moviments i el realitzam*/ |
| 1708 | // int movimentSeleccionat=qrand() % solucionaJocActual_movimentsPosiblesActuals1.count(); |
| 1709 | // QStringList movimentsItem=QStringList(solucionaJocActual_movimentsPosiblesActuals1 |
| 1710 | // .value((movimentSeleccionat+i) % solucionaJocActual_movimentsPosiblesActuals1.count()).split(" ")); |
| 1711 | |
| 1712 | // fetMoviment=false; |
| 1713 | // if ((jocResolt != 2) && (!progres->wasCanceled()) ){ |
| 1714 | // if (i==0 ){ |
| 1715 | // fetMoviment=taulerJoc->ferMoviment2(movimentsItem.value(0).toInt() |
| 1716 | // ,movimentsItem.value(1).toInt(),movimentsItem.value(2).toInt()); |
| 1717 | // } |
| 1718 | // else if ( |
| 1719 | // (taulerJoc->numeroDeMovimentsJoc()>15 && movimentsUndoStack->index()<40) //movimentsUndoStack->index()<28) |
| 1720 | // ){ |
| 1721 | // fetMoviment=taulerJoc->ferMoviment2(movimentsItem.value(0).toInt() |
| 1722 | // ,movimentsItem.value(1).toInt(),movimentsItem.value(2).toInt()); |
| 1723 | // } |
| 1724 | // /*Eliminam el moviment que no funciona (per evitar la repetició)*/ |
| 1725 | // if(fetMoviment ){ |
| 1726 | // contadorMoviments++; |
| 1727 | // if (i==0 ){ |
| 1728 | // solucionaJocActual_movimentsPosiblesActuals1. |
| 1729 | // removeAt((movimentSeleccionat+i) % solucionaJocActual_movimentsPosiblesActuals1.count()); |
| 1730 | // } |
| 1731 | // else if (taulerJoc->numeroDeMovimentsJoc()>15 && movimentsUndoStack->index()<40) |
| 1732 | // { |
| 1733 | // solucionaJocActual_movimentsPosiblesActuals1. |
| 1734 | // removeAt((movimentSeleccionat+i) % solucionaJocActual_movimentsPosiblesActuals1.count()); |
| 1735 | // } |
| 1736 | // } |
| 1737 | // } |
| 1738 | // progres->setValue(movimentsUndoStack->count()); |
| 1739 | // progres->setLabelText(missatgeNumeroMoviments(progres->maximum())); |
| 1740 | // qApp->processEvents(); |
| 1741 | // } |
| 1742 | // //qDebug("contador %d", contadorMoviments); |
| 1743 | // /*Si el joc segueix sense està resolt i no s'ha cancel·lat la recerca |
| 1744 | // * es segueix amb la recerca iterativa*/ |
| 1745 | // if( (jocResolt != 2) && (!progres->wasCanceled()) ){ |
| 1746 | // solucionaJocActual_RecercaIterativa_Exhaustiva(progres, profunditat,numeroInicialFitxesJoc,variablesSolucio); |
| 1747 | // } |
| 1748 | |
| 1749 | |
| 1750 | // /*Si el codi torna aquí, llavors tornam enrera el moviment*/ |
| 1751 | // if( (jocResolt != 2) && (!progres->wasCanceled())){ |
| 1752 | // for(int i=0;i<contadorMoviments;i++){ |
| 1753 | // movimentsUndoStack->undo(); |
| 1754 | // } |
| 1755 | //// movimentsUndoStack->undo(); |
| 1756 | // progres->setValue(movimentsUndoStack->index()); |
| 1757 | // progres->setLabelText(missatgeNumeroMoviments(progres->maximum())); |
| 1758 | // qApp->processEvents(); |
| 1759 | // } |
| 1760 | |
| 1761 | // /*Si no queden més moviments per provar, cancel·lam la recerca*/ |
| 1762 | //// if(solucionaJocActual_movimentsPosiblesActuals1.count()<1){ |
| 1763 | //// //qDebug("Joc cancelat per manca de moviments*****"); |
| 1764 | //// //progres->cancel(); |
| 1765 | //// } |
| 1766 | // if (progres->wasCanceled()){ |
| 1767 | // rellotgeLabel->aturaRellotge(); |
| 1768 | // qApp->processEvents(); |
| 1769 | // break;} |
| 1770 | // }//final del while |
| 1771 | |
| 1772 | ///*El joc està resolt. Asseguram que el progres queda tancat*/ |
| 1773 | // if(jocResolt == 2){ |
| 1774 | // //qDebug("El joc està resolt"); |
| 1775 | // progres->cancel(); |
| 1776 | // } |
| 1777 | // } |
| 1778 | //} |
| 1779 | |
| 1780 | void frmPrincipal::solucionaJocActual_RecercaIterativa_Exhaustiva1(QProgressDialog *progres, |
| 1781 | int numeroFitxesJoc){ |
| 1782 | |
| 1783 | /* Carregam els moviments inicials*/ |
| 1784 | QStringList solucionaJocActual_movimentsPosiblesActuals1; |
| 1785 | /* Carregam els moviments seleccionats per la posició actual de les fitxes*/ |
| 1786 | solucionaJocActual_movimentsPosiblesActuals1.append( |
| 1787 | taulerJoc->solucionaJocActual_CarregaMovimentsArbre4(numeroFitxesJoc)); |
| 1788 | |
| 1789 | /*Fins que el joc no estigui resolt o bé s'aturi la recerca, es repeteix el mateix |
| 1790 | * procediment*/ |
| 1791 | while ( (jocResolt != 2) |
| 1792 | && (solucionaJocActual_movimentsPosiblesActuals1.count()>0) |
| 1793 | && (!progres->wasCanceled() |
| 1794 | /*&& taulerJoc->ocuparFitxesFinalJoc()*/) |
| 1795 | ){ |
| 1796 | /*Seleccionam un dels moviments i el realitzam*/ |
| 1797 | // int movimentSeleccionat=0; |
| 1798 | int movimentSeleccionat=qrand() % solucionaJocActual_movimentsPosiblesActuals1.count(); |
| 1799 | QStringList movimentsItem=QStringList(solucionaJocActual_movimentsPosiblesActuals1 |
| 1800 | .value((movimentSeleccionat) % solucionaJocActual_movimentsPosiblesActuals1.count()).split(" ")); |
| 1801 | bool movimentFet=taulerJoc->ferMoviment2(movimentsItem.value(0).toInt() |
| 1802 | ,movimentsItem.value(1).toInt(),movimentsItem.value(2).toInt()); |
| 1803 | // if(movimentFet){ |
| 1804 | solucionaJocActual_movimentsPosiblesActuals1. |
| 1805 | removeAt((movimentSeleccionat) % solucionaJocActual_movimentsPosiblesActuals1.count());/*}*/ |
| 1806 | // progres->setValue(movimentsUndoStack->count()); |
| 1807 | if(movimentsUndoStack->index()<progres->maximum()){ |
| 1808 | progres->setValue(movimentsUndoStack->index()); |
| 1809 | progres->setLabelText(missatgeNumeroMoviments(progres->maximum())); |
| 1810 | } |
| 1811 | // progres->setLabelText(missatgeNumeroMoviments(numeroFitxesJoc-1)); |
| 1812 | qApp->processEvents(); |
| 1813 | /*Si el joc segueix sense estar resolt i no s'ha cancel·lat la recerca |
| 1814 | * es segueix amb la recerca iterativa*/ |
| 1815 | if( (jocResolt != 2) && (!progres->wasCanceled()) ){ |
| 1816 | solucionaJocActual_RecercaIterativa_Exhaustiva1(progres, |
| 1817 | numeroFitxesJoc); |
| 1818 | } |
| 1819 | |
| 1820 | /*Si el codi torna aquí, llavors tornam enrera el moviment*/ |
| 1821 | if( (jocResolt != 2) && (!progres->wasCanceled()) && movimentFet){ |
| 1822 | movimentsUndoStack->undo(); |
| 1823 | // progres->setValue(movimentsUndoStack->count()); |
| 1824 | // progres->setValue(movimentsUndoStack->index()); |
| 1825 | // progres->setLabelText(missatgeNumeroMoviments(progres->maximum())); |
| 1826 | qApp->processEvents(); |
| 1827 | } |
| 1828 | |
| 1829 | if (progres->wasCanceled()){ |
| 1830 | // progres->setVisible(false); |
| 1831 | rellotgeLabel->aturaRellotge(); |
| 1832 | qApp->processEvents(); |
| 1833 | break;} |
| 1834 | }//final del while |
| 1835 | |
| 1836 | /*El joc està resolt. Asseguram que el progrés queda tancat*/ |
| 1837 | if(jocResolt == 2){ |
| 1838 | //qDebug("El joc està resolt"); |
| 1839 | // progres->setVisible(false); |
| 1840 | progres->cancel(); |
| 1841 | } |
| 1842 | } |
| 1843 | |
| 1844 | |
| 1845 | //variables_recerca_solucio frmPrincipal::solucioJocActual_carregaVariablesCercaSolucio(int numeroInicialFitxesJoc){ |
| 1846 | // variables_recerca_solucio variablesRecercaSolucio; |
| 1847 | // if(taulerJoc->p_tipusMoviment==3){ //moviment diagonal |
| 1848 | // variablesRecercaSolucio.maximNumeroDeConjunts=6; |
| 1849 | // variablesRecercaSolucio.maximNumeroDeFitxesAillades=2;//2 |
| 1850 | // variablesRecercaSolucio.minimIndexDeMoviments=40;//15 |
| 1851 | // variablesRecercaSolucio.minimNumeroDeConjuntsActual=3;//3 |
| 1852 | // variablesRecercaSolucio.minimNumeroDeFitxesAilladesActual=2;//2 |
| 1853 | // variablesRecercaSolucio.minimIndexMovimentsPerFiltrarMovimentsSeleccionats=40; |
| 1854 | // variablesRecercaSolucio.valorMinimIndexDeMovimentsPerMovimentsMassius=60;//60 |
| 1855 | // variablesRecercaSolucio.valorMinimMovimentsJoc=15; |
| 1856 | // if(numeroInicialFitxesJoc<33){ |
| 1857 | // variablesRecercaSolucio.maximNumeroDeConjunts=2; |
| 1858 | // variablesRecercaSolucio.maximNumeroDeFitxesAillades=1; |
| 1859 | // variablesRecercaSolucio.minimNumeroDeConjuntsActual=2; |
| 1860 | // variablesRecercaSolucio.minimNumeroDeFitxesAilladesActual=1; |
| 1861 | // } |
| 1862 | // } |
| 1863 | // else if(taulerJoc->p_tipusMoviment==1){ //moviment directe |
| 1864 | // if(numeroInicialFitxesJoc<18){//amb poques fitxes |
| 1865 | // variablesRecercaSolucio.maximNumeroDeConjunts=3;//<= |
| 1866 | // variablesRecercaSolucio.maximNumeroDeFitxesAillades=3; |
| 1867 | // variablesRecercaSolucio.minimIndexDeMoviments=0;//valor a partir del qual s'intenta trobar moviments |
| 1868 | // //que disminueixin el nombre de conjunts i/o de fitxes aïllades 5 |
| 1869 | // variablesRecercaSolucio.minimNumeroDeConjuntsActual=1;//>3 |
| 1870 | // variablesRecercaSolucio.minimNumeroDeFitxesAilladesActual=0;//>5 |
| 1871 | // variablesRecercaSolucio.minimIndexMovimentsPerFiltrarMovimentsSeleccionats=20;//28 |
| 1872 | // variablesRecercaSolucio.valorMinimIndexDeMovimentsPerMovimentsMassius=18; |
| 1873 | // variablesRecercaSolucio.valorMinimMovimentsJoc=0; |
| 1874 | // } |
| 1875 | // else if(numeroInicialFitxesJoc>40){//Wiegleb |
| 1876 | // variablesRecercaSolucio.maximNumeroDeConjunts=2; |
| 1877 | // variablesRecercaSolucio.maximNumeroDeFitxesAillades=1; |
| 1878 | // variablesRecercaSolucio.minimIndexDeMoviments=30;//valor a partir del qual s'intenta trobar moviments |
| 1879 | // //que disminueixin el nombre de conjunts i/o de fitxes aïllades 5 |
| 1880 | // variablesRecercaSolucio.minimNumeroDeConjuntsActual=1; |
| 1881 | // variablesRecercaSolucio.minimNumeroDeFitxesAilladesActual=0; |
| 1882 | // variablesRecercaSolucio.minimIndexMovimentsPerFiltrarMovimentsSeleccionats=20; |
| 1883 | // variablesRecercaSolucio.valorMinimIndexDeMovimentsPerMovimentsMassius=0;//60 |
| 1884 | // variablesRecercaSolucio.valorMaximIndexDeMovimentsPerMovimentsMassius=10; |
| 1885 | // variablesRecercaSolucio.valorMinimMovimentsJoc=15; |
| 1886 | // } |
| 1887 | |
| 1888 | // else if (numeroInicialFitxesJoc>38){// Diamant |
| 1889 | // variablesRecercaSolucio.maximNumeroDeConjunts=1; |
| 1890 | // variablesRecercaSolucio.maximNumeroDeFitxesAillades=1;//2 |
| 1891 | // variablesRecercaSolucio.minimIndexDeMoviments=35; |
| 1892 | // variablesRecercaSolucio.minimNumeroDeConjuntsActual=3;//3 |
| 1893 | // variablesRecercaSolucio.minimNumeroDeFitxesAilladesActual=2;//2 |
| 1894 | // variablesRecercaSolucio.minimIndexMovimentsPerFiltrarMovimentsSeleccionats=10;//15 |
| 1895 | // variablesRecercaSolucio.valorMinimIndexDeMovimentsPerMovimentsMassius=0;//60; |
| 1896 | // variablesRecercaSolucio.valorMinimMovimentsJoc=15; |
| 1897 | //// variablesRecercaSolucio.maximNumeroDeConjunts=3; |
| 1898 | //// variablesRecercaSolucio.maximNumeroDeFitxesAillades=2; |
| 1899 | //// variablesRecercaSolucio.minimIndexDeMoviments=0; |
| 1900 | //// variablesRecercaSolucio.minimNumeroDeConjuntsActual=2; |
| 1901 | //// variablesRecercaSolucio.minimNumeroDeFitxesAilladesActual=0; |
| 1902 | //// variablesRecercaSolucio.minimIndexMovimentsPerFiltrarMovimentsSeleccionats=40; |
| 1903 | //// variablesRecercaSolucio.valorMinimIndexDeMovimentsPerMovimentsMassius=40;//30 |
| 1904 | //// variablesRecercaSolucio.valorMinimMovimentsJoc=15; |
| 1905 | // } |
| 1906 | // else if (numeroInicialFitxesJoc>33){// Europeu |
| 1907 | // variablesRecercaSolucio.maximNumeroDeConjunts=1;//2 |
| 1908 | // variablesRecercaSolucio.maximNumeroDeFitxesAillades=0;//3 |
| 1909 | // variablesRecercaSolucio.minimIndexDeMoviments=30;// 30 o 36 |
| 1910 | // variablesRecercaSolucio.minimNumeroDeConjuntsActual=1;//>3 |
| 1911 | // variablesRecercaSolucio.minimNumeroDeFitxesAilladesActual=0; |
| 1912 | // variablesRecercaSolucio.minimIndexMovimentsPerFiltrarMovimentsSeleccionats=30; |
| 1913 | // variablesRecercaSolucio.valorMinimIndexDeMovimentsPerMovimentsMassius=0;//30 |
| 1914 | // variablesRecercaSolucio.valorMinimMovimentsJoc=15; |
| 1915 | //// variablesRecercaSolucio.maximNumeroDeConjunts=2;//2 |
| 1916 | //// variablesRecercaSolucio.maximNumeroDeFitxesAillades=2; |
| 1917 | //// variablesRecercaSolucio.minimIndexDeMoviments=15;//15 30 |
| 1918 | //// variablesRecercaSolucio.minimNumeroDeConjuntsActual=1;//>3 |
| 1919 | //// variablesRecercaSolucio.minimNumeroDeFitxesAilladesActual=0; |
| 1920 | //// variablesRecercaSolucio.minimIndexMovimentsPerFiltrarMovimentsSeleccionats=0; |
| 1921 | //// variablesRecercaSolucio.valorMinimIndexDeMovimentsPerMovimentsMassius=30; |
| 1922 | //// variablesRecercaSolucio.valorMinimMovimentsJoc=15; |
| 1923 | // } |
| 1924 | // else{ |
| 1925 | // variablesRecercaSolucio.maximNumeroDeConjunts=qMax(2,1+taulerJoc->solucionaJocActual_numeroFitxesAillades()); |
| 1926 | // variablesRecercaSolucio.maximNumeroDeFitxesAillades=qMax(1,taulerJoc->solucionaJocActual_numeroFitxesAillades()); |
| 1927 | // variablesRecercaSolucio.minimIndexDeMoviments=15;//valor a partir del qual s'intenta trobar moviments |
| 1928 | // //que disminueixin el nombre de conjunts i/o de fitxes aïllades 5 |
| 1929 | // variablesRecercaSolucio.minimNumeroDeConjuntsActual=1;//>3 |
| 1930 | // variablesRecercaSolucio.minimNumeroDeFitxesAilladesActual=qMax(0,taulerJoc->solucionaJocActual_numeroFitxesAillades()); |
| 1931 | // variablesRecercaSolucio.minimIndexMovimentsPerFiltrarMovimentsSeleccionats=10; |
| 1932 | // if(numeroInicialFitxesJoc<30){ |
| 1933 | // variablesRecercaSolucio.minimIndexMovimentsPerFiltrarMovimentsSeleccionats=10; |
| 1934 | // } |
| 1935 | // variablesRecercaSolucio.valorMinimIndexDeMovimentsPerMovimentsMassius=15; |
| 1936 | // variablesRecercaSolucio.valorMinimMovimentsJoc=15; |
| 1937 | // } |
| 1938 | // } |
| 1939 | |
| 1940 | //// qDebug("maximNumeroDeConjunts %d", variablesRecercaSolucio.maximNumeroDeConjunts); |
| 1941 | //// qDebug("maximNumeroDeFitxesAillades %d", variablesRecercaSolucio.maximNumeroDeFitxesAillades); |
| 1942 | //// qDebug("minimIndexDeMoviments %d", variablesRecercaSolucio.minimIndexDeMoviments); |
| 1943 | //// qDebug("minimNumeroDeConjuntsActual %d", variablesRecercaSolucio.minimNumeroDeConjuntsActual); |
| 1944 | //// qDebug("minimNumeroDeFitxesAilladesActual %d", variablesRecercaSolucio.minimNumeroDeFitxesAilladesActual); |
| 1945 | //// qDebug("minimIndexMovimentsPerFiltrarMovimentsSeleccionats %d", variablesRecercaSolucio.minimIndexMovimentsPerFiltrarMovimentsSeleccionats); |
| 1946 | //// qDebug("valorMaximIndexDeMovimentsPerMovimentsMassius %d", variablesRecercaSolucio.valorMaximIndexDeMovimentsPerMovimentsMassius); |
| 1947 | //// qDebug("valorMinimIndexDeMovimentsPerMovimentsMassius %d", variablesRecercaSolucio.valorMinimIndexDeMovimentsPerMovimentsMassius); |
| 1948 | //// qDebug("valorMinimMovimentsJoc %d", variablesRecercaSolucio.valorMinimMovimentsJoc); |
| 1949 | // return variablesRecercaSolucio; |
| 1950 | //} |
| 1951 | |
| 1952 | /* Escriu el moviment realitzat en la recerca a un arxiu i a la finestra de sortides |
| 1953 | * del programa per facilitar el seguiment del joc |
| 1954 | No es fa servir però pot ésser útil */ |
| 1955 | void frmPrincipal::solucioJocActual_RecercaIterativa_escriuDesaMovimentRealitzat(int tabulacio,QString cadenaMoviment){ |
| 1956 | QString buits; |
| 1957 | int contador=0; |
| 1958 | while(contador< tabulacio){ |
| 1959 | buits.append(" "); |
| 1960 | contador++; |
| 1961 | } |
| 1962 | qCritical("%s",qPrintable(buits+cadenaMoviment)); |
| 1963 | desaMovimentsJoc(buits+cadenaMoviment+QString(" %1").arg(tabulacio)); |
| 1964 | } |
| 1965 | |
| 1966 | /* Retorna el nombre de 1 de la configuració de fitxes del joc |
| 1967 | * passada pel paràmetre*/ |
| 1968 | int frmPrincipal::numeroFitxesConfiguracioActualJoc(QString configuracioActual){ |
| 1969 | return configuracioActual.count("1"); |
| 1970 | } |
| 1971 | |
| 1972 | /* |
| 1973 | Busca una solució ha partir d'una altra solució |
| 1974 | */ |
| 1975 | void frmPrincipal::solucionaJocRapid(){ |
| 1976 | |
| 1977 | solitariPersonalitzat_dadesFitxes(); |
| 1978 | |
| 1979 | /* Amb la modalitat de joc personalitzat, cal preveure |
| 1980 | * la possibilitat que no hi hagi cap fitxa activa |
| 1981 | * L'opció de jocResolt està afegida per evitar que no es pugui |
| 1982 | * tornar a cercar una solució quan ja s'ha trobat una |
| 1983 | */ |
| 1984 | // if( (taulerJoc->numeroDeMovimentsJoc()<1) && |
| 1985 | // (jocResolt==0)){ |
| 1986 | // //No hi ha moviments |
| 1987 | // mostraMissatge(5); |
| 1988 | // // qDebug("numeroDeMovimentsJoc %d",taulerJoc->numeroDeMovimentsJoc()); |
| 1989 | // return; |
| 1990 | // } |
| 1991 | // else if(jocResolt==2){ |
| 1992 | // iniciSolucioSlot(); |
| 1993 | // } |
| 1994 | // //sense això, el programa fracasa si s'ha aturat la cerca |
| 1995 | // //en una situació sense moviments i es torna a intentar cercar |
| 1996 | // else if (taulerJoc->numeroDeMovimentsJoc()<1 ){ |
| 1997 | // //No hi ha moviments |
| 1998 | // mostraMissatge(5); |
| 1999 | // return; |
| 2000 | |
| 2001 | // } |
| 2002 | /* Controlam l'estat actual del joc: |
| 2003 | si ja està resolt (fitxes verdes), està finalitzat, |
| 2004 | sens moviments o és un joc personalitzat sense |
| 2005 | moviments, reiniciam el joc */ |
| 2006 | if(jocResolt==2 |
| 2007 | || |
| 2008 | (taulerJoc->numeroDeMovimentsJoc()<1 || |
| 2009 | taulerJoc->jocFinalitzat()) |
| 2010 | || |
| 2011 | (taulerJoc->solitariPersonalitzat() && |
| 2012 | taulerJoc->numeroDeMovimentsJoc()<1) |
| 2013 | ){ |
| 2014 | iniciSolucioSlot(); |
| 2015 | movimentsUndoStack->clear(); |
| 2016 | iniciSolucioAction->setEnabled(movimentsUndoStack->canUndo()); |
| 2017 | } |
| 2018 | |
| 2019 | //És possible que el joc no tengui moviments |
| 2020 | //El jugador pot haver deixat una situació sense moviments |
| 2021 | //o bé es un joc personalitzat/modificat que no te moviments |
| 2022 | taulerJoc->configuracioActual(true); |
| 2023 | if (taulerJoc->numeroDeMovimentsJoc()<1 ){ |
| 2024 | //No hi ha moviments |
| 2025 | mostraMissatge(5); |
| 2026 | return; |
| 2027 | } |
| 2028 | |
| 2029 | solucionaJocActual_movimentsJaRealitzats.clear(); |
| 2030 | solucionaJocActual_darrerMoviment.clear(); |
| 2031 | //reiniciam els intents |
| 2032 | intentsSolucio=0; |
| 2033 | taulerJoc->setEstatDelJoc(solucio); |
| 2034 | jocResolt=0; |
| 2035 | /*Posa a zero el rellotge 01/01/11 |
| 2036 | Si es clicava una segona vegada desprès d'obtenir |
| 2037 | una solució, llavors s'acumulava el temps*/ |
| 2038 | if (!rellotgeLabel->rellotgeEnMarxa()){ |
| 2039 | rellotgeLabel->estableixTemps(QString("00:00:00")); |
| 2040 | } |
| 2041 | |
| 2042 | cercaSolucioAPartirDeMovimentsInicials=false; |
| 2043 | |
| 2044 | qApp->processEvents(); |
| 2045 | //Actualitzam el comptador de les fitxes del joc |
| 2046 | taulerJoc->configuracioActual(true); |
| 2047 | int numeroFitxesJoc=taulerJoc->numeroDeMovimentsJoc(); |
| 2048 | // int numeroFitxesJoc=solucionaJocActual_numeroDeFitxesDelJoc()-1; |
| 2049 | // qDebug("numeroFitxesJoc %d", numeroFitxesJoc); |
| 2050 | |
| 2051 | if(comprovaExisteixenMovimentsPossibles()==0){ |
| 2052 | // qDebug("sense moviments"); |
| 2053 | //No hi ha moviments |
| 2054 | mostraMissatge(5); |
| 2055 | return; |
| 2056 | } |
| 2057 | |
| 2058 | /*Seleccionam el tipus de recerca a executar*/ |
| 2059 | /* Si no hi ha moviments fets*/ |
| 2060 | if(movimentsUndoStack->count()<1 ){ |
| 2061 | //La majoria dels jocs amb final marcat i generats a l'atzar |
| 2062 | //només es resoldran amb el sistema |
| 2063 | //de la versió 2.1 (que intenta fer servir solucions ja trobades) |
| 2064 | //comprovaDadesSolucions() indica si es fa servir la versió 2.1 |
| 2065 | //o la versió actual (poques modalitats es resolen amb aquesta opció) |
| 2066 | if( |
| 2067 | (taulerJoc->jocAmbFinalMarcat() && comprovaDadesSolucions() |
| 2068 | && taulerJoc->p_tipusMoviment != 3) |
| 2069 | || |
| 2070 | (solitariAtzar_esAtzar( |
| 2071 | arbreModalitatsJocTreeWidget->selectedItems().first()->text(1))) |
| 2072 | ){ |
| 2073 | retrocedeixMoviment=0; |
| 2074 | solucionaJocActual_carregaSolucio(); |
| 2075 | solucionaJocActual_Inicia(); |
| 2076 | } |
| 2077 | /*Si hi ha solucions anteriors*/ |
| 2078 | else if(comprovaArxiuDeSolucions() && !taulerJoc->jocAmbFinalMarcat()){ |
| 2079 | /*seleccionam a l'atzar el tipus de recerca*/ |
| 2080 | int atzar= qrand() % 10; |
| 2081 | //Encara no hi ha un procediment eficaç per a moltes fitxes! |
| 2082 | if (atzar<5 || (numeroFitxesJoc>40 && taulerJoc->p_tipusMoviment != 3) |
| 2083 | ){ |
| 2084 | /* Carrega i executa part dels moviments d'una solució */ |
| 2085 | retrocedeixMoviment=0; |
| 2086 | solucionaJocActual_carregaSolucio(); |
| 2087 | solucionaJocActual_Inicia(); |
| 2088 | } |
| 2089 | else { |
| 2090 | solucionaJocActual_RecercaIterativa_ExhaustivaInici(numeroFitxesJoc); |
| 2091 | } |
| 2092 | } |
| 2093 | else { |
| 2094 | //No hi ha dades (de solucions) o és un joc personalitzat o modificat |
| 2095 | solucionaJocActual_RecercaIterativa_ExhaustivaInici(numeroFitxesJoc); |
| 2096 | } |
| 2097 | // } |
| 2098 | }//if(movimentsUndoStack->index()<1) |
| 2099 | |
| 2100 | //Hi ha moviments fets i el joc està iniciat |
| 2101 | else if((rellotgeLabel->rellotgeEnMarxa()) ){ |
| 2102 | /*conservam l'índex del darrer moviment*/ |
| 2103 | // qDebug("movimentsUndoStack->count() %d", movimentsUndoStack->count()); |
| 2104 | retrocedeixMoviment=movimentsUndoStack->index(); |
| 2105 | solucionaJocActual_RecercaIterativa_ExhaustivaInici( |
| 2106 | numeroFitxesJoc+retrocedeixMoviment,retrocedeixMoviment); |
| 2107 | } |
| 2108 | /*Aqui no hauria d'arribat mai*/ |
| 2109 | else { |
| 2110 | gestioTipusDeJocASeleccionar(); |
| 2111 | solucionaJocRapid(); |
| 2112 | } |
| 2113 | } |
| 2114 | |
| 2115 | /* Soluciona el joc actual pel métode de la força |
| 2116 | * bruta. Deixa el resultat a un arxiu de tipus .arbre*/ |
| 2117 | void frmPrincipal::solucionaJoc_ForcaBruta(){ |
| 2118 | |
| 2119 | mostraMissatge(100); |
| 2120 | //Eliminam l'arxiu arbre anterior |
| 2121 | eliminaArxiu(5); |
| 2122 | solucionsTrobades.clear(); |
| 2123 | carregaSolucions(); |
| 2124 | |
| 2125 | taulerJoc->setEstatDelJoc(solucio); |
| 2126 | jocResolt=0; |
| 2127 | int numFitxesInicialsJoc=taulerJoc->numeroDeMovimentsJoc(); |
| 2128 | //int numFitxesInicialsJoc=solucionaJocActual_numeroDeFitxesDelJoc(); |
| 2129 | |
| 2130 | qApp->processEvents(); |
| 2131 | QProgressDialog *progresRecercaExahustiva =new QProgressDialog(this);; |
| 2132 | progresRecercaExahustiva->setLabelText(tr("Cercant solució")); |
| 2133 | progresRecercaExahustiva->setCancelButtonText(tr("Atura")); |
| 2134 | progresRecercaExahustiva->setMinimum(0); |
| 2135 | // progresRecercaExahustiva->setMaximum(taulerJoc->numeroDeMovimentsJoc()+retrocedeixMoviment); |
| 2136 | progresRecercaExahustiva->setMaximum(numFitxesInicialsJoc); |
| 2137 | progresRecercaExahustiva->setParent(this); |
| 2138 | qApp->processEvents(); |
| 2139 | progresRecercaExahustiva->setWindowModality(Qt::WindowModal); |
| 2140 | progresRecercaExahustiva->setVisible(true); |
| 2141 | rellotgeLabel->iniciaRellotge(); |
| 2142 | qApp->processEvents(); |
| 2143 | |
| 2144 | //sistema de recerca exhaustiva |
| 2145 | //taulerJoc->p_movimentsUndoStack->undo(); |
| 2146 | progresRecercaExahustiva->setMaximum(numFitxesInicialsJoc); |
| 2147 | taulerJoc->jocsRealitzats=0; |
| 2148 | taulerJoc->jocsAmbSolucio=0; |
| 2149 | taulerJoc->solucionaJocActual_CalculaArbreJocComplet_Inici(progresRecercaExahustiva, numFitxesInicialsJoc);/*}*/ |
| 2150 | progresRecercaExahustiva->cancel(); |
| 2151 | rellotgeLabel->aturaRellotge(); |
| 2152 | iniciSolucioSlot(); |
| 2153 | QString missatge=QString("%1 %2 %3 %4").arg(rellotgeLabel->retornaTemps(1)+" ") |
| 2154 | .arg(taulerJoc->jocsRealitzats). |
| 2155 | arg(taulerJoc->jocsAmbSolucio). |
| 2156 | arg((double)taulerJoc->jocsAmbSolucio*100/taulerJoc->jocsRealitzats); |
| 2157 | qCritical("%s",qPrintable(missatge)); |
| 2158 | //Finalment, es carregan totes les solucions. Les solucions |
| 2159 | //no es carregan continuament degut a què el mètode |
| 2160 | //no trobarà solucions repetides |
| 2161 | //veureSolucionsSlot(); |
| 2162 | } |
| 2163 | |
| 2164 | //void frmPrincipal::solucionaJoc_ForcaBruta(){ |
| 2165 | |
| 2166 | //mostraMissatge(100); |
| 2167 | ////Eliminam l'arxiu arbre anterior |
| 2168 | //eliminaArxiu(5); |
| 2169 | //solucionsTrobades.clear(); |
| 2170 | //carregaSolucions(); |
| 2171 | |
| 2172 | //taulerJoc->setEstatDelJoc(solucio); |
| 2173 | //jocResolt=0; |
| 2174 | //int numFitxesInicialsJoc=taulerJoc->numeroDeMovimentsJoc(); |
| 2175 | ////int numFitxesInicialsJoc=solucionaJocActual_numeroDeFitxesDelJoc(); |
| 2176 | |
| 2177 | //qApp->processEvents(); |
| 2178 | //QProgressDialog *progresRecercaExahustiva =new QProgressDialog(this);; |
| 2179 | //progresRecercaExahustiva->setLabelText(tr("Cercant solució")); |
| 2180 | //progresRecercaExahustiva->setCancelButtonText(tr("Atura")); |
| 2181 | //progresRecercaExahustiva->setMinimum(0); |
| 2182 | //// progresRecercaExahustiva->setMaximum(taulerJoc->numeroDeMovimentsJoc()+retrocedeixMoviment); |
| 2183 | //progresRecercaExahustiva->setMaximum(numFitxesInicialsJoc); |
| 2184 | //progresRecercaExahustiva->setParent(this); |
| 2185 | //qApp->processEvents(); |
| 2186 | //progresRecercaExahustiva->setWindowModality(Qt::WindowModal); |
| 2187 | //progresRecercaExahustiva->setVisible(true); |
| 2188 | //rellotgeLabel->iniciaRellotge(); |
| 2189 | //qApp->processEvents(); |
| 2190 | |
| 2191 | ////sistema de recerca exhaustiva |
| 2192 | ////taulerJoc->p_movimentsUndoStack->undo(); |
| 2193 | //progresRecercaExahustiva->setMaximum(numFitxesInicialsJoc); |
| 2194 | //taulerJoc->jocsRealitzats=0; |
| 2195 | //taulerJoc->jocsAmbSolucio=0; |
| 2196 | //taulerJoc->solucionaJocActual_CalculaArbreJocComplet_Inici(progresRecercaExahustiva, numFitxesInicialsJoc);/*}*/ |
| 2197 | //progresRecercaExahustiva->cancel(); |
| 2198 | //rellotgeLabel->aturaRellotge(); |
| 2199 | //iniciSolucioSlot(); |
| 2200 | //QString missatge=QString("%1 %2 %3").arg(taulerJoc->jocsRealitzats). |
| 2201 | // arg(taulerJoc->jocsAmbSolucio). |
| 2202 | // arg((double)taulerJoc->jocsAmbSolucio*100/taulerJoc->jocsRealitzats); |
| 2203 | //qCritical("%s",qPrintable(missatge)); |
| 2204 | ////Finalment, es carregan totes les solucions. Les solucions |
| 2205 | ////no es carregan continuament degut a què el mètode |
| 2206 | ////no trobarà solucions repetides |
| 2207 | ////veureSolucionsSlot(); |
| 2208 | //} |
| 2209 | |
| 2210 | void frmPrincipal::solucionaJocActual_carregaSolucio(){ |
| 2211 | if(movimentsUndoStack->index()==0){ |
| 2212 | movimentsUndoStack->clear(); |
| 2213 | //Primer carregam les solucions disponibles |
| 2214 | //06/02/13 nou prod. |
| 2215 | actualitzaConfiguracionsInicials(); |
| 2216 | comprovaArxiuSolucions(); |
| 2217 | carregaSolucions(); |
| 2218 | /*Carregam la solució*/ |
| 2219 | if (solucionsTrobades.count()>0) { |
| 2220 | //Seleccionam una solució a l'atzar |
| 2221 | qsrand(rellotgeQTime.msecsTo(QTime::currentTime())); |
| 2222 | int selec=qrand() % (solucionsTrobades.count()); |
| 2223 | /* qDebug("qrand() %d",qrand()); |
| 2224 | qDebug("solució seleccionada %d",selec); |
| 2225 | qDebug("solucionsTrobades.count() %d",solucionsTrobades.count());*/ |
| 2226 | QStringList movimentsSolucio=solucionsTrobades.value(selec).split(" "); |
| 2227 | /*02/02/11 Això és per controlar les solucions incorrectes |
| 2228 | (que no tenen el nombre de moviments corresponents al joc |
| 2229 | 10/02/13 Pareix que això ja no passa mai |
| 2230 | 21/08/16 Eliminat |
| 2231 | */ |
| 2232 | /* while (movimentsSolucio.count() != |
| 2233 | taulerJoc->numeroDeMovimentsJoc()*4){ |
| 2234 | qCritical("%s", qPrintable(solucionsTrobades.value(selec))); |
| 2235 | solucionsTrobades.removeOne(solucionsTrobades.value(selec)); |
| 2236 | //solucionsTrobades.removeAt(selec); |
| 2237 | desaSolucions(); |
| 2238 | // qDebug("eliminada %d", selec); |
| 2239 | qsrand(rellotgeQTime.msecsTo(QTime::currentTime())); |
| 2240 | int selec=qrand() % (solucionsTrobades.count()); |
| 2241 | movimentsSolucio=solucionsTrobades.value(selec).split(" "); |
| 2242 | }*/ |
| 2243 | |
| 2244 | /*Ara seleccinam a l'atzar un número |
| 2245 | i es fan els moviments corresponents a la solució |
| 2246 | fins al número seleccionat |
| 2247 | */ |
| 2248 | /* 02/01/13 |
| 2249 | * Abans dividia per 8: si el joc tenia menys moviments,llavors |
| 2250 | * fallava (això pot passar en els jocs personalitzats |
| 2251 | * 21/08/16 |
| 2252 | * Ara es reinicia el joc de zero i taulerJoc->p_numMoviments |
| 2253 | * sempre es 0. |
| 2254 | * A més, s'ha eliminat la divisió per 4 |
| 2255 | */ |
| 2256 | // selec=qrand() % ((movimentsSolucio.count()/8)); |
| 2257 | qsrand(rellotgeQTime.msecsTo(QTime::currentTime())); |
| 2258 | //selec=qrand() % ((movimentsSolucio.count()/4)); |
| 2259 | selec=qrand() % ((movimentsSolucio.count()/4)); |
| 2260 | //qDebug("selec %d",selec); |
| 2261 | //qDebug("taulerJoc->p_numMoviments %d",taulerJoc->p_numMoviments); |
| 2262 | selec=qMax(selec,taulerJoc->p_numMoviments); |
| 2263 | /*qDebug("movimentsSolucio.count() %d",movimentsSolucio.count()/4); |
| 2264 | qDebug("moviment seleccionat %d",selec); |
| 2265 | qDebug("****************************");*/ |
| 2266 | QString mov; |
| 2267 | rellotgeLabel->iniciaRellotge(); |
| 2268 | // qDebug("taulerJoc->p_numMoviments %d",taulerJoc->p_numMoviments); |
| 2269 | for(int i=0;i<(movimentsSolucio.count()/4);i++){ |
| 2270 | if(i<(movimentsSolucio.count()/4)-selec){ |
| 2271 | taulerJoc->ferMoviment(movimentsSolucio.value(i*4+1).toInt(), |
| 2272 | movimentsSolucio.value(i*4+2).toInt(), |
| 2273 | movimentsSolucio.value(i*4+3).toInt());} |
| 2274 | |
| 2275 | if(i>taulerJoc->p_numMoviments){ |
| 2276 | mov=QString("%1 %2 %3 %4"). |
| 2277 | arg(movimentsSolucio.value(i*4)). |
| 2278 | arg(movimentsSolucio.value(i*4+1)). |
| 2279 | arg(movimentsSolucio.value(i*4+2)). |
| 2280 | arg((movimentsSolucio.value(i*4+3))); |
| 2281 | solucionaJocActual_movimentsEliminats.append(mov); |
| 2282 | } |
| 2283 | } |
| 2284 | solucionaJocActual_darrerMoviment.append(mov); |
| 2285 | } /*Final de carregam la solució*/ |
| 2286 | }//if inicial movimentsUndoStack->index()==0 |
| 2287 | else cercaSolucioAPartirDeMovimentsInicials=true; |
| 2288 | } |
| 2289 | |
| 2290 | /* Carrega una solució i fa un nombre determinat de moviments |
| 2291 | * de la solució (tot seleccionat a l'atzar) |
| 2292 | * Es fa servir quan es supera el màxim de vegades que no |
| 2293 | * hi ha moviments possibles |
| 2294 | */ |
| 2295 | void frmPrincipal::solucionaJocActual_carregaSolucio1(){ |
| 2296 | //if(movimentsUndoStack->index()==0){ |
| 2297 | movimentsUndoStack->clear(); |
| 2298 | //Primer carregam les solucions disponibles |
| 2299 | actualitzaConfiguracionsInicials(); |
| 2300 | //21/04/17 |
| 2301 | //Eliminades les dues linies següents per evitar que el progress |
| 2302 | //forci el focus en el programa |
| 2303 | // comprovaArxiuSolucions(); |
| 2304 | // carregaSolucions(); |
| 2305 | /*Carregam la solució*/ |
| 2306 | if (solucionsTrobades.count()>0) { |
| 2307 | //Seleccionam una solució a l'atzar |
| 2308 | qsrand(rellotgeQTime.msecsTo(QTime::currentTime())); |
| 2309 | int selec=qrand() % (solucionsTrobades.count()); |
| 2310 | /*qDebug("qrand() %d",qrand()); |
| 2311 | qDebug("solució seleccionada %d",selec); |
| 2312 | qDebug("solucionsTrobades.count() %d",solucionsTrobades.count());*/ |
| 2313 | QStringList movimentsSolucio=solucionsTrobades.value(selec).split(" "); |
| 2314 | /*Ara seleccinam a l'atzar un número |
| 2315 | i es fan els moviments corresponents a la solució |
| 2316 | fins al número seleccionat*/ |
| 2317 | selec=(qrand() % ((movimentsSolucio.count()/4))); |
| 2318 | /*Aquest valor mínim de selec és per evitar que es repeteixin |
| 2319 | //massa les solucions trobades (que no es carraguin molts |
| 2320 | moviments de la solució*/ |
| 2321 | //qDebug("moviment seleccionat %d",selec); |
| 2322 | //qDebug("movimentsSolucio.count() %d",movimentsSolucio.count()/4); |
| 2323 | /*El 0.10 és empíric: pareix que quantes més fitxes hi ha, |
| 2324 | *és millor que el nombre sigui més petit*/ |
| 2325 | while (selec<(movimentsSolucio.count()/4)*0.10){ |
| 2326 | selec=qrand() % (movimentsSolucio.count()/4); |
| 2327 | //qDebug("selec %d",selec); |
| 2328 | } |
| 2329 | //qDebug("selec %d",selec); |
| 2330 | //qDebug("taulerJoc->p_numMoviments %d",taulerJoc->p_numMoviments); |
| 2331 | //selec=qMax(selec,taulerJoc->p_numMoviments); |
| 2332 | //qDebug("movimentsSolucio.count() %d",movimentsSolucio.count()/4); |
| 2333 | // qDebug("moviment seleccionat %d",selec); |
| 2334 | // qDebug("****************************"); |
| 2335 | QString mov; |
| 2336 | // qDebug("taulerJoc->p_numMoviments %d",taulerJoc->p_numMoviments); |
| 2337 | for(int i=0;i<(movimentsSolucio.count()/4);i++){ |
| 2338 | if(i<(movimentsSolucio.count()/4)-selec){ |
| 2339 | taulerJoc->ferMoviment(movimentsSolucio.value(i*4+1).toInt(), |
| 2340 | movimentsSolucio.value(i*4+2).toInt(), |
| 2341 | movimentsSolucio.value(i*4+3).toInt()); |
| 2342 | |
| 2343 | |
| 2344 | solucionaJocActual_darrerMoviment=QString("%1 ").arg(movimentsUndoStack->index()); |
| 2345 | mov=QString("%1 %2 %3"). |
| 2346 | arg(movimentsSolucio.value(i*4+1)). |
| 2347 | arg(movimentsSolucio.value(i*4+2)). |
| 2348 | arg((movimentsSolucio.value(i*4+3))); |
| 2349 | solucionaJocActual_darrerMoviment.append(mov); |
| 2350 | solucionaJocActual_movimentsJaRealitzats.append( |
| 2351 | solucionaJocActual_darrerMoviment); |
| 2352 | // qDebug("Solucio: moviment %d",i); |
| 2353 | } |
| 2354 | |
| 2355 | |
| 2356 | if(i>taulerJoc->p_numMoviments){ |
| 2357 | mov=QString("%1 %2 %3 %4"). |
| 2358 | arg(movimentsSolucio.value(i*4)). |
| 2359 | arg(movimentsSolucio.value(i*4+1)). |
| 2360 | arg(movimentsSolucio.value(i*4+2)). |
| 2361 | arg((movimentsSolucio.value(i*4+3))); |
| 2362 | solucionaJocActual_movimentsEliminats.append(mov); |
| 2363 | } |
| 2364 | } |
| 2365 | // solucionaJocActual_darrerMoviment.append(mov); |
| 2366 | } /*Final de carregam la solució*/ |
| 2367 | // }//if inicial movimentsUndoStack->index()==0 |
| 2368 | } |
| 2369 | |
| 2370 | /* |
| 2371 | Elimina l'arxiu de configuracions eliminades. Es fa servir |
| 2372 | quan el programa no aconsegueix trobar una solucuió al joc |
| 2373 | */ |
| 2374 | void frmPrincipal::eliminaArxiuConfgEliminades(){ |
| 2375 | comprovaDirectoriHome(); |
| 2376 | QString nomArxiu=nomArxiuJoc(1); |
| 2377 | QFile arxiu(nomArxiu); |
| 2378 | arxiu.remove(nomArxiu); |
| 2379 | } |
| 2380 | |
| 2381 | void frmPrincipal::desaConfiguracionsEliminades(int tipus){ |
| 2382 | |
| 2383 | if (solucioJocActual_configuracionsEliminadesPerDesar.count()==0){ |
| 2384 | return;} |
| 2385 | |
| 2386 | int numero=0; |
| 2387 | |
| 2388 | QProgressDialog progres(tr("Desant dades"), tr("Atura"), 0,solucioJocActual_configuracionsEliminadesPerDesar.count() ,this); |
| 2389 | progres.setWindowModality(Qt::WindowModal); |
| 2390 | progres.setValue(numero); |
| 2391 | //progres.setVisible(true); |
| 2392 | qApp->processEvents(); |
| 2393 | |
| 2394 | comprovaDirectoriHome(); |
| 2395 | |
| 2396 | QString nomArxiu=nomArxiuJoc(1); |
| 2397 | |
| 2398 | QFile arxiu(nomArxiu); |
| 2399 | bool arxiuObert=false; |
| 2400 | if (tipus==0){ |
| 2401 | if (arxiu.open(QIODevice::Append)){arxiuObert=true;} |
| 2402 | } |
| 2403 | else if (arxiu.open(QIODevice::WriteOnly)){arxiuObert=true;} |
| 2404 | |
| 2405 | if (arxiuObert){ |
| 2406 | QTextStream entrada(&arxiu); |
| 2407 | for(int j=0;j<solucioJocActual_configuracionsEliminadesPerDesar.count();j++){ |
| 2408 | entrada<<(QString("%1\n").arg(solucioJocActual_configuracionsEliminadesPerDesar.value(j) )) ; |
| 2409 | progres.setValue(++numero); |
| 2410 | progres.setLabelText(QString(tr("Desant dades: %1 de %2")).arg(numero). |
| 2411 | arg(solucioJocActual_configuracionsEliminadesPerDesar.count())); |
| 2412 | if (progres.wasCanceled()) { break; } |
| 2413 | qApp->processEvents(); |
| 2414 | } |
| 2415 | } |
| 2416 | arxiu.close(); |
| 2417 | } |
| 2418 | |
| 2419 | |
| 2420 | void frmPrincipal::carregaConfiguracionsEliminades(){ |
| 2421 | int numero=0; |
| 2422 | |
| 2423 | QString nomArxiu=nomArxiuJoc(1); |
| 2424 | |
| 2425 | QFile arxiu(nomArxiu); |
| 2426 | /*23/01/2011 |
| 2427 | Aqui hi havia una divisió per zero! |
| 2428 | Quan es fa un joc invers amb modificació de l'usuari |
| 2429 | */ |
| 2430 | int divisor=taulerJoc->numeroDeMovimentsJoc(); |
| 2431 | //Xapussa per evitar les divisions per zero |
| 2432 | if (divisor<0){divisor=1;} |
| 2433 | qint64 tamanyArxiu=arxiu.size()/divisor; |
| 2434 | /* if (taulerJoc->numeroDeMovimentsJoc()>0){ |
| 2435 | tamanyArxiu =1+arxiu.size()/(1+taulerJoc->numeroDeMovimentsJoc());} |
| 2436 | else tamanyArxiu =arxiu.size();*/ |
| 2437 | |
| 2438 | QProgressDialog progres(tr("Carregant dades"), tr("Atura"), 0,tamanyArxiu ,this); |
| 2439 | |
| 2440 | |
| 2441 | progres.setWindowModality(Qt::WindowModal); |
| 2442 | progres.setValue(numero); |
| 2443 | progres.setVisible(true); |
| 2444 | qApp->processEvents(); |
| 2445 | |
| 2446 | solucioJocActual_configuracionsEliminades.clear(); |
| 2447 | if (arxiu.open(QIODevice::ReadOnly)){ |
| 2448 | QTextStream entrada(&arxiu); |
| 2449 | QString linia0 = entrada.readLine(); |
| 2450 | while (!linia0.isNull()) { |
| 2451 | if ( ! solucioJocActual_configuracionsEliminadesPerDesar.contains(linia0)){ |
| 2452 | solucioJocActual_configuracionsEliminades.append(linia0); |
| 2453 | solucioJocActual_configuracionsEliminadesPerDesar.append(linia0); |
| 2454 | progres.setValue(++numero); |
| 2455 | progres.setLabelText(QString("Carregant dades: %1 de %2").arg(numero).arg(tamanyArxiu)); |
| 2456 | } |
| 2457 | linia0 = entrada.readLine(); |
| 2458 | if (progres.wasCanceled()) break; |
| 2459 | qApp->processEvents(); |
| 2460 | } |
| 2461 | arxiu.close(); |
| 2462 | progres.cancel(); |
| 2463 | /*07/09/16 Eliminat. Això es farà |
| 2464 | * en desar les dades |
| 2465 | desaConfiguracionsEliminades(1);*/ |
| 2466 | } |
| 2467 | } |
| 2468 | |
| 2469 | /* Escriu a un arxiu el moviment passat |
| 2470 | * per paràmetre. Serveix per seguir els moviments |
| 2471 | * provats de la recerca iterativa de solució*/ |
| 2472 | |
| 2473 | void frmPrincipal::desaMovimentsJoc(QString moviment){ |
| 2474 | |
| 2475 | comprovaDirectoriHome(); |
| 2476 | |
| 2477 | QString nomArxiu=nomArxiuJoc(4); |
| 2478 | |
| 2479 | QFile arxiu(nomArxiu); |
| 2480 | bool arxiuObert=false; |
| 2481 | if (arxiu.open(QIODevice::Append)){arxiuObert=true;} |
| 2482 | if (arxiuObert){ |
| 2483 | QTextStream entrada(&arxiu); |
| 2484 | entrada<<moviment ; |
| 2485 | entrada<<"\n"; |
| 2486 | } |
| 2487 | arxiu.close(); |
| 2488 | } |
| 2489 | |
| 2490 | /* |
| 2491 | Elimina l'arxiu de moviments provats en la recerca |
| 2492 | de iterativa de solució. |
| 2493 | */ |
| 2494 | void frmPrincipal::eliminaArxiuMovimentsJoc(){ |
| 2495 | comprovaDirectoriHome(); |
| 2496 | QString nomArxiu=nomArxiuJoc(4); |
| 2497 | QFile arxiu(nomArxiu); |
| 2498 | arxiu.remove(nomArxiu); |
| 2499 | } |
| 2500 | |
| 2501 | /* Elimina l'arxiu adequat segons el codi passat |
| 2502 | 1 ".txt" |
| 2503 | 2 ".sol" |
| 2504 | 4 ".movi" |
| 2505 | 5 ".arbre"*/ |
| 2506 | void frmPrincipal::eliminaArxiu(int codi){ |
| 2507 | comprovaDirectoriHome(); |
| 2508 | QString nomArxiu=nomArxiuJoc(codi); |
| 2509 | QFile arxiu(nomArxiu); |
| 2510 | arxiu.remove(nomArxiu); |
| 2511 | } |
| 2512 | |
| 2513 | |
| 2514 | /*Comprova si hi ha una arxiu de solucions del joc |
| 2515 | * actual*/ |
| 2516 | bool frmPrincipal::comprovaArxiuDeSolucions(){ |
| 2517 | QString nomArxiu=nomArxiuJoc(2); |
| 2518 | QFile arxiu(nomArxiu); |
| 2519 | return arxiu.exists(); |
| 2520 | } |
| 2521 | |
| 2522 | /* Carrega les solucions del joc actual |
| 2523 | * a la llista solucionsTrobades |
| 2524 | */ |
| 2525 | void frmPrincipal::carregaSolucions(){ |
| 2526 | // qDebug("carrega solucions"); |
| 2527 | QString nomArxiu=nomArxiuJoc(2); |
| 2528 | QFile arxiu(nomArxiu); |
| 2529 | solucionsTrobades.clear(); |
| 2530 | QProgressDialog progres(tr("Carregant dades"), tr("Atura"), 0,100 ,this); |
| 2531 | int contador=0; |
| 2532 | progres.setWindowModality(Qt::WindowModal); |
| 2533 | progres.setVisible(true); |
| 2534 | //int liniesLlegides=0; |
| 2535 | if (arxiu.open(QIODevice::ReadOnly)){ |
| 2536 | QTextStream entrada(&arxiu); |
| 2537 | QString linia0 = entrada.readLine(); |
| 2538 | while (!linia0.isNull()) { |
| 2539 | QStringList movimentsSolucio=linia0.split(" "); |
| 2540 | //La segona condició és una xapussa per a què |
| 2541 | //funcioni la càrrega de la solució dels solitaris |
| 2542 | //generats a l'atzar |
| 2543 | // qDebug("taulerJoc->numeroDeMovimentsJoc() %d",taulerJoc->numeroDeMovimentsJoc()); |
| 2544 | // qDebug("retrocedeixMoviment %d", retrocedeixMoviment); |
| 2545 | if ( (movimentsSolucio.count() == |
| 2546 | (taulerJoc->numeroDeMovimentsJoc()+retrocedeixMoviment)*4) |
| 2547 | || (movimentsSolucio.count() == solitariAtzar_solucio.count(" ")+1) |
| 2548 | ){ |
| 2549 | if (!solucionsTrobades.contains(linia0)){ |
| 2550 | solucionsTrobades.append(linia0); |
| 2551 | progres.setValue(contador++); |
| 2552 | if(contador>progres.maximum()-30){ |
| 2553 | progres.setMaximum(progres.maximum()*10); |
| 2554 | } |
| 2555 | // qDebug("carregada solucio"); |
| 2556 | } |
| 2557 | else { |
| 2558 | qCritical("Sol. rep. %s", qPrintable(linia0)); |
| 2559 | } |
| 2560 | } |
| 2561 | linia0 = entrada.readLine(); |
| 2562 | qApp->processEvents(); |
| 2563 | if(progres.wasCanceled()){ |
| 2564 | arxiu.close(); |
| 2565 | break;} |
| 2566 | // liniesLlegides++; |
| 2567 | // qDebug("liniesLlegides %d", liniesLlegides); |
| 2568 | /* 13/01/11 |
| 2569 | Aquesta linea provocava un error en la càrrrega de les |
| 2570 | dades de les solucions quan es feia un canvi ràpid en la |
| 2571 | selecció de la modalitar de joc*/ |
| 2572 | //qApp->processEvents(); |
| 2573 | } |
| 2574 | //qDebug("Items in list: %d", solucionsTrobades.size()); |
| 2575 | arxiu.close(); |
| 2576 | } |
| 2577 | // else qDebug("No s'obri l'arxiu!!"); |
| 2578 | //qDebug("Items in list: %d", solucionsTrobades.size()); |
| 2579 | } |
| 2580 | |
| 2581 | void frmPrincipal::desaSolucions(){ |
| 2582 | if (solucionaJocActual_movimentsJaRealitzats.count()==0){ |
| 2583 | qDebug("No hi ha solucions per desar!"); |
| 2584 | return;} |
| 2585 | /* 02/02/11 A vegades s'escriu malament la solució (no s'afageixen tots |
| 2586 | els moviments). Això evita aquest problema |
| 2587 | 10/02/13 Això pareix que ja no passa mai |
| 2588 | */ |
| 2589 | if(solucionaJocActual_movimentsJaRealitzats.count() != taulerJoc->numeroDeMovimentsJoc() ){ |
| 2590 | qDebug("problemes amb la solució %d",solucionaJocActual_movimentsJaRealitzats.count() ); |
| 2591 | qDebug("taulerJoc->numeroDeMovimentsJoc() %d",taulerJoc->numeroDeMovimentsJoc() ); |
| 2592 | return; |
| 2593 | } |
| 2594 | |
| 2595 | comprovaDirectoriHome(); |
| 2596 | QString nomArxiu; |
| 2597 | if( (taulerJoc->solitariPersonalitzat() )|| |
| 2598 | (taulerJoc->solitariModificat()) ){ |
| 2599 | /* Eliminam les solucions que hi pugui haver a l'arbre |
| 2600 | * de solucions per evitar que es carreguin solucions |
| 2601 | * del solitari sense modificar. |
| 2602 | */ |
| 2603 | // arbreSolucionsTreeWidget->clear(); |
| 2604 | // solucionsTrobades.clear(); |
| 2605 | veureSolucionsSlot(); |
| 2606 | } |
| 2607 | nomArxiu=nomArxiuJoc(2); |
| 2608 | //carregaSolucions(); |
| 2609 | QString solucioActual; |
| 2610 | for(int j=0;j<solucionaJocActual_movimentsJaRealitzats.count()-1;j++){ |
| 2611 | solucioActual.append(QString("%1 ").arg(solucionaJocActual_movimentsJaRealitzats.value(j) )) ; |
| 2612 | } |
| 2613 | /*04/02/11 Eliminats els espais buits del final |
| 2614 | */ |
| 2615 | solucioActual.append(QString("%1").arg(solucionaJocActual_movimentsJaRealitzats.value( |
| 2616 | solucionaJocActual_movimentsJaRealitzats.count()-1) )) ; |
| 2617 | //if( !solucionsTrobades.contains(solucioActual)){ |
| 2618 | if( solucionsTrobades.indexOf(solucioActual)<0){ |
| 2619 | QFile arxiu(nomArxiu); |
| 2620 | if (arxiu.open(QIODevice::Append)){ |
| 2621 | QTextStream entrada(&arxiu); |
| 2622 | entrada<<(QString("%1\n").arg(solucioActual )) ; |
| 2623 | statusBar()->showMessage(tr("S'ha trobat una nova solució!")); |
| 2624 | //qDebug("desaSolucions()"); |
| 2625 | // solucionsTrobades.append(solucioActual); |
| 2626 | // qDebug("S'ha trobat una nova solució!"); |
| 2627 | arxiu.close(); |
| 2628 | } |
| 2629 | else qDebug("No es pot obrir l'arxiu de solucions per desar"); |
| 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | /* |
| 2634 | Desa la solució actual continguda a movimentsUndoStack |
| 2635 | Es fa servir des de taulerJoc |
| 2636 | */ |
| 2637 | void frmPrincipal::desaSolucions1(){ |
| 2638 | /*if (movimentsUndoStack->count()==0){ |
| 2639 | return; |
| 2640 | }*/ |
| 2641 | comprovaDirectoriHome(); |
| 2642 | QString nomArxiu; |
| 2643 | /* ?????? */ |
| 2644 | if(taulerJoc->solitariPersonalitzat()){ |
| 2645 | nomArxiu=nomArxiuJoc(2);} |
| 2646 | else nomArxiu=nomArxiuJoc(2); |
| 2647 | // qCritical("desaSolucions1 %s", qPrintable(nomArxiu)); |
| 2648 | // carregaSolucions(); |
| 2649 | QString solucioActual; |
| 2650 | for(int j=0;j<movimentsUndoStack->count()-1;j++){ |
| 2651 | solucioActual.append(QString("%1 %2 "). |
| 2652 | arg(j+1). |
| 2653 | arg(coordenadesAMoviment(movimentsUndoStack->text(j)))) ; |
| 2654 | } |
| 2655 | /*04/02/11 Eliminats els espais buits del final |
| 2656 | */ |
| 2657 | solucioActual.append(QString("%1 %2"). |
| 2658 | arg(movimentsUndoStack->count()). |
| 2659 | arg(coordenadesAMoviment(movimentsUndoStack->text( |
| 2660 | movimentsUndoStack->count()-1)))) ; |
| 2661 | /* 10/12/16 |
| 2662 | * Aqui no s'afegia la nova solució a la llista de solucions. |
| 2663 | * Hi ha solucions repetides als arxius de solucions*/ |
| 2664 | //if( !solucionsTrobades.contains(solucioActual)){ |
| 2665 | |
| 2666 | // qCritical("%s", qPrintable(solucioActual)); |
| 2667 | if( solucionsTrobades.indexOf(solucioActual)<0){ |
| 2668 | // qDebug("solucionsTrobades.indexOf(solucioActual) %d", solucionsTrobades.indexOf(solucioActual)); |
| 2669 | QFile arxiu(nomArxiu); |
| 2670 | if (arxiu.open(QIODevice::Append)){ |
| 2671 | QTextStream entrada(&arxiu); |
| 2672 | entrada<<(QString("%1\n").arg(solucioActual)) ; |
| 2673 | statusBar()->showMessage(tr("S'ha trobat una nova solució!")); |
| 2674 | |
| 2675 | } |
| 2676 | arxiu.close(); |
| 2677 | } |
| 2678 | } |
| 2679 | |
| 2680 | /* Carrega les solucions del joc actual |
| 2681 | * a l'arbre de solucions |
| 2682 | */ |
| 2683 | void frmPrincipal::veureSolucionsSlot(){ |
| 2684 | |
| 2685 | //while(!this->isVisible()){ |
| 2686 | //this->show(); |
| 2687 | //} |
| 2688 | QApplication::setOverrideCursor(Qt::WaitCursor); |
| 2689 | |
| 2690 | |
| 2691 | qApp->processEvents(); |
| 2692 | |
| 2693 | arbreSolucionsTreeWidget->clear(); |
| 2694 | |
| 2695 | //Carregam les solucions |
| 2696 | //solucionsTrobades.clear(); |
| 2697 | carregaSolucions(); |
| 2698 | qApp->processEvents(); |
| 2699 | int numeroSolucio=1; |
| 2700 | //qDebug("solucionsTrobades %d",solucionsTrobades.count()); |
| 2701 | if (solucionsTrobades.count()>0){ |
| 2702 | |
| 2703 | QProgressDialog progres(tr("Carregant dades"), tr("Atura"), 0,solucionsTrobades.count() ,this); |
| 2704 | progres.setWindowModality(Qt::WindowModal); |
| 2705 | progres.setVisible(true); |
| 2706 | //qDebug("Items in list: %d", solucionsTrobades.size()); |
| 2707 | //arbreSolucionsTreeWidget->clear(); |
| 2708 | for(int i=0;i<solucionsTrobades.count();i++){ |
| 2709 | if ( ! solucionsTrobades.value(i).mid(0,1).contains("#")){ |
| 2710 | //afegim un item arrel a l'arbre |
| 2711 | QTreeWidgetItem *itemSolucio=new QTreeWidgetItem(); |
| 2712 | QList<QTreeWidgetItem *> itemsArbre; |
| 2713 | QStringList movimentsSolucio=solucionsTrobades.value(i).split(" "); |
| 2714 | for(int moviment=0 ; moviment<movimentsSolucio.count()/4;++moviment){ |
| 2715 | QTreeWidgetItem *item=new QTreeWidgetItem(); |
| 2716 | item->setText(0, |
| 2717 | movimentACoordenades(movimentsSolucio.value(4*moviment+1),movimentsSolucio.value(4*moviment+3))); |
| 2718 | item->setText(1,QString("%1 %2 %3").arg(movimentsSolucio.value(4*moviment+1)). |
| 2719 | arg(movimentsSolucio.value(4*moviment+2)). |
| 2720 | arg(movimentsSolucio.value(4*moviment+3)) ); |
| 2721 | itemsArbre.append(item); |
| 2722 | } |
| 2723 | itemSolucio->insertChildren(0,itemsArbre); |
| 2724 | itemSolucio->setText(0,tr("Solució %1").arg(numeroSolucio)); |
| 2725 | arbreSolucionsTreeWidget->insertTopLevelItem(numeroSolucio-1,itemSolucio); |
| 2726 | qApp->processEvents(); |
| 2727 | progres.setValue(i); |
| 2728 | ++numeroSolucio; |
| 2729 | // qDebug("numeroSolucio",numeroSolucio); |
| 2730 | arbreModalitatsJocTreeWidget->expandAll(); |
| 2731 | if (progres.wasCanceled()) { break; } |
| 2732 | } |
| 2733 | } |
| 2734 | progres.close(); |
| 2735 | } |
| 2736 | else { |
| 2737 | //qDebug("No s'ha trobat les solucions"); |
| 2738 | QTreeWidgetItem *itemSolucio=new QTreeWidgetItem(); |
| 2739 | itemSolucio->setText(0,tr("No hi ha solucions")); |
| 2740 | //arbreSolucionsTreeWidget->clear(); |
| 2741 | arbreSolucionsTreeWidget->insertTopLevelItem(numeroSolucio-1,itemSolucio); |
| 2742 | } |
| 2743 | QTreeWidgetItem *itemCapcalera=new QTreeWidgetItem(); |
| 2744 | |
| 2745 | QString textCapcalera; |
| 2746 | if(tipusJocActual==0){ |
| 2747 | textCapcalera=arbreModalitatsJocTreeWidget->selectedItems().first()->text(0);} |
| 2748 | else if (tipusJocActual ==1){ |
| 2749 | textCapcalera=arbreModalitatsJocPersonalitzatsTreeWidget->selectedItems().first()->text(0);} |
| 2750 | |
| 2751 | textCapcalera.append(" ("+QString("%1").arg(numeroSolucio-1)+")"); |
| 2752 | itemCapcalera->setText(0,textCapcalera); |
| 2753 | arbreSolucionsTreeWidget->setHeaderItem(itemCapcalera); |
| 2754 | tabArbres->setTabText(1," ("+QString("%1").arg(numeroSolucio-1)+")"); |
| 2755 | tabArbres->setTabToolTip(1,tr("Solucions")+" ("+QString("%1").arg(numeroSolucio-1)+")"); |
| 2756 | |
| 2757 | qApp->processEvents(); |
| 2758 | QApplication::setOverrideCursor(Qt::ArrowCursor); |
| 2759 | } |
| 2760 | |
| 2761 | void frmPrincipal::carregaSolucio(QTreeWidgetItem*, int){ |
| 2762 | if(arbreSolucionsTreeWidget->selectedItems().first()->childCount()>0){ |
| 2763 | QMessageBox missatgeBox; |
| 2764 | missatgeBox.setText(tr("Carregar ")+arbreSolucionsTreeWidget->selectedItems().first()->text(0)); |
| 2765 | missatgeBox.setInformativeText(tr("De debó voleu carregar la solució? Perdreu els moviments que heu fet!")); |
| 2766 | missatgeBox.setIcon(QMessageBox::Question); |
| 2767 | missatgeBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); |
| 2768 | missatgeBox.setDefaultButton(QMessageBox::No); |
| 2769 | if(missatgeBox.exec()==QMessageBox::Yes){ |
| 2770 | carregaSolucio1(); |
| 2771 | statusBar()->showMessage(tr("S'ha carregat la ")+arbreSolucionsTreeWidget->selectedItems().first()->text(0)+ |
| 2772 | tr(". Feu servir els botons Avança i Retrocedeix per veure la solució. ")); |
| 2773 | } |
| 2774 | } |
| 2775 | } |
| 2776 | |
| 2777 | /* Carrega una solució seleccionada de l'arbre de solucions |
| 2778 | */ |
| 2779 | void frmPrincipal::carregaSolucio1(){ |
| 2780 | taulerJoc->setEstatDelJoc(solucio); |
| 2781 | iniciSolucioSlot(); |
| 2782 | |
| 2783 | //06/02/13 nou prod. |
| 2784 | actualitzaConfiguracionsInicials(); |
| 2785 | // solucioJocActual_configuracioInicial.clear(); |
| 2786 | // solucioJocActual_configuracioInicial.append(taulerJoc->configuracioActual(true)); |
| 2787 | // QStringList llista; |
| 2788 | // QString cadena; |
| 2789 | for(int i=0;i<arbreSolucionsTreeWidget->selectedItems().first()->childCount();i++){ |
| 2790 | QStringList movimentsSolucio= |
| 2791 | arbreSolucionsTreeWidget->selectedItems().first()->child(i)->text(1).split(" "); |
| 2792 | taulerJoc->ferMoviment(movimentsSolucio.value(0).toInt(), |
| 2793 | movimentsSolucio.value(1).toInt(), |
| 2794 | movimentsSolucio.value(2).toInt()); |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | /* |
| 2799 | Converteix les dades d'un moviment en número |
| 2800 | a coordenades |
| 2801 | */ |
| 2802 | QString frmPrincipal::movimentACoordenades(QString inici,QString final){ |
| 2803 | int numero_inici=inici.toInt(); |
| 2804 | int numero_final=final.toInt(); |
| 2805 | return QString("(%1,%2) -> (%3,%4)").arg(numero_inici/100).arg(numero_inici % 100). |
| 2806 | arg(numero_final/100).arg(numero_final % 100); |
| 2807 | } |
| 2808 | |
| 2809 | /* |
| 2810 | Converteix les dades d'un moviment en coordenades |
| 2811 | a números |
| 2812 | */ |
| 2813 | QString frmPrincipal::coordenadesAMoviment(QString coordenades){ |
| 2814 | QRegExp coord(".(\\d+),(\\d+). -> .(\\d+),(\\d+)."); |
| 2815 | if (coord.exactMatch(coordenades)){ |
| 2816 | int fitxaBotada=((coord.cap(1).toInt()+coord.cap(3).toInt())/2)*100+ |
| 2817 | ((coord.cap(2).toInt()+coord.cap(4).toInt())/2); |
| 2818 | return QString("%1 %2 %3").arg(coord.cap(1).toInt()*100+coord.cap(2).toInt()). |
| 2819 | arg(fitxaBotada). |
| 2820 | arg(coord.cap(3).toInt()*100+coord.cap(4).toInt()); |
| 2821 | } |
| 2822 | else { |
| 2823 | return QString("");} |
| 2824 | } |
| 2825 | |
| 2826 | /* |
| 2827 | Retorna el nom i directori de l'arxiu de dades/solucions del |
| 2828 | joc actual. |
| 2829 | tipus=1 -> arxiu amb les configuracions eliminades |
| 2830 | tipus=2 -> arxiu amb les solucions |
| 2831 | tipus=3 -> arxiu temporal de joc personalitzat |
| 2832 | tipus=4 -> arxiu de moviments provats en la recerca de solució .movi |
| 2833 | */ |
| 2834 | QString frmPrincipal::nomArxiuJoc(int tipus){ |
| 2835 | comprovaDirectoriHome(); |
| 2836 | QString nomArxiu=QDir::homePath (); |
| 2837 | QString extensio; |
| 2838 | if (tipus==1){ extensio=".txt";} |
| 2839 | else if (tipus==2){extensio=".sol";} |
| 2840 | else if (tipus==4){extensio=".movi";} |
| 2841 | else if (tipus==5){extensio=".arbre";} |
| 2842 | |
| 2843 | nomArxiu.append (QDir().separator()); |
| 2844 | nomArxiu.append (qApp->applicationName()); |
| 2845 | nomArxiu.append (QDir().separator()); |
| 2846 | // qCritical("codi joc actual desar arxiu %s",qPrintable(taulerJoc->modalitatJocActual())); |
| 2847 | if ( (taulerJoc->solitariPersonalitzat()) || |
| 2848 | (taulerJoc->solitariModificat()) ){ |
| 2849 | // qDebug("nomArxiuJoc solitari personalizat"); |
| 2850 | nomArxiu.append(QString(solucioJocActual_configuracioInicial+"_"+ |
| 2851 | QString("%1").arg(seguentCodiSolitariPersonalitzat)+extensio)); |
| 2852 | } |
| 2853 | else { |
| 2854 | // qDebug("nomArxiuJoc solitari NO personalizat"); |
| 2855 | nomArxiu.append (QString(solucioJocActual_configuracioInicial+"_"+ |
| 2856 | QString("%1").arg(taulerJoc->modalitatJocActual())+extensio)); |
| 2857 | } |
| 2858 | //qCritical("nomArxiu %s", qPrintable(nomArxiu)); |
| 2859 | return nomArxiu; |
| 2860 | } |
| 2861 | |
| 2862 | /* |
| 2863 | Comprova que existeix el directori /Solitari |
| 2864 | en el directori d'usuari |
| 2865 | */ |
| 2866 | void frmPrincipal::comprovaDirectoriHome(){ |
| 2867 | QDir dirArxiu(QDir::homePath ()); |
| 2868 | if (!dirArxiu.exists(qApp->applicationName())){ |
| 2869 | dirArxiu.mkdir(qApp->applicationName()); |
| 2870 | } |
| 2871 | } |
| 2872 | |
| 2873 | void frmPrincipal::comprovaRegistre(){ |
| 2874 | QSettings registre; |
| 2875 | // int reg=registre.value( QString("General/Registre"),0).toInt(); |
| 2876 | if (registre.value( QString("General/Registre"),0).toInt()==0){ |
| 2877 | if(QDesktopServices::openUrl(ADRECA_WEB_REGISTRE)){ |
| 2878 | QSettings().setValue("General/Registre",1); |
| 2879 | }; |
| 2880 | } |
| 2881 | } |
| 2882 | |
| 2883 | /* |
| 2884 | Retorna la cadena amb el missatge del número de moviments realitzats |
| 2885 | i total. |
| 2886 | Cal que s'hagi executat taulerJoc->numeroDeMovimentsJoc() per tenir |
| 2887 | acutalitzades les dades del nombre de fitxes del joc |
| 2888 | */ |
| 2889 | QString frmPrincipal::missatgeNumeroMoviments(int maxim){ |
| 2890 | QString numMovAct=QString("%1").arg(movimentsUndoStack->index()); |
| 2891 | //QString totalMovJoc=QString("%1").arg(taulerJoc->numeroDeMovimentsJoc()); |
| 2892 | QString totalMovJoc=QString("%1").arg(maxim); |
| 2893 | //qCritical("numMovAct %s", qPrintable(numMovAct)); |
| 2894 | //qCritical("totalMovJoc %s", qPrintable(totalMovJoc)); |
| 2895 | //if(movimentsUndoStack->index()>=maxim){ |
| 2896 | // qDebug("Problema!!!!!"); |
| 2897 | //} |
| 2898 | |
| 2899 | while (numMovAct.length()<totalMovJoc.length() && numMovAct !="0"){numMovAct.prepend("0");} |
| 2900 | return QString(tr("Moviment ")+numMovAct+tr(" de %1").arg(totalMovJoc)); |
| 2901 | //return QString(tr("Moviment ")+numMovAct+tr(" de %1").arg(maxim)); |
| 2902 | } |
| 2903 | |
| 2904 | /* |
| 2905 | Copia l'arxiu de solucions en el directori |
| 2906 | de l'usuari |
| 2907 | */ |
| 2908 | void frmPrincipal::comprovaArxiuSolucions(){ |
| 2909 | // return; |
| 2910 | comprovaDirectoriHome(); |
| 2911 | QString nomArxiuDesti=QDir::homePath (); |
| 2912 | nomArxiuDesti.append (QDir().separator()); |
| 2913 | nomArxiuDesti.append (qApp->applicationName()); |
| 2914 | nomArxiuDesti.append (QDir().separator()); |
| 2915 | nomArxiuDesti.append(QString(solucioJocActual_configuracioInicial+"_"+ |
| 2916 | QString("%1").arg(taulerJoc->modalitatJocActual())+".sol")); |
| 2917 | |
| 2918 | QString nomArxiuInicial=directoriLinux(); |
| 2919 | nomArxiuInicial.append(QDir().separator()); |
| 2920 | nomArxiuInicial.append(DIRECTORI_DADES); |
| 2921 | nomArxiuInicial.append(QDir().separator()); |
| 2922 | nomArxiuInicial.append(QString(solucioJocActual_configuracioInicial+"_"+ |
| 2923 | QString("%1").arg(taulerJoc->modalitatJocActual())+".sol")); |
| 2924 | // qDebug("Directori Linux %s",qPrintable(nomArxiuInicial)); |
| 2925 | |
| 2926 | QFile arxiu(nomArxiuInicial); |
| 2927 | arxiu.copy(nomArxiuDesti); |
| 2928 | } |
| 2929 | |
| 2930 | /* Comprova si hi ha un arxiu amb solucions del joc actual |
| 2931 | * en el directorio /games |
| 2932 | * Es fa servir per saber si el programa aconsegueix resoldre |
| 2933 | * el joc sense fer servir dades de solucions prèvies*/ |
| 2934 | bool frmPrincipal::comprovaDadesSolucions(){ |
| 2935 | QString nomArxiuInicial=directoriLinux(); |
| 2936 | nomArxiuInicial.append(QDir().separator()); |
| 2937 | nomArxiuInicial.append(DIRECTORI_DADES); |
| 2938 | nomArxiuInicial.append(QDir().separator()); |
| 2939 | nomArxiuInicial.append(QString(solucioJocActual_configuracioInicial+"_"+ |
| 2940 | QString("%1").arg(taulerJoc->modalitatJocActual())+".sol")); |
| 2941 | // qCritical("%s",qPrintable(nomArxiuInicial)); |
| 2942 | QDir dirArxiu(QDir::homePath ()); |
| 2943 | if (!dirArxiu.exists(nomArxiuInicial)){ |
| 2944 | // qDebug("No existeix"); |
| 2945 | return false; |
| 2946 | } |
| 2947 | else return true; |
| 2948 | } |
| 2949 | |
| 2950 | /* Comprova si les dades de les fitxes es corresponen |
| 2951 | * amb una modalitat de final marcat |
| 2952 | */ |
| 2953 | bool frmPrincipal::esSolitariAmbFinalMarcat(QString dadesFitxes){ |
| 2954 | return ( dadesFitxes.contains("11")) |
| 2955 | ||(dadesFitxes.contains("10")); |
| 2956 | } |
| 2957 | |
| 2958 | /* Comprova si hi ha alguna solució a l'arbre |
| 2959 | * de solucions |
| 2960 | */ |
| 2961 | bool frmPrincipal::noHiHaSolucionsArbreSolucions(){ |
| 2962 | if(arbreSolucionsTreeWidget->topLevelItemCount()>0){ |
| 2963 | return arbreSolucionsTreeWidget->topLevelItem(0)->text(0). |
| 2964 | contains(tr("No hi ha solucions")) ;} |
| 2965 | else return true; |
| 2966 | } |
| 2967 | |
| 2968 | //Mostra un missatge passat pel tauler del joc |
| 2969 | void frmPrincipal::mostraMissatge(int codi){ |
| 2970 | switch (codi) { |
| 2971 | case 0: |
| 2972 | statusBar()->showMessage(tr("No hi ha més moviments: el joc ha finalitzat!")); |
| 2973 | break; |
| 2974 | case 1: |
| 2975 | statusBar()->showMessage(tr("Joc resolt!")); |
| 2976 | break; |
| 2977 | case 2: |
| 2978 | QMessageBox::information(this,tr("Nova marca personal"), |
| 2979 | tr("Heu establert un nou record personal en aquesta modalitat de joc")); |
| 2980 | if(arbreModalitatsJocTreeWidget->selectedItems().count()==1){ |
| 2981 | QTreeWidgetItem *item=arbreModalitatsJocTreeWidget->selectedItems().first(); |
| 2982 | QStringList dades=item->text(1).split(" "); |
| 2983 | item->setIcon(0,QIcon(posaIconeOK(dades.value(0)))); |
| 2984 | } |
| 2985 | break; |
| 2986 | case 3: |
| 2987 | statusBar()->showMessage(/* |
| 2988 | missatgeNumeroMoviments(0));*/ |
| 2989 | QString(tr("Moviment %1 de %2 ")).arg(movimentsUndoStack->index()). |
| 2990 | arg(taulerJoc->numeroDeMovimentsJoc())); |
| 2991 | break; |
| 2992 | case 4: |
| 2993 | statusBar()->showMessage(/*missatgeNumeroMoviments(0));*/ |
| 2994 | QString(tr("Moviment %1 de %2 ")) |
| 2995 | .arg(movimentsUndoStack->index()) |
| 2996 | .arg(taulerJoc->numeroDeMovimentsJoc())); |
| 2997 | // .arg(solucionaJocActual_numeroDeFitxesDelJoc()-1)); |
| 2998 | break; |
| 2999 | case 5: |
| 3000 | statusBar()->showMessage(tr("No hi ha moviments!")); |
| 3001 | break; |
| 3002 | case 100: |
| 3003 | statusBar()->showMessage(" "); |
| 3004 | break; |
| 3005 | } |
| 3006 | // if(codi>3){ |
| 3007 | // statusBar()->showMessage( |
| 3008 | // QString(tr("jocsRealitzats %1 ")).arg(codi));//} |
| 3009 | } |
| 3010 | |
| 3011 | /* Procediments dels solitaris a l'atzar |
| 3012 | */ |
| 3013 | void frmPrincipal::solitariAtzar_generaJoc(){ |
| 3014 | |
| 3015 | solitariAtzar_eliminaArxiuSolucio(); |
| 3016 | |
| 3017 | //Primer cal generar les dades per construir un joc a l'atzar |
| 3018 | |
| 3019 | //Tipus de moviment del solitari final |
| 3020 | int tipus_MovimentGenerat = (qrand() % 3); |
| 3021 | //tipus_MovimentGenerat=2; |
| 3022 | //Tipus de moviment en el procés de generació del joc |
| 3023 | int tipusMovimentGenerador; |
| 3024 | //Tipus de fitxa en l'inici de la generació del solitari |
| 3025 | QString tipusFitxa="10"; |
| 3026 | if (tipus_MovimentGenerat==0){tipus_MovimentGenerat=3;} |
| 3027 | //qDebug("tipus_MovimentGenerat %d",tipus_MovimentGenerat); |
| 3028 | //Retorna el tipus de moviment per generar el solitari |
| 3029 | //i el tipus de fitxa |
| 3030 | tipusMovimentGenerador= |
| 3031 | solitariAtzar_tipusMovimentGenerador(tipus_MovimentGenerat,tipusFitxa); |
| 3032 | //Assegurem que hi haurà un nombre mínim de files i columnes |
| 3033 | int minimFilesColumnes=5; |
| 3034 | int maximFilesColumnes=30; |
| 3035 | int maximNumeroFitxes=50; |
| 3036 | int num_Files= 0; |
| 3037 | while (num_Files<minimFilesColumnes){ |
| 3038 | num_Files=(qrand() % maximFilesColumnes)+1; |
| 3039 | } |
| 3040 | int num_Columnes=0; |
| 3041 | while ( (num_Columnes<minimFilesColumnes) || |
| 3042 | (num_Columnes>num_Files+4) ){ |
| 3043 | num_Columnes=(qrand() % maximFilesColumnes)+1; |
| 3044 | } |
| 3045 | //Seleccionam la fitxa inicial per jugar |
| 3046 | int fitxa_Inicial=(qrand() % (num_Files*num_Columnes))+1; |
| 3047 | QString dades_Fitxes; |
| 3048 | bool fitxa=false; |
| 3049 | //generam les dades de les fitxes per al tauler de joc |
| 3050 | for(int j=0 ; j<num_Files;j++){ |
| 3051 | for(int i=1 ; i<=num_Columnes;i++){ |
| 3052 | if( (j*num_Columnes+i==fitxa_Inicial) && !fitxa){ |
| 3053 | dades_Fitxes=dades_Fitxes+tipusFitxa.mid(0,1)+" "; |
| 3054 | fitxa=true; |
| 3055 | } |
| 3056 | else dades_Fitxes=dades_Fitxes+tipusFitxa.mid(1,1)+" "; |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | //Fem invisible el tauler de joc per evitar |
| 3061 | //el molest "parpadeig" mentre es genera el joc |
| 3062 | taulerJoc->setVisible(false); |
| 3063 | //Carregam el joc |
| 3064 | taulerJoc->joc_CarregaJoc(QString("1000 %1 100 0").arg(tipusMovimentGenerador), |
| 3065 | QString("%1 %2").arg(num_Files).arg(num_Columnes), |
| 3066 | dades_Fitxes.simplified()); |
| 3067 | |
| 3068 | //Aqui es comença a jugar per generar el solitari |
| 3069 | QStringList llistaMoviments; |
| 3070 | //Seleccionam a l'atzar el número de fitxes actives que tendrà el solitari |
| 3071 | //(garantint que hi haurà un mínim de fitxes! 14) |
| 3072 | int numeroFitxes=0; |
| 3073 | while ( (numeroFitxes<minimFilesColumnes*minimFilesColumnes*0.2) || |
| 3074 | (numeroFitxes>maximNumeroFitxes)){ |
| 3075 | numeroFitxes=(qrand() % qRound(num_Files*num_Columnes*0.3)); |
| 3076 | } |
| 3077 | //Ara es juga fins a assolir el nombre de fitxes actives |
| 3078 | for(int j=0 ; j<numeroFitxes;j++){ |
| 3079 | taulerJoc->solucionaJocActual_CalculaMovimentsPosibles(); |
| 3080 | llistaMoviments= |
| 3081 | taulerJoc->solucionaJocActual_CarregaMovimentsArbre1(llistaMoviments,QString("")); |
| 3082 | //qDebug("llistaMoviments %d",llistaMoviments.count()); |
| 3083 | if (llistaMoviments.count()>0){ |
| 3084 | QStringList moviment=llistaMoviments |
| 3085 | .value(qrand() % llistaMoviments.count()).split(" "); |
| 3086 | taulerJoc->ferMoviment(moviment.value(0).toInt(), |
| 3087 | moviment.value(1).toInt(), |
| 3088 | moviment.value(2).toInt(),false); |
| 3089 | /* Si el tipus de moviment del joc és directe o diagonal, |
| 3090 | * és el primer moviment |
| 3091 | * i una vegada de cada 2, es marca la fitxa inicial com |
| 3092 | * a fitxa final de joc |
| 3093 | */ |
| 3094 | if ( (tipus_MovimentGenerat != 2) && |
| 3095 | ( (qrand() % 2) == 1) && |
| 3096 | (j==0) ){ |
| 3097 | taulerJoc->solitariAtzar_MarcaFitxaUsada(moviment.value(0).toInt(),true); |
| 3098 | } |
| 3099 | else taulerJoc->solitariAtzar_MarcaFitxaUsada(moviment.value(0).toInt()); |
| 3100 | taulerJoc->solitariAtzar_MarcaFitxaUsada(moviment.value(1).toInt()); |
| 3101 | taulerJoc->solitariAtzar_MarcaFitxaUsada(moviment.value(2).toInt()); |
| 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | //Generam les dades de les fitxes del solitari generat |
| 3106 | dades_Fitxes=taulerJoc->solitariAtzar_dadesEstatFitxes(num_Files,num_Columnes); |
| 3107 | statusBar()->showMessage(""); |
| 3108 | //qCritical("%s", qPrintable(dades_Fitxes)); |
| 3109 | //solitariAtzar_generaImatge(); |
| 3110 | |
| 3111 | //Carregam les dades a l'ítem de l'arbre del joc |
| 3112 | /*num_Files=8; |
| 3113 | num_Columnes=6; |
| 3114 | dades_Fitxes="-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 0 -1 -1 0 -1 0 0 1 1 1 0 -1 0 0 1 0 -1"; |
| 3115 | */ |
| 3116 | solitariAtzar_carregaDadesArbreJoc( |
| 3117 | QString("1000 %1 10 1").arg(tipus_MovimentGenerat), |
| 3118 | QString("%1 %2").arg(num_Files).arg(num_Columnes), |
| 3119 | dades_Fitxes); |
| 3120 | //qDebug("Files %d *****",num_Files); |
| 3121 | //qDebug("Columnes %d *****\n",num_Columnes); |
| 3122 | //qCritical("%s", qPrintable(dades_Fitxes)); |
| 3123 | //qDebug("*****"); |
| 3124 | solitariAtzar_solucio.clear(); |
| 3125 | solitariAtzar_solucio=solitariAtzar_inverteixSolucioJocGenerat(); |
| 3126 | //Carregam el joc |
| 3127 | seleccioModalitatJoc(); |
| 3128 | taulerJoc->setVisible(true); |
| 3129 | //desam la solució a un arxiu |
| 3130 | solitariAtzar_desaSolucio(); |
| 3131 | //La carregam a l'arbre de solucions |
| 3132 | veureSolucionsSlot(); |
| 3133 | } |
| 3134 | |
| 3135 | /* Retorna el tipus de moviment del joc |
| 3136 | * en el procés de generació del solitaria l'atzar |
| 3137 | * El paràmetre té els codis de les fitxes a l'inici |
| 3138 | * de la generació del solitari |
| 3139 | */ |
| 3140 | int frmPrincipal::solitariAtzar_tipusMovimentGenerador( |
| 3141 | int tipusMoviementGenerat, QString &tipusFitxa){ |
| 3142 | int tipusRetorn=1; |
| 3143 | switch (tipusMoviementGenerat) { |
| 3144 | case 1: |
| 3145 | tipusRetorn=2; |
| 3146 | tipusFitxa="10"; |
| 3147 | break; |
| 3148 | case 2: |
| 3149 | tipusRetorn=1; |
| 3150 | tipusFitxa="01"; |
| 3151 | break; |
| 3152 | case 3: |
| 3153 | tipusRetorn=5; |
| 3154 | tipusFitxa="10"; |
| 3155 | break; |
| 3156 | } |
| 3157 | return tipusRetorn; |
| 3158 | } |
| 3159 | |
| 3160 | /* Carrega les dades del solitari generat a l'ítem de l'arbre |
| 3161 | */ |
| 3162 | void frmPrincipal::solitariAtzar_carregaDadesArbreJoc(QString codi,QString FilesColumnes, |
| 3163 | QString dadesFitxes){ |
| 3164 | QTreeWidgetItem *item; |
| 3165 | item=arbreModalitatsJocTreeWidget->selectedItems().first(); |
| 3166 | item->setText(1,codi); |
| 3167 | item->setText(2,FilesColumnes); |
| 3168 | item->setText(3,dadesFitxes); |
| 3169 | } |
| 3170 | |
| 3171 | /* Abans de posar en marxa el procés de cercar solució |
| 3172 | * es comprova si estem en un solitari generat a l'atzar |
| 3173 | * En aquest cas, la solució ja és coneguda i, simplement |
| 3174 | * es carrega |
| 3175 | */ |
| 3176 | bool frmPrincipal::solitariAtzar_CarregaSolucio(){ |
| 3177 | bool retorn=false; |
| 3178 | QTreeWidgetItem *item; |
| 3179 | item=arbreModalitatsJocTreeWidget->selectedItems().first(); |
| 3180 | if(solitariAtzar_esAtzar(item->text(1))){ |
| 3181 | solucionsTrobades.clear(); |
| 3182 | solucionsTrobades.append(solitariAtzar_solucio); |
| 3183 | retorn=true; |
| 3184 | } |
| 3185 | return retorn; |
| 3186 | } |
| 3187 | |
| 3188 | /* En haver generat un joc, es transforma els moviments de |
| 3189 | * movimentsUndoStack en al solució del joc |
| 3190 | * (invertint els moviments) |
| 3191 | */ |
| 3192 | QString frmPrincipal::solitariAtzar_inverteixSolucioJocGenerat(){ |
| 3193 | //La pila de moviments està en el final de tot |
| 3194 | //Llegim la informació de la pila del final al principi |
| 3195 | QString movimentsSolucio; |
| 3196 | for(int j=0 ; j<movimentsUndoStack->count();j++){ |
| 3197 | movimentsSolucio.append(QString("%1 ").arg(j+1)); |
| 3198 | movimentsSolucio.append( |
| 3199 | solitariAtzar_coordenadesAMoviment( |
| 3200 | movimentsUndoStack->text(movimentsUndoStack->count()-j-1))); |
| 3201 | } |
| 3202 | return movimentsSolucio.simplified(); |
| 3203 | } |
| 3204 | |
| 3205 | /* Converteix les coordenades de un moviment a dades |
| 3206 | * però invertint el moviment |
| 3207 | * (simplement s'inverteixen les fitxes final i inicial |
| 3208 | */ |
| 3209 | QString frmPrincipal::solitariAtzar_coordenadesAMoviment(QString coordenades){ |
| 3210 | QRegExp coord(".(\\d+),(\\d+). -> .(\\d+),(\\d+)."); |
| 3211 | if (coord.exactMatch(coordenades)){ |
| 3212 | int fitxaBotada=((coord.cap(1).toInt()+coord.cap(3).toInt())/2)*100+ |
| 3213 | ((coord.cap(2).toInt()+coord.cap(4).toInt())/2); |
| 3214 | return QString("%1 %2 %3 ").arg(coord.cap(3).toInt()*100+coord.cap(4).toInt()). |
| 3215 | arg(fitxaBotada). |
| 3216 | arg(coord.cap(1).toInt()*100+coord.cap(2).toInt()) |
| 3217 | ; |
| 3218 | } |
| 3219 | else { |
| 3220 | return QString("");} |
| 3221 | } |
| 3222 | |
| 3223 | /* Desa a un arxiu la solució del solitari |
| 3224 | * generat a l'atzar |
| 3225 | */ |
| 3226 | void frmPrincipal::solitariAtzar_desaSolucio(){ |
| 3227 | comprovaDirectoriHome(); |
| 3228 | QString nomArxiu=nomArxiuJoc(2); |
| 3229 | carregaSolucions(); |
| 3230 | QFile arxiu(nomArxiu); |
| 3231 | if (arxiu.open(QIODevice::Append)){ |
| 3232 | QTextStream entrada(&arxiu); |
| 3233 | entrada<<(QString("%1\n").arg(solitariAtzar_solucio)) ; |
| 3234 | } |
| 3235 | arxiu.close(); |
| 3236 | } |
| 3237 | |
| 3238 | /* Gestiona el canvi de la selecció de joc per controlar |
| 3239 | * el tipus de joc de generació a l'atzar |
| 3240 | * elimina les dades del ítem a l'atzar per permetre la |
| 3241 | * generació en tornar a seleccionar |
| 3242 | */ |
| 3243 | void frmPrincipal::canviItemArbreJoc(QTreeWidgetItem *actual, |
| 3244 | QTreeWidgetItem *anterior){ |
| 3245 | |
| 3246 | if(anterior != NULL){ |
| 3247 | if(solitariAtzar_esAtzar(anterior->text(1))){ |
| 3248 | anterior->setText(3,"0"); |
| 3249 | //eliminam la solució anterior |
| 3250 | solitariAtzar_solucio.clear(); |
| 3251 | //eliminam l'arxiu de solucions i els |
| 3252 | //de suport |
| 3253 | solitariAtzar_eliminaArxiuSolucio(); |
| 3254 | } |
| 3255 | else if(solitariPersonalitzat_esPersonalitzat(anterior->text(1))){ |
| 3256 | //eliminam la solució anterior |
| 3257 | solitariAtzar_solucio.clear(); |
| 3258 | solitariPersonalitzat_eliminaArxiuSolucio(); |
| 3259 | } |
| 3260 | } |
| 3261 | } |
| 3262 | |
| 3263 | /* Gestiona el doble clic sobre l'ítem de la generació |
| 3264 | * a l'atzar de solitaris |
| 3265 | */ |
| 3266 | void frmPrincipal::dobleClickArbreJoc(QTreeWidgetItem *item, int columne){ |
| 3267 | //estem fent doble clic al node de generacíó |
| 3268 | //a l'atzar |
| 3269 | if(solitariAtzar_esAtzar(item->text(1))){ |
| 3270 | solitariAtzar_generaJoc(); |
| 3271 | } |
| 3272 | /* en cas contrari, carregam el joc |
| 3273 | * Això és necessari per als jocs |
| 3274 | * personalitzats |
| 3275 | */ |
| 3276 | else seleccioModalitatJoc(); |
| 3277 | } |
| 3278 | |
| 3279 | /* genera una imatge del primer pas del procés de generació |
| 3280 | * d'un joc a l'atzar |
| 3281 | */ |
| 3282 | void frmPrincipal::solitariAtzar_generaImatge(){ |
| 3283 | QPixmap pixMap = QPixmap::grabWidget(taulerJoc); |
| 3284 | pixMap.createMaskFromColor(Qt::white,Qt::MaskInColor); |
| 3285 | QString nomArxiuImatge="solitariAtzar.png"; |
| 3286 | pixMap.save(nomArxiuImatge); |
| 3287 | } |
| 3288 | |
| 3289 | /* Elimina l'arxiu de la solució del solitari actual |
| 3290 | */ |
| 3291 | void frmPrincipal::solitariAtzar_eliminaArxiuSolucio(){ |
| 3292 | if(arbreModalitatsJocTreeWidget->selectedItems().count()>0){ |
| 3293 | if(solitariAtzar_esAtzar( |
| 3294 | arbreModalitatsJocTreeWidget->selectedItems().first()->text(1))){ |
| 3295 | comprovaDirectoriHome(); |
| 3296 | QString nomArxiu=nomArxiuJoc(2); |
| 3297 | //Això és necessari per evitar eliminar arxius d'altres |
| 3298 | //jocs que tenguin solucions noves |
| 3299 | if(solitariAtzar_esAtzar(nomArxiu)){ |
| 3300 | QFile arxiu(nomArxiu); |
| 3301 | if (arxiu.exists()){ |
| 3302 | arxiu.remove(); |
| 3303 | qApp->processEvents(); |
| 3304 | nomArxiu=nomArxiuJoc(1); |
| 3305 | QFile arxiu1(nomArxiu); |
| 3306 | arxiu1.remove(); |
| 3307 | qApp->processEvents(); |
| 3308 | } |
| 3309 | } |
| 3310 | }//if arbre-text |
| 3311 | }//if arbre-count |
| 3312 | } |
| 3313 | |
| 3314 | /* Determina si el solitari actual és o no |
| 3315 | * a l'atzar |
| 3316 | */ |
| 3317 | bool frmPrincipal::solitariAtzar_esAtzar(QString joc){ |
| 3318 | /* La segona condició s'ha afegit per evitar errors |
| 3319 | * quan es fa la comprovació amb el nom de l'arxiu |
| 3320 | * de solucions |
| 3321 | */ |
| 3322 | return (joc.contains("1000") || joc.contains(" _1000") ); |
| 3323 | } |
| 3324 | |
| 3325 | /* Jocs personalitzats |
| 3326 | * Són els jocs inventats per l'usuari amb els ítems |
| 3327 | * Personalitzat (diagonal/invers) o bé modificaNT |
| 3328 | * un joc del programa. |
| 3329 | * Una vegada l'usuari ha generat les fitxes, en |
| 3330 | * començar a jugar o clicar el sistema de cerca de |
| 3331 | * solució, es recalculen les dades del nou joc. |
| 3332 | * Es controla si el joc és personalitzat amb els |
| 3333 | * codis de joc de l'arbreModalitatsJocTreeWidget, la |
| 3334 | * funció solitariPersonalitzat_esPersonalitzat, |
| 3335 | * la propietat taulerJoc.solitariPersonalitzat(), la |
| 3336 | * propietat taulerJoc.solitariModificat() i la propietat |
| 3337 | * fitxa.p_fitxaSolitariPersonalitzat. |
| 3338 | * Si s'aconseguix trobar una solució, llavors les dades |
| 3339 | * del nou joc s'afegeixen a l'arbre de jocs personalitzats |
| 3340 | * i a l'arxiu de dades /Solitari/game-per.dat |
| 3341 | * A cada nou joc personalitzat se li assigna un codi que |
| 3342 | * es va actualitzant a l'arxiu ini de conf (i comença amb 10000). |
| 3343 | * S'ha fet bastant complexe conservar les dades a l'arxiu de solucions |
| 3344 | */ |
| 3345 | |
| 3346 | /* Calcula les dades de les fitxes del solitari personalitzat |
| 3347 | * i carrega el joc |
| 3348 | */ |
| 3349 | void frmPrincipal::solitariPersonalitzat_dadesFitxes(){ |
| 3350 | //Cal actualitzar això primer |
| 3351 | taulerJoc->configuracioActual(true); |
| 3352 | /* Si ja hi ha una solució a l'arbre de solucions, |
| 3353 | * llavors no és necessari res de tot això |
| 3354 | */ |
| 3355 | if ( !noHiHaSolucionsArbreSolucions() && taulerJoc->solitariPersonalitzat()){ |
| 3356 | return;} |
| 3357 | /* 13/02/13 no pareix que això sigui necessari |
| 3358 | * S'ha eliminat |
| 3359 | */ |
| 3360 | /*else if ( (tipusJocActual==1) //|| (!taulerJoc->solitariModificat()) |
| 3361 | || (taulerJoc->solitariPersonalitzat()) ){ |
| 3362 | //Això és necessari per poder jugar |
| 3363 | taulerJoc->marcaFitxesSolitariPersonalitzat(false); |
| 3364 | return; |
| 3365 | }*/ |
| 3366 | else if (taulerJoc->numeroDeMovimentsJoc()<1){ |
| 3367 | return; |
| 3368 | } |
| 3369 | /*primer comprovam si es tracte d'un joc |
| 3370 | *personalitzat/mod.*/ |
| 3371 | if( (taulerJoc->solitariPersonalitzat()) || |
| 3372 | (taulerJoc->solitariModificat()) ){ |
| 3373 | //Això per si ja s'ha intentat trobar una solució per al solitari |
| 3374 | iniciSolucioSlot(); |
| 3375 | //obtenim les dades del solitari |
| 3376 | QStringList dadesFitxes=taulerJoc->solitariPersonalitzat_dadesFitxes(); |
| 3377 | //carregam el joc |
| 3378 | QString dades; |
| 3379 | if(p_arbreJocsActual==0){ //és un joc del programa |
| 3380 | dades=arbreModalitatsJocTreeWidget->selectedItems().first()->text(1);} |
| 3381 | else if (p_arbreJocsActual==1){ //és un joc de l'arbre de personalitzats/mod |
| 3382 | dades=arbreModalitatsJocPersonalitzatsTreeWidget->selectedItems().first()->text(1); |
| 3383 | } |
| 3384 | seguentCodiSolitariPersonalitzat.clear(); |
| 3385 | seguentCodiSolitariPersonalitzat.append(solitariPersonalitzat_nouCodiJoc(false)); |
| 3386 | taulerJoc->joc_CarregaJoc( |
| 3387 | dades, |
| 3388 | dadesFitxes.value(0), |
| 3389 | dadesFitxes.value(1)); |
| 3390 | taulerJoc->configuracioActual(true); |
| 3391 | |
| 3392 | //06/02/13 nou prod. |
| 3393 | actualitzaConfiguracionsInicials(); |
| 3394 | } |
| 3395 | //}//if arbreModalitatsJocTreeWidget |
| 3396 | } |
| 3397 | |
| 3398 | /* Quan es resol un solitari personalitzat |
| 3399 | * es desa a l'arbre de jocs personalitzats |
| 3400 | * (prèvia comprovació de que no està repetit) |
| 3401 | */ |
| 3402 | void frmPrincipal::solitariPersonalitzat_desarSolitari(){ |
| 3403 | /* Primer comprovam si el solitari ja està a l'arbre de solitaris |
| 3404 | * personalitzats |
| 3405 | */ |
| 3406 | solitariPersonalitzat_comprovaArbre(); |
| 3407 | } |
| 3408 | |
| 3409 | /* Comprova si el solitari personalitzat ja està |
| 3410 | * a l'arbre de solitaris personalitzats |
| 3411 | */ |
| 3412 | void frmPrincipal::solitariPersonalitzat_comprovaArbre(){ |
| 3413 | bool jocTrobat=false; |
| 3414 | //Capturam les dades del joc personalitzat actual |
| 3415 | //Primer cal tornar a l'inici del joc |
| 3416 | iniciSolucioSlot(); |
| 3417 | QStringList dadesFitxes=taulerJoc->solitariPersonalitzat_dadesFitxes(); |
| 3418 | |
| 3419 | if(arbreModalitatsJocPersonalitzatsTreeWidget->topLevelItemCount()>0){ |
| 3420 | for(int i=0 ; i<arbreModalitatsJocPersonalitzatsTreeWidget->topLevelItemCount();++i){ |
| 3421 | QString tipusJoc=arbreModalitatsJocPersonalitzatsTreeWidget |
| 3422 | ->topLevelItem(i)->text(1).split(" ").value(1); |
| 3423 | tipusJoc=" "+tipusJoc+" "; |
| 3424 | if( (arbreModalitatsJocPersonalitzatsTreeWidget-> |
| 3425 | topLevelItem(i)->text(3)==dadesFitxes.value(1)) && |
| 3426 | (taulerJoc->p_tipusMoviment==tipusJoc.toInt()) ){ |
| 3427 | jocTrobat=true; |
| 3428 | } |
| 3429 | } |
| 3430 | } |
| 3431 | if(!jocTrobat){ |
| 3432 | QString nouCodi=solitariPersonalitzat_afegeixJoc(dadesFitxes); |
| 3433 | //renomenam l'arxiu de solucions |
| 3434 | solitariPersonalitzat_renomenaArxiuSolucio(nouCodi); |
| 3435 | //Eliminan els arxius .sol i .txt que hi pugui haver |
| 3436 | //de la modalitat de generació de solitaris |
| 3437 | solitariPersonalitzat_eliminaArxiuSolucio(); |
| 3438 | taulerJoc->setModalitatJocActual(nouCodi); |
| 3439 | //Tornam la situació al final de la solució |
| 3440 | finalSolucioSlot(true); |
| 3441 | } |
| 3442 | //Si el joc ja existeix, no té cap sentit conservar els arxius |
| 3443 | else {solitariPersonalitzat_eliminaArxiuSolucio(); |
| 3444 | //Tornam la situació al final de la solució |
| 3445 | //sense marcar el final del joc |
| 3446 | finalSolucioSlot(false);} |
| 3447 | } |
| 3448 | |
| 3449 | /* Afegeix un joc personalitzat a l'arbre |
| 3450 | */ |
| 3451 | QString frmPrincipal::solitariPersonalitzat_afegeixJoc(QStringList dadesJocList){ |
| 3452 | |
| 3453 | QTreeWidgetItem *item=new QTreeWidgetItem(); |
| 3454 | QString nouCodiSolitari=solitariPersonalitzat_nouCodiJoc(true); |
| 3455 | /* Capturam el nom del joc original |
| 3456 | * sense afegitons |
| 3457 | */ |
| 3458 | /*QString nomSolitari=nomDelJoc( |
| 3459 | arbreModalitatsJocTreeWidget->selectedItems().first()->text(4),false)+ |
| 3460 | afageixTipusMovimentNomJoc( |
| 3461 | arbreModalitatsJocTreeWidget->selectedItems().first()->text(1)) |
| 3462 | +" "+nouCodiSolitari;*/ |
| 3463 | QString nomSolitari=nomDelJoc( |
| 3464 | taulerJoc->nomJocActual(),false)+ |
| 3465 | afageixTipusMovimentNomJoc( |
| 3466 | QString(" %1 ").arg(taulerJoc->p_tipusMoviment)) |
| 3467 | // arbreModalitatsJocTreeWidget->selectedItems().first()->text(1)) |
| 3468 | +" "+nouCodiSolitari; |
| 3469 | if(esSolitariAmbFinalMarcat(dadesJocList.value(1))) { |
| 3470 | nomSolitari=nomSolitari+" *" ;} |
| 3471 | |
| 3472 | item->setText(0,nomSolitari); |
| 3473 | item->setToolTip(0,item->text(0)); |
| 3474 | //linea 0: codi joc, tipus moviment |
| 3475 | // QStringList dadesAntigues= |
| 3476 | // arbreModalitatsJocTreeWidget->selectedItems().first()->text(1).split(" "); |
| 3477 | |
| 3478 | //El codi del joc es reemplaça pel nou |
| 3479 | item->setText(1, |
| 3480 | QString("%1 %2 5 0").arg(nouCodiSolitari). |
| 3481 | arg(taulerJoc->p_tipusMoviment) ); |
| 3482 | //Actualitzat per els nous jocs |
| 3483 | //que són modificació d'altres ja existents |
| 3484 | // arg(dadesAntigues.value(1)) ); |
| 3485 | //linea 1: files i columnes |
| 3486 | item->setText(2,dadesJocList.value(0)); |
| 3487 | //linea 2: estat de les fitxes |
| 3488 | item->setText(3,dadesJocList.value(1)); |
| 3489 | //item->setText(4,arbreModalitatsJocTreeWidget->selectedItems().first()->text(4)); |
| 3490 | item->setText(4,taulerJoc->nomJocActual()); |
| 3491 | arbreModalitatsJocPersonalitzatsTreeWidget->addTopLevelItem(item); |
| 3492 | arbreModalitatsJocPersonalitzatsTreeWidget->expandAll(); |
| 3493 | arbreModalitatsJocPersonalitzatsTreeWidget->sortItems(0,Qt::AscendingOrder); |
| 3494 | |
| 3495 | |
| 3496 | //Actualitzam la capçalera |
| 3497 | QTreeWidgetItem *itemCapcalera=new QTreeWidgetItem(); |
| 3498 | QString textCapcalera; |
| 3499 | textCapcalera.append(tr("Jocs personalitzats")+" ("+ |
| 3500 | QString("%1").arg( |
| 3501 | arbreModalitatsJocPersonalitzatsTreeWidget->topLevelItemCount())+")"); |
| 3502 | itemCapcalera->setText(0,textCapcalera); |
| 3503 | arbreModalitatsJocPersonalitzatsTreeWidget->setHeaderItem(itemCapcalera); |
| 3504 | |
| 3505 | //Ara ho afegim a l'arxiu de dades |
| 3506 | solitariPersonalitzat_desaJocArxiu(item->text(1),dadesJocList, |
| 3507 | item->text(4)); |
| 3508 | return nouCodiSolitari; |
| 3509 | } |
| 3510 | |
| 3511 | /* Afegeix les dades del joc personalitzat a l'arxiu |
| 3512 | * de dades /home/Solitari/game-per.dat |
| 3513 | */ |
| 3514 | void frmPrincipal::solitariPersonalitzat_desaJocArxiu(QString codi, |
| 3515 | QStringList dadesFitxes, QString codiNom){ |
| 3516 | comprovaDirectoriHome(); |
| 3517 | QString nomArxiu=QDir::homePath (); |
| 3518 | nomArxiu.append (QDir().separator()); |
| 3519 | nomArxiu.append (qApp->applicationName()); |
| 3520 | nomArxiu.append (QDir().separator()); |
| 3521 | nomArxiu.append ("game-per.dat"); |
| 3522 | QFile arxiu(nomArxiu); |
| 3523 | if (arxiu.open(QIODevice::Append)){ |
| 3524 | QTextStream entrada(&arxiu); |
| 3525 | entrada<<("######\n") ; |
| 3526 | entrada<<(codi+"\n") ; |
| 3527 | entrada<<(dadesFitxes.value(0)+"\n") ; |
| 3528 | entrada<<(dadesFitxes.value(1)+"\n") ; |
| 3529 | entrada<<(codiNom+"\n") ; |
| 3530 | } |
| 3531 | arxiu.close(); |
| 3532 | } |
| 3533 | |
| 3534 | /* Renomena l'arxiu amb la solució del solitari |
| 3535 | * personalitzat nou |
| 3536 | */ |
| 3537 | void frmPrincipal::solitariPersonalitzat_renomenaArxiuSolucio(QString nouCodi){ |
| 3538 | return; |
| 3539 | QString nomArxiu=nomArxiuJoc(2); |
| 3540 | QString nomArxiuModificat=nomArxiuJoc(2); |
| 3541 | nomArxiuModificat.replace("_"+taulerJoc->modalitatJocActual(),"_"+nouCodi); |
| 3542 | QFile::copy(nomArxiu,nomArxiuModificat); |
| 3543 | } |
| 3544 | |
| 3545 | |
| 3546 | /* Llegeix i carrega les dades dels jocs personalitzats |
| 3547 | * de l'arxiu /home/Solitari/games-per.dat a la llista |
| 3548 | * dadesArxiuData |
| 3549 | */ |
| 3550 | bool frmPrincipal::llegeixArxiuDataPersonalitzats(){ |
| 3551 | bool resultat=false; |
| 3552 | comprovaDirectoriHome(); |
| 3553 | QString arxiuData=QDir::homePath (); |
| 3554 | arxiuData.append (QDir().separator()); |
| 3555 | arxiuData.append (qApp->applicationName()); |
| 3556 | arxiuData.append (QDir().separator()); |
| 3557 | arxiuData.append ("game-per.dat"); |
| 3558 | QFile arxiu(arxiuData); |
| 3559 | if(arxiu.exists()){ |
| 3560 | if (arxiu.open(QIODevice::ReadOnly | QIODevice::Text)){ |
| 3561 | QTextStream entrada(&arxiu); |
| 3562 | QString linia0 = entrada.readLine(); |
| 3563 | dadesArxiuData.clear(); |
| 3564 | while (!linia0.isNull()) { |
| 3565 | if ( ! (linia0.mid(0,1)=="#") ){ |
| 3566 | dadesArxiuData.append(linia0); //tipus de joc |
| 3567 | for(int dades=0 ; dades<numeroLiniesDadesJoc-1;++dades){ |
| 3568 | dadesArxiuData.append(entrada.readLine()); |
| 3569 | } |
| 3570 | } |
| 3571 | linia0 = entrada.readLine(); |
| 3572 | } //final del while de la lectura de l'arxiu |
| 3573 | resultat=true; |
| 3574 | } |
| 3575 | }//final if exists |
| 3576 | return resultat; |
| 3577 | } |
| 3578 | |
| 3579 | /* Gestiona la selecció dels jocs |
| 3580 | * personalitzats |
| 3581 | */ |
| 3582 | void frmPrincipal::seleccioModalitatJocPersonalitzat(){ |
| 3583 | statusBar()->clearMessage(); |
| 3584 | /*Necessari per controlar les solucions distintes*/ |
| 3585 | retrocedeixMoviment=0; |
| 3586 | /*Això per preveure que es canvii dels jocs del programa |
| 3587 | *als jocs personalitzats sense haver eliminat |
| 3588 | *els arxius del joc personalitzat |
| 3589 | */ |
| 3590 | if( (tipusJocActual==0) && (noHiHaSolucionsArbreSolucions()) ){ |
| 3591 | solitariPersonalitzat_eliminaArxiuSolucio(); |
| 3592 | } |
| 3593 | // if (!arbreModalitatsJocTreeWidget->selectedItems().isEmpty()){ |
| 3594 | if (arbreModalitatsJocPersonalitzatsTreeWidget->selectedItems().count()==1){ |
| 3595 | QTreeWidgetItem *item; |
| 3596 | item=arbreModalitatsJocPersonalitzatsTreeWidget->selectedItems().first(); |
| 3597 | //No s'ha clicat el nus arrel |
| 3598 | if (item->childCount()==0){ |
| 3599 | movimentsUndoStack->clear(); |
| 3600 | iniciSolucioAction->setEnabled(movimentsUndoStack->canUndo()); |
| 3601 | //Reinciam el número d'intents de trobar |
| 3602 | //la solució |
| 3603 | intentsSolucio=0; |
| 3604 | jocResolt=0; |
| 3605 | //es tracta d'un joc personalitzat/modificat |
| 3606 | tipusJocActual=1; |
| 3607 | taulerJoc->joc_CarregaJoc(item->text(1),item->text(2),item->text(3)); |
| 3608 | taulerJoc->setCodiNomJocActual(item->text(4)); |
| 3609 | taulerJoc->setSolitariModificat(false); |
| 3610 | taulerJoc->setSolitariPersonalitzat(false); |
| 3611 | setArbreJocsActual(1); |
| 3612 | //30/12/12 Nova funció hihaRecord() |
| 3613 | QStringList tipusJoc = item->text(1).split(" "); |
| 3614 | QString record=hihaRecordJoc(tipusJoc.value(0)); |
| 3615 | if ( record != "0") { |
| 3616 | statusBar()->showMessage( |
| 3617 | QString(tr("Joc carregat. El vostre record actual és: %1")).arg(record)); |
| 3618 | } |
| 3619 | //06/02/13 nou prod. |
| 3620 | actualitzaConfiguracionsInicials(); |
| 3621 | //06/02/13 Innecessari! |
| 3622 | //comprovaArxiuSolucions(); |
| 3623 | veureSolucionsSlot(); |
| 3624 | } |
| 3625 | } |
| 3626 | } |
| 3627 | |
| 3628 | |
| 3629 | /*Carrega les dades dels solitaris personalitzats |
| 3630 | */ |
| 3631 | void frmPrincipal::carregaArbreModalitatsJocPersonalitzats(){ |
| 3632 | |
| 3633 | //Si no hi ha arxiu, no cal fer res! |
| 3634 | if ( !llegeixArxiuDataPersonalitzats()){ |
| 3635 | QTreeWidgetItem *item=new QTreeWidgetItem(); |
| 3636 | item->setText(0,tr("Cap joc personalitzat")); |
| 3637 | arbreModalitatsJocPersonalitzatsTreeWidget->setHeaderItem(item); |
| 3638 | return;} |
| 3639 | if (dadesArxiuData.size()>0){ |
| 3640 | QApplication::setOverrideCursor(Qt::WaitCursor); |
| 3641 | //netejam |
| 3642 | arbreModalitatsJocPersonalitzatsTreeWidget->clear(); |
| 3643 | arbreModalitatsJocPersonalitzatsTreeWidget->setColumnCount(numeroLiniesDadesJoc+1); |
| 3644 | arbreModalitatsJocPersonalitzatsTreeWidget->setColumnHidden(1,true); |
| 3645 | arbreModalitatsJocPersonalitzatsTreeWidget->setColumnHidden(2,true); |
| 3646 | arbreModalitatsJocPersonalitzatsTreeWidget->setColumnHidden(3,true); |
| 3647 | arbreModalitatsJocPersonalitzatsTreeWidget->setColumnHidden(4,true); |
| 3648 | |
| 3649 | //posam la capçalera de l'arbre |
| 3650 | QTreeWidgetItem *item=new QTreeWidgetItem(); |
| 3651 | item->setText(0,tr("Jocs personalitzats")); |
| 3652 | arbreModalitatsJocPersonalitzatsTreeWidget->setHeaderItem(item); |
| 3653 | |
| 3654 | QList<QTreeWidgetItem *> itemsArbre; |
| 3655 | for(int llista=0 ; llista<dadesArxiuData.size()/(numeroLiniesDadesJoc);++llista){ |
| 3656 | QTreeWidgetItem *item=new QTreeWidgetItem(); |
| 3657 | /*QStringList nomJocOrig=(tr(nomModalitatsJoc[ |
| 3658 | dadesArxiuData.value( |
| 3659 | llista*numeroLiniesDadesJoc+3).toInt()])).split(" - ");*/ |
| 3660 | //QString nomJoc=nomJocOrig.value(0); |
| 3661 | QString nomJoc=nomDelJoc(dadesArxiuData.value( |
| 3662 | llista*numeroLiniesDadesJoc+3),false); |
| 3663 | //Afegim el codi del joc |
| 3664 | QStringList codi=dadesArxiuData.value(llista*(numeroLiniesDadesJoc)).split(" "); |
| 3665 | |
| 3666 | nomJoc=nomJoc+ |
| 3667 | afageixTipusMovimentNomJoc(dadesArxiuData.value(llista*(numeroLiniesDadesJoc))) |
| 3668 | +" "+codi.value(0); |
| 3669 | //Comprovam si és una modalitat amb final marcat |
| 3670 | //per afegir un * al nom |
| 3671 | //12/01/13 Nova funció |
| 3672 | //if( (dadesArxiuData.value(llista*(numeroLiniesDadesJoc-1)+2).contains("11")) |
| 3673 | // ||(dadesArxiuData.value(llista*(numeroLiniesDadesJoc-1)+2).contains("10")) ){ |
| 3674 | if(esSolitariAmbFinalMarcat( |
| 3675 | dadesArxiuData.value(llista*(numeroLiniesDadesJoc)+2))) { |
| 3676 | nomJoc=nomJoc+" *" ;} |
| 3677 | item->setText(0,nomJoc); |
| 3678 | item->setToolTip(0,item->text(0)); |
| 3679 | //linea 0: codi joc, tipus moviment |
| 3680 | item->setText(1,dadesArxiuData.value(llista*(numeroLiniesDadesJoc))); |
| 3681 | //linea 1: files i columnes |
| 3682 | item->setText(2,dadesArxiuData.value(llista*(numeroLiniesDadesJoc)+1)); |
| 3683 | //linea 2: estat de les fitxes |
| 3684 | item->setText(3,dadesArxiuData.value(llista*(numeroLiniesDadesJoc)+2)); |
| 3685 | //linea 3: codi del nom del joc |
| 3686 | item->setText(4,dadesArxiuData.value(llista*(numeroLiniesDadesJoc)+3)); |
| 3687 | //posam l'icone OK si hi ha un rècord |
| 3688 | item->setIcon(0,QIcon(posaIconeOK(codi.value(0)))); |
| 3689 | itemsArbre.append(item); |
| 3690 | } |
| 3691 | arbreModalitatsJocPersonalitzatsTreeWidget->insertTopLevelItems(0,itemsArbre); |
| 3692 | arbreModalitatsJocPersonalitzatsTreeWidget->expandAll(); |
| 3693 | arbreModalitatsJocPersonalitzatsTreeWidget->sortItems(0,Qt::AscendingOrder); |
| 3694 | //Afegim el nombre de jocs de l'arbre al ròtul |
| 3695 | item->setText(0,tr("Jocs personalitzats")+" ("+QString::number( |
| 3696 | arbreModalitatsJocPersonalitzatsTreeWidget->topLevelItemCount()) +")"); |
| 3697 | } |
| 3698 | QApplication::setOverrideCursor(Qt::ArrowCursor); |
| 3699 | } |
| 3700 | |
| 3701 | |
| 3702 | /* Elimina l'arxiu de la solució del solitari personalitzat |
| 3703 | * actual |
| 3704 | */ |
| 3705 | void frmPrincipal::solitariPersonalitzat_eliminaArxiuSolucio(){ |
| 3706 | return; |
| 3707 | if(arbreModalitatsJocTreeWidget->selectedItems().count()>0){ |
| 3708 | if( (solitariPersonalitzat_esPersonalitzat( |
| 3709 | arbreModalitatsJocTreeWidget->selectedItems().first()->text(1))) |
| 3710 | || (taulerJoc->solitariPersonalitzat()) ){ |
| 3711 | comprovaDirectoriHome(); |
| 3712 | QString nomArxiu=nomArxiuJoc(2); |
| 3713 | /*Això és necessari per evitar eliminar arxius d'altres |
| 3714 | jocs que tenguin solucions noves*/ |
| 3715 | if(solitariPersonalitzat_esPersonalitzat(nomArxiu) ){ |
| 3716 | QFile arxiu(nomArxiu); |
| 3717 | if (arxiu.exists()){ |
| 3718 | arxiu.remove(); |
| 3719 | qApp->processEvents(); |
| 3720 | nomArxiu=nomArxiuJoc(1); |
| 3721 | QFile arxiu1(nomArxiu); |
| 3722 | arxiu1.remove(); |
| 3723 | qApp->processEvents(); |
| 3724 | } |
| 3725 | } |
| 3726 | }//if arbre-text |
| 3727 | }//if arbre-count |
| 3728 | } |
| 3729 | |
| 3730 | /* Retorna el nou codi del solitari personalitzat |
| 3731 | */ |
| 3732 | QString frmPrincipal::solitariPersonalitzat_nouCodiJoc(bool nou){ |
| 3733 | QSettings codiJocPersonalitzat; |
| 3734 | int codi=codiJocPersonalitzat.value( QString("General/codiJocPer"),10000).toInt(); |
| 3735 | codi++; |
| 3736 | if(nou){ |
| 3737 | QSettings().setValue("General/codiJocPer",QString("%1").arg(codi));} |
| 3738 | return QString("%1").arg(codi); |
| 3739 | } |
| 3740 | |
| 3741 | /* Determina si el solitari actual és o no |
| 3742 | * personalitzat |
| 3743 | */ |
| 3744 | bool frmPrincipal::solitariPersonalitzat_esPersonalitzat(QString joc){ |
| 3745 | return (joc.contains("1001")) |
| 3746 | || (joc.contains("1002")) |
| 3747 | || (joc.contains("1003")); |
| 3748 | } |
| 3749 | |
| 3750 | |
| 3751 | /* Gestiona el canvi de selecció |
| 3752 | * de la fulla del tab amb els arbres de jocs |
| 3753 | * i solucions |
| 3754 | */ |
| 3755 | void frmPrincipal::canviTabSeleccionat( int tabSeleccionat){ |
| 3756 | if(tabSeleccionat==0) { |
| 3757 | //tab dels jocs del programa |
| 3758 | seleccioModalitatJoc();} |
| 3759 | else if (tabSeleccionat==2) { |
| 3760 | //Forçam que hi hagi un ítem seleccionat |
| 3761 | if(arbreModalitatsJocPersonalitzatsTreeWidget->children().count()>0){ |
| 3762 | if(arbreModalitatsJocPersonalitzatsTreeWidget->selectedItems().empty()){ |
| 3763 | arbreModalitatsJocPersonalitzatsTreeWidget->setCurrentItem( |
| 3764 | arbreModalitatsJocPersonalitzatsTreeWidget->topLevelItem(0));} |
| 3765 | //tab dels jocs personalitzats |
| 3766 | seleccioModalitatJocPersonalitzat();}} |
| 3767 | } |
| 3768 | |
| 3769 | /* Retorna el tipus de moviment en text |
| 3770 | * (invers/diagonal) |
| 3771 | */ |
| 3772 | QString frmPrincipal::afageixTipusMovimentNomJoc(QString tipus){ |
| 3773 | if(tipus.contains(" 2 ")){ |
| 3774 | return tr(" - invers"); |
| 3775 | } |
| 3776 | else if (tipus.contains(" 3 ")){ |
| 3777 | return tr(" - diagonal"); |
| 3778 | } |
| 3779 | else return ""; |
| 3780 | } |
| 3781 | |
| 3782 | /* Retorna el nom del joc |
| 3783 | * (sense afegitons segons el paràmetre) |
| 3784 | */ |
| 3785 | QString frmPrincipal::nomDelJoc(QString codi, bool complet){ |
| 3786 | //Cadenes amb els noms de les modalitats de joc per a la traducció |
| 3787 | //El codi de joc de data.sol cal que coincideixi amb l'index a l'array |
| 3788 | //El primer és el ròtul de l'arbre amb les modalitats del joc |
| 3789 | /* 17/06/12 v. 1.3 |
| 3790 | * S'ha modificat tot el sistema de traducció per evitar haver de posar |
| 3791 | * totes les cadenes que només es diferencien en el número d'ordre |
| 3792 | * Ara, cada cadena única està a la matriu següent, i desprès |
| 3793 | * s'assigna un numero d'ordre segons les repeticions |
| 3794 | * (amb un arxiu ini) |
| 3795 | */ |
| 3796 | static const char *const nomModalitatsJoc[] = { |
| 3797 | QT_TR_NOOP("Modalitats del joc"), |
| 3798 | QT_TR_NOOP("Clàssic"), // 1 |
| 3799 | QT_TR_NOOP("Clàssic - simetria"), // 2 |
| 3800 | QT_TR_NOOP("Clàssic - pentàgon"), //3 |
| 3801 | QT_TR_NOOP("Clàssic - creu petita"), //4 |
| 3802 | QT_TR_NOOP("Clàssic - creu gran"), //5 |
| 3803 | // QT_TR_NOOP("Clàssic - invers"), // 6->1 |
| 3804 | QT_TR_NOOP("Solitari estrella 7x7"), //6 |
| 3805 | QT_TR_NOOP("Clàssic - superior"), // 7 |
| 3806 | QT_TR_NOOP("Clàssic - inferior"), //8 |
| 3807 | QT_TR_NOOP("Clàssic - fletxa"), //9 |
| 3808 | QT_TR_NOOP("Clàssic - piràmide"), //10 |
| 3809 | QT_TR_NOOP("Clàssic - diamant"), //11 |
| 3810 | QT_TR_NOOP("Clàssic - rombe"), //12 |
| 3811 | QT_TR_NOOP("Solitari 3x5"), //13 |
| 3812 | QT_TR_NOOP("Triangular 4x7"), //14 |
| 3813 | QT_TR_NOOP("Europeu"), //15 |
| 3814 | QT_TR_NOOP("Asimètric 8x8"), //16 |
| 3815 | // QT_TR_NOOP("Clàssic - diagonal"), //17->1 |
| 3816 | QT_TR_NOOP("Solitari 6x7"), //107->17 |
| 3817 | QT_TR_NOOP("Asimètric - superior"), //18 |
| 3818 | QT_TR_NOOP("Asimètric 8x8"), //19 |
| 3819 | QT_TR_NOOP("Clàssic - central"), //20 |
| 3820 | // QT_TR_NOOP("Europeu - diagonal"), //21->15 |
| 3821 | QT_TR_NOOP("Solitari OK"), //106->21 |
| 3822 | QT_TR_NOOP("Quadrat 5x5"), //22 |
| 3823 | QT_TR_NOOP("Clàssic - quadrat central"), //23 |
| 3824 | QT_TR_NOOP("Clàssic - rectangle central"), //24 |
| 3825 | QT_TR_NOOP("Clàssic - arbre"), //25 |
| 3826 | QT_TR_NOOP("Quadrat 5x5 - central"), //26 |
| 3827 | QT_TR_NOOP("Quadrat 5x5 - H"), //27 |
| 3828 | QT_TR_NOOP("Wiegleb"), //28 |
| 3829 | QT_TR_NOOP("Diamant 9x9"), //29 |
| 3830 | QT_TR_NOOP("Europeu - creu"), //30 |
| 3831 | QT_TR_NOOP("Wiegleb - clàssic"), //31 |
| 3832 | // QT_TR_NOOP("Europeu diagonal"), //32->15 |
| 3833 | QT_TR_NOOP("Solitari 6x6"), //104->32 |
| 3834 | QT_TR_NOOP("Quadrat 6x6"), //33 |
| 3835 | QT_TR_NOOP("Diamant 5x5"), //34 |
| 3836 | QT_TR_NOOP("Diamant 7x7"), //35 |
| 3837 | QT_TR_NOOP("Anglès antic"), //36 |
| 3838 | QT_TR_NOOP("Incomplet 6x6"), //37 |
| 3839 | QT_TR_NOOP("Incomplet 7x7"), //38 |
| 3840 | QT_TR_NOOP("Wiegleb reduit"), //39 |
| 3841 | QT_TR_NOOP("Solitari 8x9"), //40 |
| 3842 | QT_TR_NOOP("Solitari 5x6"), //41 |
| 3843 | QT_TR_NOOP("Wiegleb - fletxa"), //42 |
| 3844 | QT_TR_NOOP("Clàssic - E"), //43 |
| 3845 | QT_TR_NOOP("Clàssic - R"), //44 |
| 3846 | QT_TR_NOOP("Clàssic - T"), //45 |
| 3847 | QT_TR_NOOP("Solitari 5x6"), //46 |
| 3848 | QT_TR_NOOP("Quadrat 6x6"), //47 |
| 3849 | QT_TR_NOOP("Quadrat 5x5 - quadrats"), //48 |
| 3850 | QT_TR_NOOP("Triangular 4x7"), //49 |
| 3851 | QT_TR_NOOP("Triangular 4x7 - quadrat"), // 50 |
| 3852 | QT_TR_NOOP("Triangular 4x7 - piràmide"), //51 |
| 3853 | QT_TR_NOOP("Quadrat 5x5 - piràmide"), //52 |
| 3854 | QT_TR_NOOP("Solitari 7x5"), //53 |
| 3855 | QT_TR_NOOP("Asimètric 6x6"), //54 |
| 3856 | QT_TR_NOOP("Quadrat 9x9"), //55 |
| 3857 | QT_TR_NOOP("Anglès antic - diamant"), //56 |
| 3858 | QT_TR_NOOP("Triangular 5"), // 57 |
| 3859 | QT_TR_NOOP("Triangular 4"), //58 |
| 3860 | QT_TR_NOOP("Triangular 6"), //59 |
| 3861 | QT_TR_NOOP("Wiegleb - creu petita"), //60 |
| 3862 | QT_TR_NOOP("Wiegleb - simetria"), //61 |
| 3863 | // QT_TR_NOOP("Wiegleb diagonal"), //62->28 |
| 3864 | QT_TR_NOOP("Clàssic - quadrat"), //102->62 |
| 3865 | QT_TR_NOOP("Asimètric 6x6"), //63 |
| 3866 | QT_TR_NOOP("Asimètric 8x8"), //64 |
| 3867 | // QT_TR_NOOP("Europeu invers"), //65->15 |
| 3868 | QT_TR_NOOP("Clàssic - cúpula"), //101->65 |
| 3869 | // QT_TR_NOOP("Wiegleb invers"), //66->28 |
| 3870 | QT_TR_NOOP("Clàssic - Cabana"), //100->66 |
| 3871 | QT_TR_NOOP("Wiegleb reduit"), // 67 |
| 3872 | QT_TR_NOOP("Solitari 3x5 bis"), //68 |
| 3873 | QT_TR_NOOP("Solitari 4x4"), //69 |
| 3874 | QT_TR_NOOP("Solitari 6x5"),//70 |
| 3875 | QT_TR_NOOP("Solitari 4x5"),//71 |
| 3876 | QT_TR_NOOP("Triangular 7"), //72 |
| 3877 | QT_TR_NOOP("Triangular 8"), //73 |
| 3878 | QT_TR_NOOP("Triangular 9"), //74 |
| 3879 | QT_TR_NOOP("Europeu - quadrat"), //75 |
| 3880 | QT_TR_NOOP("Clàssic - molinet"), //76 |
| 3881 | QT_TR_NOOP("Triangular 10"), //77 |
| 3882 | QT_TR_NOOP("Quadrat 8x8"), //78 |
| 3883 | QT_TR_NOOP("Solitari 7x5"), //79 |
| 3884 | QT_TR_NOOP("Clàssic - quadrat central"), //80 |
| 3885 | QT_TR_NOOP("Clàssic - O"), //81 |
| 3886 | //nous versió 1.2 |
| 3887 | QT_TR_NOOP("Dos quadrats 10x10"), //82 |
| 3888 | QT_TR_NOOP("Dos quadrats 11x11"), //83 |
| 3889 | QT_TR_NOOP("Tres quadrats 16x16"), //84 |
| 3890 | QT_TR_NOOP("Dos quadrats 9x9"), //85 |
| 3891 | QT_TR_NOOP("Tres quadrats 13x13"), //86 |
| 3892 | QT_TR_NOOP("Quatre quadrats 13x13"), //87 |
| 3893 | QT_TR_NOOP("Clàssic ampliat"), //88 |
| 3894 | QT_TR_NOOP("Diamant 9x9"), //89 |
| 3895 | QT_TR_NOOP("Rombe 36"), //90 |
| 3896 | // Nous versió 2.0 |
| 3897 | QT_TR_NOOP("Hexagonal inclinat"), //91 |
| 3898 | QT_TR_NOOP("Clàssic - 4 forquilles"), //92 |
| 3899 | QT_TR_NOOP("Pentagonal"), //93 |
| 3900 | QT_TR_NOOP("Hexagonal 7x11"), //94 |
| 3901 | QT_TR_NOOP("Clàssic - Dos quadrats"), //95 |
| 3902 | QT_TR_NOOP("Clàssic - Banyes"), //96 |
| 3903 | QT_TR_NOOP("Clàssic - X"), //97 |
| 3904 | QT_TR_NOOP("Clàssic - Torxa"), //98 |
| 3905 | QT_TR_NOOP("Clàssic - Palau"), //99 |
| 3906 | // QT_TR_NOOP("Clàssic - quadrat"), //102->28 |
| 3907 | QT_TR_NOOP("Personalitzat"), //105->100 |
| 3908 | QT_TR_NOOP("Solitari a l'atzar"), //103->101 |
| 3909 | // QT_TR_NOOP("Personalitzat - diagonal"), //109->105 |
| 3910 | // QT_TR_NOOP("Personalitzat - invers"), //110->105 |
| 3911 | QT_TR_NOOP("Solo"), //102 |
| 3912 | QT_TR_NOOP("Solitari 8x3"), //103 |
| 3913 | QT_TR_NOOP("Solitari 8x6"), //104 |
| 3914 | 0 |
| 3915 | }; |
| 3916 | |
| 3917 | QString nom=tr(nomModalitatsJoc[codi.toInt()]); |
| 3918 | if (!complet){ |
| 3919 | QStringList nomList=nom.split(" - "); |
| 3920 | nom=nomList.value(0); |
| 3921 | } |
| 3922 | return nom; |
| 3923 | } |
| 3924 | |
| 3925 | /* Arbre del joc actual. |
| 3926 | * Es fa servir per saber quin tipus de joc |
| 3927 | * està actiu |
| 3928 | * 0: arbre dels jocs del programa |
| 3929 | * 1: arbre dels jocs personalitzats |
| 3930 | */ |
| 3931 | void frmPrincipal::setArbreJocsActual(int valor){ |
| 3932 | p_arbreJocsActual=valor; |
| 3933 | } |
| 3934 | |
| 3935 | /* Actualitza les cadenes que conservan la configuració |
| 3936 | * de les fitxes a l'inici del joc |
| 3937 | */ |
| 3938 | void frmPrincipal::actualitzaConfiguracionsInicials(){ |
| 3939 | //qCritical("solucioJocActual_configuracioInicial %s",qPrintable(solucioJocActual_configuracioInicial)); |
| 3940 | solucioJocActual_configuracioInicial.clear(); |
| 3941 | solucioJocActual_configuracioInicial.append(taulerJoc->configuracioActual(true)); |
| 3942 | //jocActual_configuracioInicialFitxesMarcades.clear(); |
| 3943 | //jocActual_configuracioInicialFitxesMarcades.append( |
| 3944 | // taulerJoc->configuracioInicialAmbFitxesMarcades()); |
| 3945 | //qCritical("jocActual_configuracioInicialFitxesMarcades %s",qPrintable(jocActual_configuracioInicialFitxesMarcades)); |
| 3946 | } |
| 3947 | |
| 3948 | |
| 3949 | |
| 3950 | /* Versió 2.1 |
| 3951 | * Degut als canvis de QHash a QMap a la migració a Qt5, |
| 3952 | * cal canviar els noms dels arxius de solucions anteriors |
| 3953 | * a aquesta versió. No és possible fer el canvi dels arxius |
| 3954 | * de solitaris personalitzats |
| 3955 | */ |
| 3956 | void frmPrincipal::actualitzaCodisArxiusDeSolucio(){ |
| 3957 | //Si no existeix el directori $home/Solitari |
| 3958 | // o ja s'ha fet la migració, no feim res. |
| 3959 | QDir dirArxiu(QDir::homePath ()); |
| 3960 | if ((dirArxiu.exists(qApp->applicationName())) && (QSettings().value("General/migracio")<"2.1") ){ |
| 3961 | bool migracio=false; |
| 3962 | //Camviam el nom del directori Solitari a Solitari_seg |
| 3963 | QApplication::setOverrideCursor(Qt::WaitCursor); |
| 3964 | QDir dirSolitari(QDir::homePath ()+QDir().separator()+qApp->applicationName()); |
| 3965 | dirSolitari.rename(QDir::homePath ()+QDir().separator()+qApp->applicationName(), |
| 3966 | QDir::homePath ()+QDir().separator()+qApp->applicationName()+"_seg"); |
| 3967 | //tornam a generar el direcotri Solitari |
| 3968 | comprovaDirectoriHome(); |
| 3969 | //Primer carregam els noms dels arxius antics i nous de l'arxiu codis.txt |
| 3970 | QStringList nomsArxius; |
| 3971 | QString nomArxiu=directoriLinux()+QDir().separator()+"games/codis.txt"; |
| 3972 | QFile arxiuData(nomArxiu); |
| 3973 | if (!arxiuData.open(QIODevice::ReadOnly | QIODevice::Text)){ |
| 3974 | QMessageBox::critical(this, tr("Solitari"), |
| 3975 | QString(tr("No s'ha trobat l'arxiu %1")).arg(nomArxiu) ); |
| 3976 | return ; |
| 3977 | } |
| 3978 | QTextStream entrada(&arxiuData); |
| 3979 | QString linia0 = entrada.readLine(); |
| 3980 | nomsArxius.clear(); |
| 3981 | while (!linia0.isNull()) { |
| 3982 | nomsArxius.append(linia0); |
| 3983 | linia0 = entrada.readLine(); |
| 3984 | }//final del while de la lectura de l'arxiu |
| 3985 | // qDebug("noms arxius %d",nomsArxius.count()); |
| 3986 | /* Per cada nom a un lloc senar de la llista, cal comprovar |
| 3987 | * si existeix l'arxiu en el directori /Solitari |
| 3988 | * i, en cas positiu, canviar el nom de l'arxiu pel nom nou i |
| 3989 | * eliminar l'arxiu de posicions eliminades (amb el mateix nom |
| 3990 | * però extensió .txt |
| 3991 | */ |
| 3992 | for(int i=0 ; i<nomsArxius.count()/2;++i){ |
| 3993 | //Els arxius de solucions originals estan en el directori Solitari_seg |
| 3994 | QString nomArxiuSolucionsAntic=QDir::homePath ()+QDir().separator()+ |
| 3995 | qApp->applicationName()+"_seg"+QDir().separator()+nomsArxius.value(i*2)+".sol"; |
| 3996 | QString nomArxiuSolucionsNou=QDir::homePath ()+QDir().separator()+ |
| 3997 | qApp->applicationName()+QDir().separator()+nomsArxius.value(i*2+1)+".sol"; |
| 3998 | QFile arxiuSolucions(nomArxiuSolucionsAntic); |
| 3999 | //Renomenam l'arxiu de solucions |
| 4000 | if (arxiuSolucions.exists()){ |
| 4001 | // qCritical("Existeix l'arxiu %s", qPrintable(nomArxiuSolucionsAntic)); |
| 4002 | (arxiuSolucions.copy(nomArxiuSolucionsNou)); |
| 4003 | migracio=true; |
| 4004 | } |
| 4005 | |
| 4006 | //Copiam l'arxiu game-per.data (si existeix) |
| 4007 | QString nomarxiuSolitarisPersonalitzats=QDir::homePath ()+QDir().separator()+ |
| 4008 | qApp->applicationName()+"_seg"+QDir().separator()+"game-per.dat"; |
| 4009 | QFile arxiuSolitarisPersonalitzats(nomarxiuSolitarisPersonalitzats); |
| 4010 | if (arxiuSolitarisPersonalitzats.exists()){ |
| 4011 | arxiuSolitarisPersonalitzats.copy(QDir::homePath ()+QDir().separator()+ |
| 4012 | qApp->applicationName()+QDir().separator()+"game-per.dat"); |
| 4013 | migracio=true; |
| 4014 | } |
| 4015 | } |
| 4016 | if (migracio){ |
| 4017 | QDesktopServices::openUrl(QUrl("file:///"+directoriLinux()+ |
| 4018 | QDir().separator()+ |
| 4019 | DIR_HELP+ |
| 4020 | QDir().separator()+ |
| 4021 | "migracio.html", QUrl::TolerantMode)); |
| 4022 | //Desam a la configuració que s'ha fet la migració |
| 4023 | QSettings().setValue(QString("General/migracio"),"2.1"); |
| 4024 | } |
| 4025 | QApplication::setOverrideCursor(Qt::ArrowCursor); |
| 4026 | } |
| 4027 | } |