Contenuto cancellato Contenuto aggiunto
asdasd
Annullata la modifica 101173309 di BlueCap88 (discussione)
Etichetta: Annulla
Riga 3:
<nowiki>#</nowiki>include <iostream>
 
// #include <string>  // es: string blabla; cin >> blabla;
 
<nowiki>#</nowiki>include "sudoku2lib.h"
Riga 9:
using namespace std;
 
type_tavola tab;
int TestID = 1;
 
int livello_annidamento = 0;
int livelloAnnidamento = 1; // spostare quanto più possibile nel main
 
type_esitoTest esito[TESTS_TO_RUN] /* = {UNKNOWN} */;
 
int main()
Riga 19 ⟶ 17:
{
 
  char orai[5] = {'?', '?', '?', '?', '?'};
  int ReturnValue = UNKNOWN;
 
  type_tavola tab;
 
  type_tavola tabSol;
 
  char oraf[5] = {'?', '?', '?', '?', '?'};
  #if (!DEBUGGING)
 
  int i = 1;
Riga 31 ⟶ 25:
  int j = 1;
 
  int spia = 0;
  #endif
 
  int tent = 0;
  cout << "    Algoritmo di risoluzione del SUDOKU        \n" << endl;
 
  int tentmille = 0;
  cout << "Ingegneria fisica - Politecnico di Milano      " << endl;
 
  int tentmigli = 0;
  cout << "     Informatica A - Prof. Sam Guinea\n        " << endl;
 
  int tentmiliar = 0;
  cout << "      (2) Dott. Mag. Ing. Antonio Indirli      " << endl;
 
  // int tentativicella = 0;
  cout << "               Embedded SW Dev.                " << endl;
 
  cout << "      Algoritmo  di  risoluzione  del  SUDOKU   Alten ITALIA                   \n\n\n" << endl;
 
  cout << "Ingegneria fisica - Politecnico di Milano  " << endl;
  for (TestID = 1; TestID <= TESTS_TO_RUN; TestID++)
 
  cout << "     Informatica A - Prof. Sam Guinea      " << endl << endl << endl << endl;
  {
 
  cout << "Inserire valori noti (0 se non si conosce)." << endl << endl;
   #if (DEBUGGING)
 
  // string bla;
   InitTest(&tab[0][0], SVUOTA_SI, TestID);
 
  // cout << "Debug: inserire una stringa:" << endl;
   #else // No Debugging
 
  // cin >> bla;
   /**********************************************/
 
   /*/  cout  <<  "la Inserimentostringa deiinserita valoriè: -" BEGIN<<  bla  <<  "!!!!!!"<< */endl;
 
   /**********************************************/
 
  /*       Inserimento dei valori - BEGIN       */
   cout << "Inserire valori noti (0 se non si conosce).\n\n" << endl;
 
  /**********************************************/ /*
   for (i = 1; i <= 9; i++) {
 
    for cout(i <<= "1; RIGAi " <<= 9; i++) << endl;{
 
     forcout (j<< =" 1;RIGA j" <=< 9;i j++)<< {endl;
 
      for (j = 1; j <= 9; doj++) {
 
     do {
         cout << "(" << i << ":" << j << ")= ";
 
       cout << "(" << i << ":" << j << ")= " endl;
         cin >> tab[i][j].num;                               // Non sono sicuro se serve passargli l'indirizzo, credo di sì in realtà!!
 
         if ((tab[i][j].numcin >= 1) &&> (tab[i][j].num; <=// 9))non  sono //sicuro Dase 1serve apassargli 9l'indirizzo, ilcredo di valore èin certorealtà!!
 
          if ((tab[i][j].statusnum >= FOUND;1) && (tab[i][j].num <= 9)) // Da 1 a 9, il valore è certo
 
         elsetab[i][j].status=FOUND;
 
           tab[i][j].status = EMPTY;else
 
         } while ((tab[i][j].num < 0) || (tab[i][j].num > 9))status=EMPTY; // Sotto 0 e sopra 9, ciclo da rifare
 
     } while (tab[i][j].num<0 || tab[i][j].num>9); // sotto 0 e sopra 9, ciclo da rifare
       if ((j % 3) == 0)
 
        if ((j % cout3) <<== endl;0)
 
       cout << }endl;
 
     cout << endl;
 
   }
 
   cout << endl;
   /********************************************/
 
  } */
   /*       Inserimento dei valori - END       */
 
   /********************************************/
 
  /*       Inserimento dei valori - END       */
   #endif
 
  /********************************************/
   #if (DEBUGGING)
 
  /***********************************************************/
   cout << "Test numero "<< TestID << ". ";
 
  /*        PARTE TEMPORANEA: VALORI VALIDI ASSEGNATI        */
   #endif
 
  /*       PER BYPASSARE L'INSERIMENTO MANUALE - BEGIN       */
   cout << "I valori inseriti sono:\n" << endl;
 
  /***********************************************************/
   mostra_numeri_status(tab);
 
  tab[1][1].num = 0; tab[1][2].num = 4; tab[1][3].num = 5;
   #if (!DEBUGGING)
 
  tab[1][4].num = 3; tab[1][5].num = 2; tab[1][6].num = 7;
   cout << "\nPremi un tasto per continuare.\n" << endl;
 
  tab[1][7].num = 6; tab[1][8].num = 9; tab[1][9].num = 8;
   fflush(stdin);
 
  tab[2][1].num = 8; tab[2][2].num = 3; tab[2][3].num = 9;
   getchar();
 
  tab[2][4].num = 6; tab[2][5].num = 5; tab[2][6].num = 4;
   /**********************************************************/
 
  tab[2][7].num = 1; tab[2][8].num = 2; tab[2][9].num = 7;
   /*       Controllo della validità  dei dati immessi       */
 
  tab[3][1].num = 6; tab[3][2].num = 7; tab[3][3].num = 2;
   /**********************************************************/
 
  tab[3][4].num = 9; tab[3][5].num = 1; tab[3][6].num = 8;
   if (soluzione_valida(tab) == ERRORE)
 
  tab[3][7].num = 5; tab[3][8].num = 4; tab[3][9].num = 3;
   {
 
  tab[4][1].num = 4; tab[4][2].num = 9; tab[4][3].num = 6;
     cout << "I dati inseriti contengono errori; il programma verrà terminato." << endl;
 
  tab[4][4].num = 1; tab[4][5].num = 8; tab[4][6].num = 5;
     fflush(stdin);
 
  tab[4][7].num = 3; tab[4][8].num = 7; tab[4][9].num = 2;
     getchar();
 
  tab[5][1].num = 2; tab[5][2].num = 1; tab[5][3].num = 8;
     return ERRORE;
 
  tab[5][4].num = 4; tab[5][5].num = 7; tab[5][6].num = 3;
   }
 
  tab[5][7].num = 9; tab[5][8].num = 5; tab[5][9].num = 6;
   #endif
 
  tab[6][1].num = 7; tab[6][2].num = 5; tab[6][3].num = 3;
   /************************************/
 
  tab[6][4].num = 2; tab[6][5].num = 9; tab[6][6].num = 6;
   /*       Cuore dell'algoritmo       */
 
  tab[6][7].num = 4; tab[6][8].num = 8; tab[6][9].num = 1;
   /************************************/
 
  tab[7][1].num = 3; tab[7][2].num = 6; tab[7][3].num = 7;
   cout << "\nInizio della risoluzione..." << endl;
 
   esitotab[TestID7][4].num -= 15; tab[7][5].resultnum = risolvi(4; tab)[7][6].num = 2;
 
  tab[7][7].num = 8; tab[7][8].num = 1; tab[7][9].num = 9;
   cout << "Risoluzione terminata.\n\n\n\n" << endl;
 
  tab[8][1].num = 9; tab[8][2].num = 8; tab[8][3].num = 4;
   // Carico la vera soluzione del test TestID nella tavola tab_soluzione
 
  tab[8][4].num = 7; tab[8][5].num = 6; tab[8][6].num = 0; /**/
   InitTest(&tabSol[0][0], SVUOTA_NO, TestID);
 
   esitotab[TestID - 18][7].matchnum = confronta_tabelle(&2; tab[08][08],.num &tabSol= 3; tab[08][09]).num = 5;
 
  tab[9][1].num = 5; tab[9][2].num = 2; tab[9][3].num = 1;
  } // End of for (TestID = 1; TestID <= TESTS_TO_RUN; TestID++)
 
  tab[9][4].num = 8; tab[9][5].num = 3; tab[9][6].num = 9;
  /***************************/
 
  tab[9][7].num = 7; tab[9][8].num = 6; tab[9][9].num = 4;
  /*       Conclusioni       */
 
  for (i = 1; i <= 9; i++)
  /***************************/
 
   for (j = 1; j <= 9; j++)
  for (TestID = 1; TestID <= TESTS_TO_RUN; TestID++) // Se il debugging è disattivato, si tratta di un solo test
 
     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))
 
  {
 
   cout << "I dati inseriti contengono errori; il programma verra' terminato." << endl;
   #if (DEBUGGING)
 
   fflush(stdin);
   if (esito[TestID - 1].result == FOUND)
 
     {getchar();
 
   return ERRORE;
     cout << "Test " << TestID << ": ";
 
  }
     if (esito[TestID - 1].match)
 
  /*
       cout << STRING_OK << endl;
 
  cout << "Inserisci l'orario attuale [HH:MM]:" << endl;
     else
 
  cin >> orai; // no indirizzo perché il char è già un puntatore a carattere
       cout << STRING_NOT_OK << endl;
 
  fflush(stdin);
     StampaTentativi(esito[TestID - 1]);
 
     cout << "Inizio della risoluzione..." << endl;
 
   }*/
 
  for (tent = 0;
   else
 
                ( (soluzione_valida(tab) != OK   )
   {
 
                  ||
     cout << "La soluzione per il test " << TestID << " non è stata trovata." << endl;
 
                  (status_tabella  (tab) != FOUND)
     StampaTentativi(esito[TestID - 1]);
 
                )
   }
 
    #else  //  No        Debugging&&
 
                (tentmigli < 500);
   if (esito[TestID - 1].result == FOUND)
 
      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)
 
   {
 
     tent = 0;
     cout << "La soluzione è stata trovata!" << endl;
 
     tentmille++;
     cout << "Premi un tasto per visualizzare la soluzione." << endl;
 
     getcharif (tentmille == 1000);
 
     fflush(stdin);{
 
       tentmille = 0;
     mostra_numeri_status(tab);
 
       tentmigli++;
     StampaTentativi(esito[TestID - 1]);
 
       getcharif (tentmigli == 1000);
 
       {
 
         tentmigli = 0;
 
         tentmiliar++;
 
       }
 
     }
 
   }
 
   // Stampa del numero di tentativi
   else
 
   if ((tent == 0) && ((tentmille % 50) == 0))
 
   {
 
     if (tentmiliar != 0)
     cout << "Soluzione non trovata, mi dispiace!!!" << endl; // Il programma non dovrebbe mai visualizzare questa dicitura
 
       cout << tentmiliar << " miliardi ";
     StampaTentativi(esito[TestID - 1]);
 
     getcharif (tentmigli != 0);
 
       cout << tentmigli << " milioni ";
 
     if (tentmille != 0)
 
       cout << tentmille << " mila tentativi" << endl;
 
     else if (spia != 0)
 
       cout << "di tentativi" << endl;
 
     spia = 1;
 
   }
 
   // cuore dell'algoritmo
   #endif
 
   risolvi(tab, &livello_annidamento);
  } // End of for (TestID = 1; TestID <= TESTS_TO_RUN; TestID++)
 
   // Conclusioni
  ReturnValue = calcola_esito_TOT(esito);
 
   if (ReturnValuesoluzione_valida(tab) && status_tabella(tab)== FOUND) {
 
     cout << "La soluzione e' stata trovata!";
  {
 
     cout << "\n/********************************/"Inserisci  l'orario  attuale [HH:MM]: " << endl;
 
     cin >> oraf;
   cout <<   "/********************************/"     << endl;
 
     fflush(stdin);
   cout <<   "/*       !!! ALLES OK !!!       */"     << endl;
 
     cout <<  "Inizio ore "/********************************/ << orai << ";  fine  ore " << oraf << "." << endl;
 
     cout << "Numero di tentativi: ";
   cout <<   "/********************************/\n\n" << endl;
 
     if (tentmiliar)
  }
 
       cout << tentmiliar << " miliardi ";
  else
 
     if (tentmigli)
  {
 
       cout << "\n/******************************/"    tentmigli << endl" milioni ";
 
     if (tentmille)
   cout <<   "/******************************/"     << endl;
 
   cout <<   "/*      cout !!!<< FEHLERtentmille !!!<<  "  mila   */"     << endl;
 
     cout <<  tent << "/******************************/!"     << endl;
 
     cout <<   "/******************************/\n\nPremi un tasto per visualizzare la soluzione." << endl;
 
     getchar();
  }
 
  return   ReturnValuefflush(stdin);
 
     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;
 
   }
 
  }
 
}