Contenuto cancellato Contenuto aggiunto
asd
asdasd
Riga 3:
<nowiki>#</nowiki>include <iostream>
 
// #include <string>  // es: string blabla; cin >> blabla;
 
<nowiki>#</nowiki>include "sudoku2lib.h"
Riga 9:
using namespace std;
 
int TestID = 1;
type_tavola tab;
 
int livelloAnnidamento = 1; // spostare quanto più possibile nel main
int livello_annidamento = 0;
 
type_esitoTest esito[TESTS_TO_RUN] /* = {UNKNOWN} */;
 
int main()
Riga 17 ⟶ 19:
{
 
  int ReturnValue = UNKNOWN;
  char orai[5] = {'?', '?', '?', '?', '?'};
 
  type_tavola tab;
 
  type_tavola tabSol;
 
  #if (!DEBUGGING)
  char oraf[5] = {'?', '?', '?', '?', '?'};
 
  int i = 1;
Riga 25 ⟶ 31:
  int j = 1;
 
  #endif
  int spia = 0;
 
  cout << "    Algoritmo di risoluzione del SUDOKU        \n" << endl;
  int tent = 0;
 
  cout << "Ingegneria fisica - Politecnico di Milano      " << endl;
  int tentmille = 0;
 
  cout << "     Informatica A - Prof. Sam Guinea\n        " << endl;
  int tentmigli = 0;
 
  cout << "      (2) Dott. Mag. Ing. Antonio Indirli      " << endl;
  int tentmiliar = 0;
 
  cout << "               Embedded SW Dev.                " << endl;
  // int tentativicella = 0;
 
  cout << "     Algoritmo  di  risoluzione  del  SUDOKU    Alten ITALIA                   \n\n\n" << endl;
 
  for (TestID = 1; TestID <= TESTS_TO_RUN; TestID++)
  cout << "Ingegneria fisica - Politecnico di Milano  " << endl;
 
  {
  cout << "     Informatica A - Prof. Sam Guinea      " << endl << endl << endl << endl;
 
   #if (DEBUGGING)
  cout << "Inserire valori noti (0 se non si conosce)." << endl << endl;
 
   InitTest(&tab[0][0], SVUOTA_SI, TestID);
  // string bla;
 
   #else // No Debugging
  // cout << "Debug: inserire una stringa:" << endl;
 
   /**********************************************/
  // cin >> bla;
 
   //* cout  <<  "la  stringaInserimento inseritadei è:valori "- <<BEGIN bla  <<  "!!!!!!"<<  endl;*/
 
   /**********************************************/
 
   cout << "Inserire valori noti (0 se non si conosce).\n\n" << endl;
  /*       Inserimento dei valori - BEGIN       */
 
   for (i = 1; i <= 9; i++) {
  /**********************************************/ /*
 
  for   (icout =<< 1;" iRIGA " <<= 9; i++) {<< endl;
 
     coutfor <<(j "= RIGA1; "j <<= i9; <<j++) endl;{
 
    for (j = 1; j <= 9;   j++)do {
 
         cout << "(" << i << ":" << j << ")= ";
     do {
 
         cin >> tab[i][j].num;                               // Non sono sicuro se serve passargli l'indirizzo, credo di sì in realtà!!
       cout << "(" << i << ":" << j << ")= " endl;
 
         cinif ((tab[i][j].num >>= 1) && (tab[i][j].num; //<= non9)) sono  sicuro// seDa serve1 passarglia l'indirizzo9, credo diil valore inè realtà!!certo
 
        if   ((tab[i][j].numstatus >= 1) && (tab[i][j].num <= 9)) // Da 1 a 9, il valore è certoFOUND;
 
         tab[i][j].status=FOUND;else
 
        else   tab[i][j].status = EMPTY;
 
         } while ((tab[i][j].status=EMPTYnum < 0) || (tab[i][j].num > 9)); // Sotto 0 e sopra 9, ciclo da rifare
 
       if ((j % 3) == 0)
     } while (tab[i][j].num<0 || tab[i][j].num>9); // sotto 0 e sopra 9, ciclo da rifare
 
      if ((j %   3)cout ==<< 0)endl;
 
     }

     cout << endl;
 
   }
 
   /********************************************/
   cout << endl;
 
   /*       Inserimento dei valori - END       */
  } */
 
   /********************************************/
 
   #endif
  /*       Inserimento dei valori - END       */
 
   #if (DEBUGGING)
  /********************************************/
 
   cout << "Test numero "<< TestID << ". ";
  /***********************************************************/
 
   #endif
  /*        PARTE TEMPORANEA: VALORI VALIDI ASSEGNATI        */
 
   cout << "I valori inseriti sono:\n" << endl;
  /*       PER BYPASSARE L'INSERIMENTO MANUALE - BEGIN       */
 
   mostra_numeri_status(tab);
  /***********************************************************/
 
   #if (!DEBUGGING)
  tab[1][1].num = 0; tab[1][2].num = 4; tab[1][3].num = 5;
 
   cout << "\nPremi un tasto per continuare.\n" << endl;
  tab[1][4].num = 3; tab[1][5].num = 2; tab[1][6].num = 7;
 
   fflush(stdin);
  tab[1][7].num = 6; tab[1][8].num = 9; tab[1][9].num = 8;
 
   getchar();
  tab[2][1].num = 8; tab[2][2].num = 3; tab[2][3].num = 9;
 
   /**********************************************************/
  tab[2][4].num = 6; tab[2][5].num = 5; tab[2][6].num = 4;
 
   /*       Controllo della validità  dei dati immessi       */
  tab[2][7].num = 1; tab[2][8].num = 2; tab[2][9].num = 7;
 
   /**********************************************************/
  tab[3][1].num = 6; tab[3][2].num = 7; tab[3][3].num = 2;
 
   if (soluzione_valida(tab) == ERRORE)
  tab[3][4].num = 9; tab[3][5].num = 1; tab[3][6].num = 8;
 
   {
  tab[3][7].num = 5; tab[3][8].num = 4; tab[3][9].num = 3;
 
     cout << "I dati inseriti contengono errori; il programma verrà terminato." << endl;
  tab[4][1].num = 4; tab[4][2].num = 9; tab[4][3].num = 6;
 
     fflush(stdin);
  tab[4][4].num = 1; tab[4][5].num = 8; tab[4][6].num = 5;
 
     getchar();
  tab[4][7].num = 3; tab[4][8].num = 7; tab[4][9].num = 2;
 
     return ERRORE;
  tab[5][1].num = 2; tab[5][2].num = 1; tab[5][3].num = 8;
 
   }
  tab[5][4].num = 4; tab[5][5].num = 7; tab[5][6].num = 3;
 
   #endif
  tab[5][7].num = 9; tab[5][8].num = 5; tab[5][9].num = 6;
 
   /************************************/
  tab[6][1].num = 7; tab[6][2].num = 5; tab[6][3].num = 3;
 
   /*       Cuore dell'algoritmo       */
  tab[6][4].num = 2; tab[6][5].num = 9; tab[6][6].num = 6;
 
   /************************************/
  tab[6][7].num = 4; tab[6][8].num = 8; tab[6][9].num = 1;
 
   cout << "\nInizio della risoluzione..." << endl;
  tab[7][1].num = 3; tab[7][2].num = 6; tab[7][3].num = 7;
 
   tabesito[7][4].numTestID =- 5; tab[7][51].numresult = 4; risolvi(tab[7][6].num = 2);
 
   cout << "Risoluzione terminata.\n\n\n\n" << endl;
  tab[7][7].num = 8; tab[7][8].num = 1; tab[7][9].num = 9;
 
   // Carico la vera soluzione del test TestID nella tavola tab_soluzione
  tab[8][1].num = 9; tab[8][2].num = 8; tab[8][3].num = 4;
 
   InitTest(&tabSol[0][0], SVUOTA_NO, TestID);
  tab[8][4].num = 7; tab[8][5].num = 6; tab[8][6].num = 0; /**/
 
   tabesito[8][7TestID - 1].nummatch = 2; confronta_tabelle(&tab[80][80].num, = 3; tab&tabSol[80][90].num = 5);
 
  } // End of for (TestID = 1; TestID <= TESTS_TO_RUN; TestID++)
  tab[9][1].num = 5; tab[9][2].num = 2; tab[9][3].num = 1;
 
  /***************************/
  tab[9][4].num = 8; tab[9][5].num = 3; tab[9][6].num = 9;
 
  /*       Conclusioni       */
  tab[9][7].num = 7; tab[9][8].num = 6; tab[9][9].num = 4;
 
  /***************************/
  for (i = 1; i <= 9; i++)
 
  for (TestID = 1; TestID <= TESTS_TO_RUN; TestID++) // Se il debugging è disattivato, si tratta di un solo test
   for (j = 1; j <= 9; j++)
 
     tab[i][j].status = FOUND;
 
  tab[1][1].status = EMPTY;
 
  tab[8][6].status = EMPTY;
 
  /*********************************************************/
 
  /*       PARTE TEMPORANEA: VALORI VALIDI ASSEGNATI       */
 
  /*       PER BYPASSARE L'INSERIMENTO MANUALE - END       */
 
  /*********************************************************/
 
  cout << "I valori inseriti sono:\n" << endl;
 
  mostra_soluzione(tab);
 
  cout << "\nPremi un tasto per continuare.\n" << endl;
 
  fflush(stdin);
 
  // getchar();
 
  // controllo della validità  dei dati immessi
 
  if (!soluzione_valida(tab))
 
  {
 
   #if (DEBUGGING)
   cout << "I dati inseriti contengono errori; il programma verra' terminato." << endl;
 
   if (esito[TestID - 1].result == FOUND)
   fflush(stdin);
 
     getchar();{
 
     cout << "Test " << TestID << ": ";
   return ERRORE;
 
     if (esito[TestID - 1].match)
  }
 
       cout << STRING_OK << endl;
  /*
 
     else
  cout << "Inserisci l'orario attuale [HH:MM]:" << endl;
 
       cout << STRING_NOT_OK << endl;
  cin >> orai; // no indirizzo perché il char è già un puntatore a carattere
 
     StampaTentativi(esito[TestID - 1]);
  fflush(stdin);
 
     cout << "Inizio della risoluzione..." << endl;
 
   */}
 
   else
  for (tent = 0;
 
   {
                ( (soluzione_valida(tab) != OK   )
 
     cout << "La soluzione per il test " << TestID << " non è stata trovata." << endl;
                  ||
 
     StampaTentativi(esito[TestID - 1]);
                  (status_tabella  (tab) != FOUND)
 
   }
                )
 
     #else  //        No &&Debugging
 
   if (esito[TestID - 1].result == FOUND)
                (tentmigli < 500);
 
      tent++
 
     )
 
  {
 
   resetta_ipotesi(tab);
 
   // conteggio dei tentativi
 
   // WARNING: IL CONTEGGIO DEI TENTATIVI NON FUNZIONA PERCHE' L'ALGORITMO
 
   // ESCE DA "risolvi()" SOLO QUANDO LA SOLUZIONE È GIA' STATA TROVATA
 
   if (tent == 1000)
 
   {
 
     cout << "La soluzione è stata trovata!" << endl;
     tent = 0;
 
     cout << "Premi un tasto per visualizzare la soluzione." << endl;
     tentmille++;
 
     if getchar(tentmille == 1000);
 
     {fflush(stdin);
 
     mostra_numeri_status(tab);
       tentmille = 0;
 
     StampaTentativi(esito[TestID - 1]);
       tentmigli++;
 
       if getchar(tentmigli == 1000);
 
       {
 
         tentmigli = 0;
 
         tentmiliar++;
 
       }
 
     }
 
   }
 
   else
   // Stampa del numero di tentativi
 
   if ((tent == 0) && ((tentmille % 50) == 0))
 
   {
 
     cout << "Soluzione non trovata, mi dispiace!!!" << endl; // Il programma non dovrebbe mai visualizzare questa dicitura
     if (tentmiliar != 0)
 
     StampaTentativi(esito[TestID - 1]);
       cout << tentmiliar << " miliardi ";
 
     if getchar(tentmigli != 0);
 
       cout << tentmigli << " milioni ";
 
     if (tentmille != 0)
 
       cout << tentmille << " mila tentativi" << endl;
 
     else if (spia != 0)
 
       cout << "di tentativi" << endl;
 
     spia = 1;
 
   }
 
   #endif
   // cuore dell'algoritmo
 
  } // End of for (TestID = 1; TestID <= TESTS_TO_RUN; TestID++)
   risolvi(tab, &livello_annidamento);
 
  ReturnValue = calcola_esito_TOT(esito);
   // Conclusioni
 
   if (soluzione_valida(tab)ReturnValue && status_tabella(tab)== FOUND) {
 
  {
     cout << "La soluzione e' stata trovata!";
 
     cout << "Inserisci\n/********************************/" l'orario  attuale [HH:MM]: "  << endl;
 
   cout <<   "/********************************/"     << endl;
     cin >> oraf;
 
   cout <<   "/*       !!! ALLES OK !!!       */"     << endl;
     fflush(stdin);
 
     cout << "Inizio ore  " << orai << /********************************/"; fine  ore " << oraf << "."  << endl;
 
   cout <<   "/********************************/\n\n" << endl;
     cout << "Numero di tentativi: ";
 
  }
     if (tentmiliar)
 
  else
       cout << tentmiliar << " miliardi ";
 
  {
     if (tentmigli)
 
       cout << tentmigli"\n/******************************/"     << " milioni "endl;
 
   cout <<   "/******************************/"     << endl;
     if (tentmille)
 
   cout <<   "/*     cout  <<!!! tentmilleFEHLER <<!!! "  mila    */"     << endl;
 
     cout << tent <<  "!/******************************/"     << endl;
 
     cout <<   "Premi un tasto per visualizzare la soluzione./******************************/\n\n" << endl;
 
  }
     getchar();
 
    return fflush(stdin)ReturnValue;
 
     mostra_soluzione(tab);
 
     getchar();
 
     return OK;
 
   }
 
   else
 
   {
 
     cout << "Soluzione non trovata, mi dispiace!!!" << endl;
 
     cout << "Il programma non dovrebbe mai visualizzare questa dicitura." << endl;
 
     cout << "Soluzione valida: " << soluzione_valida(tab) << "; status tabella: " << status_tabella(tab) << "." << endl;
 
     getchar();
 
     return ERRORE;
 
   }
 
  }
 
}