Accueil > > > SUDOKU NIVEAU FACIL, MOYEN DIFFICILE (GOOGLE) PAS AU PLUS
SUDOKU NIVEAU FACIL, MOYEN DIFFICILE (GOOGLE) PAS AU PLUS
Information sur la source
Description
Programme de résolution des Sudokus de niveau facile, moyen, difficile, d'après l'estimation de difficulté des sudokus de google. Possibilité d'enregistrer les grilles, et de les charger par la suite. pour le niveau facile et moyen, la logique du programme résout parfaitement la grille. Pour les difficiles... j'ai magouillé un peu ... mais ce n'est pas de la logique pure. Pour les niveaux de difficultés supérieurs ( expert et diabolique) je n'y parvient pas. Ps: votre aide est la bienvenue, ainsi vos critiques.
Source
- #include "appli.h"
-
- main()
- {
- FILE *fp;
- coord point;
- coord temp[100];
- int tab[9][9][10][2];
- int i,j,k,l;
- int ii,jj,ll,kk;
- int count=0;
- int compteur;
- char rep;
- int choix;
- char nom[20];
- int bloquer=0, bl, retry=0, tempo;
-
- printf("\nOuvrir un sudoku existant ? taper 1. ");
- printf("\nEntrer manuellement un nouveau Sudoku ? taper 2. ");
- scanf("%d",&choix);
-
- if(choix==1)
- {
- printf("\n Entrer nom du Sudoku :");
- scanf("%s",&nom);
- debut:
- fp=fopen(nom,"r");
- if(fp==NULL) exit(0);
-
- for(i=0; i<9; i++)
- {
- for(j=0; j<9; j++)
- {
- fscanf(fp,"%d",&tab[i][j][9][0]);
- for(k=0; k<9; k++)
- {
- tab[i][j][k][0]=k+1;
- }
- }
- }
- fclose(fp);
- }
-
- if(choix==2)
- {
- choix=1;
- printf("\nEntrer un nom: ");
- scanf("%s",&nom);
- l=11;
- for(i=0;i<9;i++)
- { for(j=0;j<9;j++)
- { tab[i][j][9][0]=l;
- for(k=0; k<9; k++)
- {
- tab[i][j][k][0]=k+1;
- }
- l++;
- }
- }
- }
- /////////////
- //printf("bloquer = %d\n",bloquer);
- //system("pause");
- if(bloquer >= 1)
- { for(bl=0; bl<retry;bl++)
- {
- i=temp[bl].x;
- j=temp[bl].y;
- kk= temp[bl].k;
- tab[i][j][kk][0] = 10;
- for(kk=0; kk<9; kk++)
- {
- //printf("tab[%d][%d][%d][%d] = %d\n",i,j,kk,0, tab[i][j][kk][0]);
- //system("pause");
- }
- }
- }
-
- /////////////
-
- i=0; j=0;
- while(point.test != 1)
- {
- point=bouger(tab, i,j);
- if(point.test==0)
- {
- tab[point.x][point.y][9][0] = point.val;
- i=point.x; j=point.y;
- }
- }
-
- fp=fopen(nom,"w+");
- for(i=0; i<9; i++)
- {
- for(j=0; j<9; j++)
- {
- fprintf(fp,"%d ",tab[i][j][9][0]);
- }
- }
- fclose(fp);
-
-
- while(1)//coord point; tab[][][9] contient la valeur unique de la case tab[][]
- {
- for(i=0; i<9; i++)
- { for(j=0; j<9; j++)
- { if(tab[i][j][9][0]<=9)
- { for(kk=0;kk<9;kk++)
- {
- tab[i][j][kk][0]=10;
- } } } }
-
- k=0;
- for(i=0; i<9; i++) // Initialise les compteurs ...
- { for(j=0; j<9; j++)
- { for(kk=0; kk<10; kk++)
- { tab[i][j][kk][1]=0; // ...à zero
- } } }
-
- //lignes
- for(i=0; i<9; i++)// scanne les lignes pour enlever des possibilités les chiffres rencontrés.
- { for(j=0; j<9; j++)
- { for(kk=0; kk<9; kk++)
- { for(ii=0; ii<9; ii++)
- { if( tab[i][j][kk][0] == tab[ii][j][9][0] )
- { tab[i][j][kk][0] = 10;
- } } } } }
-
- //colonnes
- for(i=0; i<9; i++)// scanne les colonnes pour faire de meme.
- { for(j=0; j<9; j++)
- { for(kk=0; kk<9; kk++)
- { for(jj=0; jj<9; jj++)
- { if( tab[i][j][kk][0] == tab[i][jj][9][0] )
- { tab[i][j][kk][0] = 10;
- } } } } }
-
- for(i=0;i<9;i++) // Plus complexe: scanne les blocs un par un. Ecarte les possibilités égalements.
- { for(j=0;j<9;j++)
- { if(tab[i][j][9][0]<10) // si valeur de la case est comprise entre 1 et 9
- { if(i<3)
- { if(j<3)
- { for(ii=0; ii<3; ii++)
- { for(jj=0;jj<3;jj++)
- { if(i==ii && j==jj) kk=0;
- else
- { for(ll=0; ll<9; ll++)
- { if(tab[ii][jj][ll][0]==tab[i][j][9][0])
- { tab[ii][jj][ll][0]=10;
- } } } } } }
- if(j>=3 && j<6)
- { for(ii=0; ii<3; ii++)
- { for(jj=3;jj<6;jj++)
- { if(i==ii && j==jj) kk=0;
- else
- { for(ll=0; ll<9; ll++)
- { if(tab[ii][jj][ll][0]==tab[i][j][9][0])
- { tab[ii][jj][ll][0]=10;
- } } } } } }
- if(j>=6)
- { for(ii=0; ii<3; ii++)
- { for(jj=6;jj<9;jj++)
- { if(i==ii && j==jj) kk=0;
- else
- { for(ll=0; ll<9; ll++)
- { if(tab[ii][jj][ll][0]==tab[i][j][9][0])
- { tab[ii][jj][ll][0]=10;
- } } } } } } }
- if(i>=3 && i<6)
- {
- if(j<3)
- { for(ii=3; ii<6; ii++)
- { for(jj=0;jj<3;jj++)
- { if(i==ii && j==jj) kk=0;
- else
- { for(ll=0; ll<9; ll++)
- { if(tab[ii][jj][ll][0]==tab[i][j][9][0])
- { tab[ii][jj][ll][0]=10;
- } } } } } }
- if(j>=3 && j<6)
- { for(ii=3; ii<6; ii++)
- { for(jj=3;jj<6;jj++)
- { if(i==ii && j==jj) kk=0;
- else
- { for(ll=0; ll<9; ll++)
- { if(tab[ii][jj][ll][0]==tab[i][j][9][0])
- { tab[ii][jj][ll][0]=10;
- } } } } } }
- if(j>=6)
- { for(ii=3; ii<6; ii++)
- { for(jj=6;jj<9;jj++)
- { if(i==ii && j==jj) kk=0;
- else
- { for(ll=0; ll<9; ll++)
- { if(tab[ii][jj][ll][0]==tab[i][j][9][0])
- { tab[ii][jj][ll][0]=10;
- } } } } } } }
- if(i>=6)
- { if(j<3)
- { for(ii=6; ii<9; ii++)
- { for(jj=0;jj<3;jj++)
- { if(i==ii && j==jj) kk=0;
- else
- { for(ll=0; ll<9; ll++)
- { if(tab[ii][jj][ll][0]==tab[i][j][9][0])
- { tab[ii][jj][ll][0]=10;
- } } } } } }
- if(j>=3 && j<6)
- { for(ii=6; ii<9; ii++)
- { for(jj=3;jj<6;jj++)
- { if(i==ii && j==jj) kk=0;
- else
- { for(ll=0; ll<9; ll++)
- { if(tab[ii][jj][ll][0]==tab[i][j][9][0])
- {
- tab[ii][jj][ll][0]=10;
- } } } } } }
- if(j>=6)
- { for(ii=6; ii<9; ii++)
- { for(jj=6;jj<9;jj++)
- { if(i==ii && j==jj) kk=0;
- else
- { for(ll=0; ll<9; ll++)
- { if(tab[ii][jj][ll][0]==tab[i][j][9][0])
- { tab[ii][jj][ll][0]=10;
- } } } } } } } }
-
-
- if(tab[i][j][9][0]>9)// Compte dans les blocs les nombres de fois que l'on rencontre une possibilité.
- {
- k=0;
- if(i<3)
- { if(j<3)
- { for(kk=0; kk<9; kk++)
- { if( tab[i][j][kk][0] != 10 )
- { for(ii=0; ii<3; ii++)
- { for(jj=0;jj<3;jj++)
- { if( (tab[ii][jj][9][0]>10) )
- { if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
- {
- tab[i][j][kk][1]++;
- } } } } } } }
-
- if(j>=3 && j<6)
- { for(kk=0; kk<9; kk++)
- { if( tab[i][j][kk][0] != 10 )
- { for(ii=0; ii<3; ii++)
- { for(jj=3;jj<6;jj++)
- { if( (tab[ii][jj][9][0]>10) )
- { if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
- {
- tab[i][j][kk][1]++;
- } } } } } } }
-
- if(j>=6)
- { for(kk=0; kk<9; kk++)
- { if( tab[i][j][kk][0] != 10 )
- { for(ii=0; ii<3; ii++)
- { for(jj=6;jj<9;jj++)
- { if( (tab[ii][jj][9][0]>10) )
- { if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
- {
- tab[i][j][kk][1]++;
- } } } } } } }
- }
- if(i>=3 && i<6)
- { if(j<3)
- { for(kk=0; kk<9; kk++)
- { if( tab[i][j][kk][0] != 10 )
- { for(ii=3; ii<6; ii++)
- { for(jj=0;jj<3;jj++)
- { if( (tab[ii][jj][9][0]>10) )
- { if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
- {
- tab[i][j][kk][1]++;
- } } } } } } }
-
- if(j>=3 && j<6)
- { for(kk=0; kk<9; kk++)
- { if( tab[i][j][kk][0] != 10 )
- { for(ii=3; ii<6; ii++)
- { for(jj=3;jj<6;jj++)
- { if( (tab[ii][jj][9][0]>10) )
- { if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
- {
- tab[i][j][kk][1]++;
- } } } } } } }
-
- if(j>=6)
- { for(kk=0; kk<9; kk++)
- { if( tab[i][j][kk][0] != 10 )
- { for(ii=3; ii<6; ii++)
- { for(jj=6;jj<9;jj++)
- { if( (tab[ii][jj][9][0]>10) )
- { if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
- {
- tab[i][j][kk][1]++;
- } } } } } } }
- }
- if(i>=6)
- { if(j<3)
- { for(kk=0; kk<9; kk++)
- { if( tab[i][j][kk][0] != 10 )
- { for(ii=6; ii<9; ii++)
- { for(jj=0;jj<3;jj++)
- { if( (tab[ii][jj][9][0]>10) )
- { if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
- {
- tab[i][j][kk][1]++;
- } } } } } } }
-
- if(j>=3 && j<6) //bloc test.
- { for(kk=0; kk<9; kk++)
- { if( tab[i][j][kk][0] != 10 )
- { for(ii=6; ii<9; ii++)
- { for(jj=3; jj<6; jj++)
- { if( (tab[ii][jj][9][0]>10) )
- { if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
- {
- tab[i][j][kk][1]++;
- } } } } } } }
-
- if(j>=6)
- { for(kk=0; kk<9; kk++)
- { if( tab[i][j][kk][0] != 10 )
- { for(ii=6; ii<9; ii++)
- { for(jj=6;jj<9;jj++)
- { if( (tab[ii][jj][9][0]>10) )
- { if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
- {
- tab[i][j][kk][1]++;
- } } } } } } }
- }
- }
- }
- }//fin du comptage des possibilités des blocs.
-
- for(i=0; i<9; i++) // Affectation de la valeur mise en évidence par le comptage.
- { for(j=0; j<9; j++)
- { if(tab[i][j][9][0] > 9)
- { for(kk=0; kk<9; kk++)
- { if( (tab[i][j][kk][1]==1) && (tab[i][j][kk][0]!=10) )
- {
- tab[i][j][9][0] = tab[i][j][kk][0];
- goto fin;
- } } } } }
-
- for(i=0; i<9; i++) // Reinitialise a zero le comptage...
- { for(j=0; j<9; j++)
- { for(kk=0; kk<10; kk++)
- { tab[i][j][kk][1]=0;
- } } }
-
- for(i=0; i<9; i++) // 2eme comptage. Cette fois, au niveau des lignes.
- { for(j=0; j<9; j++)
- { if(tab[i][j][9][0] > 9)
- { for(ii=0; ii<9; ii++)
- { if(tab[ii][j][9][0] > 9)
- { for(kk=0; kk<9; kk++)
- { if( tab[i][j][kk][0] < 10 )
- {
- if(tab[i][j][kk][0] == tab[ii][j][kk][0])
- {
- tab[i][j][kk][1]++;
- } } } } } } } }
-
- for(i=0; i<9; i++) // 2eme affectation des valeurs trouvées.
- { for(j=0; j<9; j++)
- { if(tab[i][j][9][0] > 9)
- { for(kk=0; kk<9; kk++)
- { if( (tab[i][j][kk][1]==1) && (tab[i][j][kk][0]!=10) )
- {
- tab[i][j][9][0] = tab[i][j][kk][0];
- goto fin;
- } } } } }
-
-
-
- for(i=0; i<9; i++) // 2eme réinitialisation des compteurs
- { for(j=0; j<9; j++)
- { for(kk=0; kk<9; kk++)
- { tab[i][j][kk][1]=0;
- } } }
-
- for(i=0; i<9; i++) // 3eme comptage. Au niveau des colonnes.
- { for(j=0; j<9; j++)
- { if(tab[i][j][9][0] > 9)
- { for(jj=0; jj<9; jj++)
- { if( tab[i][jj][9][0] > 9 )
- { for(kk=0; kk<9; kk++)
- { if( tab[i][j][kk][0] != 10 )
- {
- if(tab[i][j][kk][0] == tab[i][jj][kk][0])
- {
- tab[i][j][kk][1]++;
- }
- } } } } } } }
-
- for(i=0; i<9; i++) // 3eme affectation des valeurs. La réinitialisation aura lieu au debut
- { for(j=0; j<9; j++) // de la boucle generale.
- { if(tab[i][j][9][0] > 9)
- { for(kk=0; kk<9; kk++)
- { if( (tab[i][j][kk][1]==1) && (tab[i][j][kk][0]!=10) )
- {
- tab[i][j][9][0] = tab[i][j][kk][0];
- goto fin;
- } } } } }
-
- for(i=0; i<9; i++)
- { for(j=0; j<9; j++)
- {
- compteur = 0;
- for(kk=0; kk<9; kk++)
- {
- if(tab[i][j][kk][0] != 10)
- {
- temp[99].val = tab[i][j][kk][0];
- temp[99].x =i;
- temp[99].y =j;
- compteur++;
- }
- }
- if(compteur == 1)
- {
- tab[temp[99].x][temp[99].y][9][0]= temp[99].val;
- goto fin;
- }
- }
- }
- fin:
- count=0;
- for (i=0;i<9;i++) // compte le nombre de possibilités restantes.
- { for(j=0;j<9;j++)
- { if(tab[i][j][9][0]>=10)
- {
- count++;
- } } }
-
-
- /////////////////////////////////
- if(tempo==count)
- { for(i=0; i<9; i++)
- { for(j=0; j<9; j++)
- { if(tab[i][j][9][0]>9)
- { for(kk=0; kk<9; kk++)
- { if(tab[i][j][kk][1]==2)
- {
- if(bloquer>=1)
- {
- for(bl=0; bl<bloquer; bl++)
- {
- if(i!= temp[bl].x && j!=temp[bl].y && kk!= temp[bl].k)
- {
- tab[i][j][9][0]=tab[i][j][kk][0];
- temp[bloquer].x=i;
- temp[bloquer].y=j;
- temp[bloquer].k=kk;
- bloquer++;
- goto fin2;
- }
- }
- }
- else
- {
- tab[i][j][9][0]=tab[i][j][kk][0];
- temp[bloquer].x= i;
- temp[bloquer].y= j;
- temp[bloquer].k= kk;
- // for(kk=0; kk<9; kk++)printf("\n\ntab[%d][%d][%d][%d]= %d\n\n",i,j,kk,0,tab[i][j][kk][0]);
- bloquer++;
- // printf("\a");
- // system("pause");
- goto fin2;
- }
- } } } } } }
- if(tempo == count && bloquer>=1)
- {
- if(count==0) goto fin2;
- retry++;
- // printf("\a");
- goto debut;
- }
- tempo=count;
- fin2:
-
- //printf("\n>>%d<<\n",count);
- if(count==0)
- {
- printf("\n");
- affiche(0,0,tab, 0);
- system("pause");
- return 0;
- }
-
- /////////////////////////////////
-
- //printf("continuer ? (o/n)");
- //rep=fgetc(stdin);
- if(rep=='n') return 0;
- if(rep=='a')
- {
- point=bouger(tab, 0, 0);
- if(point.test==0)
- {
- tab[point.x][point.y][9][0]=point.val;
- }
- }
- if(rep=='r')
- {
- retry++;
- goto debut;
- }
- }
- }
-
- fin(char *pMsg)
- {
- puts(pMsg);
- }
#include "appli.h"
main()
{
FILE *fp;
coord point;
coord temp[100];
int tab[9][9][10][2];
int i,j,k,l;
int ii,jj,ll,kk;
int count=0;
int compteur;
char rep;
int choix;
char nom[20];
int bloquer=0, bl, retry=0, tempo;
printf("\nOuvrir un sudoku existant ? taper 1. ");
printf("\nEntrer manuellement un nouveau Sudoku ? taper 2. ");
scanf("%d",&choix);
if(choix==1)
{
printf("\n Entrer nom du Sudoku :");
scanf("%s",&nom);
debut:
fp=fopen(nom,"r");
if(fp==NULL) exit(0);
for(i=0; i<9; i++)
{
for(j=0; j<9; j++)
{
fscanf(fp,"%d",&tab[i][j][9][0]);
for(k=0; k<9; k++)
{
tab[i][j][k][0]=k+1;
}
}
}
fclose(fp);
}
if(choix==2)
{
choix=1;
printf("\nEntrer un nom: ");
scanf("%s",&nom);
l=11;
for(i=0;i<9;i++)
{ for(j=0;j<9;j++)
{ tab[i][j][9][0]=l;
for(k=0; k<9; k++)
{
tab[i][j][k][0]=k+1;
}
l++;
}
}
}
/////////////
//printf("bloquer = %d\n",bloquer);
//system("pause");
if(bloquer >= 1)
{ for(bl=0; bl<retry;bl++)
{
i=temp[bl].x;
j=temp[bl].y;
kk= temp[bl].k;
tab[i][j][kk][0] = 10;
for(kk=0; kk<9; kk++)
{
//printf("tab[%d][%d][%d][%d] = %d\n",i,j,kk,0, tab[i][j][kk][0]);
//system("pause");
}
}
}
/////////////
i=0; j=0;
while(point.test != 1)
{
point=bouger(tab, i,j);
if(point.test==0)
{
tab[point.x][point.y][9][0] = point.val;
i=point.x; j=point.y;
}
}
fp=fopen(nom,"w+");
for(i=0; i<9; i++)
{
for(j=0; j<9; j++)
{
fprintf(fp,"%d ",tab[i][j][9][0]);
}
}
fclose(fp);
while(1)//coord point; tab[][][9] contient la valeur unique de la case tab[][]
{
for(i=0; i<9; i++)
{ for(j=0; j<9; j++)
{ if(tab[i][j][9][0]<=9)
{ for(kk=0;kk<9;kk++)
{
tab[i][j][kk][0]=10;
} } } }
k=0;
for(i=0; i<9; i++) // Initialise les compteurs ...
{ for(j=0; j<9; j++)
{ for(kk=0; kk<10; kk++)
{ tab[i][j][kk][1]=0; // ...à zero
} } }
//lignes
for(i=0; i<9; i++)// scanne les lignes pour enlever des possibilités les chiffres rencontrés.
{ for(j=0; j<9; j++)
{ for(kk=0; kk<9; kk++)
{ for(ii=0; ii<9; ii++)
{ if( tab[i][j][kk][0] == tab[ii][j][9][0] )
{ tab[i][j][kk][0] = 10;
} } } } }
//colonnes
for(i=0; i<9; i++)// scanne les colonnes pour faire de meme.
{ for(j=0; j<9; j++)
{ for(kk=0; kk<9; kk++)
{ for(jj=0; jj<9; jj++)
{ if( tab[i][j][kk][0] == tab[i][jj][9][0] )
{ tab[i][j][kk][0] = 10;
} } } } }
for(i=0;i<9;i++) // Plus complexe: scanne les blocs un par un. Ecarte les possibilités égalements.
{ for(j=0;j<9;j++)
{ if(tab[i][j][9][0]<10) // si valeur de la case est comprise entre 1 et 9
{ if(i<3)
{ if(j<3)
{ for(ii=0; ii<3; ii++)
{ for(jj=0;jj<3;jj++)
{ if(i==ii && j==jj) kk=0;
else
{ for(ll=0; ll<9; ll++)
{ if(tab[ii][jj][ll][0]==tab[i][j][9][0])
{ tab[ii][jj][ll][0]=10;
} } } } } }
if(j>=3 && j<6)
{ for(ii=0; ii<3; ii++)
{ for(jj=3;jj<6;jj++)
{ if(i==ii && j==jj) kk=0;
else
{ for(ll=0; ll<9; ll++)
{ if(tab[ii][jj][ll][0]==tab[i][j][9][0])
{ tab[ii][jj][ll][0]=10;
} } } } } }
if(j>=6)
{ for(ii=0; ii<3; ii++)
{ for(jj=6;jj<9;jj++)
{ if(i==ii && j==jj) kk=0;
else
{ for(ll=0; ll<9; ll++)
{ if(tab[ii][jj][ll][0]==tab[i][j][9][0])
{ tab[ii][jj][ll][0]=10;
} } } } } } }
if(i>=3 && i<6)
{
if(j<3)
{ for(ii=3; ii<6; ii++)
{ for(jj=0;jj<3;jj++)
{ if(i==ii && j==jj) kk=0;
else
{ for(ll=0; ll<9; ll++)
{ if(tab[ii][jj][ll][0]==tab[i][j][9][0])
{ tab[ii][jj][ll][0]=10;
} } } } } }
if(j>=3 && j<6)
{ for(ii=3; ii<6; ii++)
{ for(jj=3;jj<6;jj++)
{ if(i==ii && j==jj) kk=0;
else
{ for(ll=0; ll<9; ll++)
{ if(tab[ii][jj][ll][0]==tab[i][j][9][0])
{ tab[ii][jj][ll][0]=10;
} } } } } }
if(j>=6)
{ for(ii=3; ii<6; ii++)
{ for(jj=6;jj<9;jj++)
{ if(i==ii && j==jj) kk=0;
else
{ for(ll=0; ll<9; ll++)
{ if(tab[ii][jj][ll][0]==tab[i][j][9][0])
{ tab[ii][jj][ll][0]=10;
} } } } } } }
if(i>=6)
{ if(j<3)
{ for(ii=6; ii<9; ii++)
{ for(jj=0;jj<3;jj++)
{ if(i==ii && j==jj) kk=0;
else
{ for(ll=0; ll<9; ll++)
{ if(tab[ii][jj][ll][0]==tab[i][j][9][0])
{ tab[ii][jj][ll][0]=10;
} } } } } }
if(j>=3 && j<6)
{ for(ii=6; ii<9; ii++)
{ for(jj=3;jj<6;jj++)
{ if(i==ii && j==jj) kk=0;
else
{ for(ll=0; ll<9; ll++)
{ if(tab[ii][jj][ll][0]==tab[i][j][9][0])
{
tab[ii][jj][ll][0]=10;
} } } } } }
if(j>=6)
{ for(ii=6; ii<9; ii++)
{ for(jj=6;jj<9;jj++)
{ if(i==ii && j==jj) kk=0;
else
{ for(ll=0; ll<9; ll++)
{ if(tab[ii][jj][ll][0]==tab[i][j][9][0])
{ tab[ii][jj][ll][0]=10;
} } } } } } } }
if(tab[i][j][9][0]>9)// Compte dans les blocs les nombres de fois que l'on rencontre une possibilité.
{
k=0;
if(i<3)
{ if(j<3)
{ for(kk=0; kk<9; kk++)
{ if( tab[i][j][kk][0] != 10 )
{ for(ii=0; ii<3; ii++)
{ for(jj=0;jj<3;jj++)
{ if( (tab[ii][jj][9][0]>10) )
{ if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
{
tab[i][j][kk][1]++;
} } } } } } }
if(j>=3 && j<6)
{ for(kk=0; kk<9; kk++)
{ if( tab[i][j][kk][0] != 10 )
{ for(ii=0; ii<3; ii++)
{ for(jj=3;jj<6;jj++)
{ if( (tab[ii][jj][9][0]>10) )
{ if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
{
tab[i][j][kk][1]++;
} } } } } } }
if(j>=6)
{ for(kk=0; kk<9; kk++)
{ if( tab[i][j][kk][0] != 10 )
{ for(ii=0; ii<3; ii++)
{ for(jj=6;jj<9;jj++)
{ if( (tab[ii][jj][9][0]>10) )
{ if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
{
tab[i][j][kk][1]++;
} } } } } } }
}
if(i>=3 && i<6)
{ if(j<3)
{ for(kk=0; kk<9; kk++)
{ if( tab[i][j][kk][0] != 10 )
{ for(ii=3; ii<6; ii++)
{ for(jj=0;jj<3;jj++)
{ if( (tab[ii][jj][9][0]>10) )
{ if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
{
tab[i][j][kk][1]++;
} } } } } } }
if(j>=3 && j<6)
{ for(kk=0; kk<9; kk++)
{ if( tab[i][j][kk][0] != 10 )
{ for(ii=3; ii<6; ii++)
{ for(jj=3;jj<6;jj++)
{ if( (tab[ii][jj][9][0]>10) )
{ if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
{
tab[i][j][kk][1]++;
} } } } } } }
if(j>=6)
{ for(kk=0; kk<9; kk++)
{ if( tab[i][j][kk][0] != 10 )
{ for(ii=3; ii<6; ii++)
{ for(jj=6;jj<9;jj++)
{ if( (tab[ii][jj][9][0]>10) )
{ if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
{
tab[i][j][kk][1]++;
} } } } } } }
}
if(i>=6)
{ if(j<3)
{ for(kk=0; kk<9; kk++)
{ if( tab[i][j][kk][0] != 10 )
{ for(ii=6; ii<9; ii++)
{ for(jj=0;jj<3;jj++)
{ if( (tab[ii][jj][9][0]>10) )
{ if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
{
tab[i][j][kk][1]++;
} } } } } } }
if(j>=3 && j<6) //bloc test.
{ for(kk=0; kk<9; kk++)
{ if( tab[i][j][kk][0] != 10 )
{ for(ii=6; ii<9; ii++)
{ for(jj=3; jj<6; jj++)
{ if( (tab[ii][jj][9][0]>10) )
{ if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
{
tab[i][j][kk][1]++;
} } } } } } }
if(j>=6)
{ for(kk=0; kk<9; kk++)
{ if( tab[i][j][kk][0] != 10 )
{ for(ii=6; ii<9; ii++)
{ for(jj=6;jj<9;jj++)
{ if( (tab[ii][jj][9][0]>10) )
{ if(tab[i][j][kk][0] == tab[ii][jj][kk][0])
{
tab[i][j][kk][1]++;
} } } } } } }
}
}
}
}//fin du comptage des possibilités des blocs.
for(i=0; i<9; i++) // Affectation de la valeur mise en évidence par le comptage.
{ for(j=0; j<9; j++)
{ if(tab[i][j][9][0] > 9)
{ for(kk=0; kk<9; kk++)
{ if( (tab[i][j][kk][1]==1) && (tab[i][j][kk][0]!=10) )
{
tab[i][j][9][0] = tab[i][j][kk][0];
goto fin;
} } } } }
for(i=0; i<9; i++) // Reinitialise a zero le comptage...
{ for(j=0; j<9; j++)
{ for(kk=0; kk<10; kk++)
{ tab[i][j][kk][1]=0;
} } }
for(i=0; i<9; i++) // 2eme comptage. Cette fois, au niveau des lignes.
{ for(j=0; j<9; j++)
{ if(tab[i][j][9][0] > 9)
{ for(ii=0; ii<9; ii++)
{ if(tab[ii][j][9][0] > 9)
{ for(kk=0; kk<9; kk++)
{ if( tab[i][j][kk][0] < 10 )
{
if(tab[i][j][kk][0] == tab[ii][j][kk][0])
{
tab[i][j][kk][1]++;
} } } } } } } }
for(i=0; i<9; i++) // 2eme affectation des valeurs trouvées.
{ for(j=0; j<9; j++)
{ if(tab[i][j][9][0] > 9)
{ for(kk=0; kk<9; kk++)
{ if( (tab[i][j][kk][1]==1) && (tab[i][j][kk][0]!=10) )
{
tab[i][j][9][0] = tab[i][j][kk][0];
goto fin;
} } } } }
for(i=0; i<9; i++) // 2eme réinitialisation des compteurs
{ for(j=0; j<9; j++)
{ for(kk=0; kk<9; kk++)
{ tab[i][j][kk][1]=0;
} } }
for(i=0; i<9; i++) // 3eme comptage. Au niveau des colonnes.
{ for(j=0; j<9; j++)
{ if(tab[i][j][9][0] > 9)
{ for(jj=0; jj<9; jj++)
{ if( tab[i][jj][9][0] > 9 )
{ for(kk=0; kk<9; kk++)
{ if( tab[i][j][kk][0] != 10 )
{
if(tab[i][j][kk][0] == tab[i][jj][kk][0])
{
tab[i][j][kk][1]++;
}
} } } } } } }
for(i=0; i<9; i++) // 3eme affectation des valeurs. La réinitialisation aura lieu au debut
{ for(j=0; j<9; j++) // de la boucle generale.
{ if(tab[i][j][9][0] > 9)
{ for(kk=0; kk<9; kk++)
{ if( (tab[i][j][kk][1]==1) && (tab[i][j][kk][0]!=10) )
{
tab[i][j][9][0] = tab[i][j][kk][0];
goto fin;
} } } } }
for(i=0; i<9; i++)
{ for(j=0; j<9; j++)
{
compteur = 0;
for(kk=0; kk<9; kk++)
{
if(tab[i][j][kk][0] != 10)
{
temp[99].val = tab[i][j][kk][0];
temp[99].x =i;
temp[99].y =j;
compteur++;
}
}
if(compteur == 1)
{
tab[temp[99].x][temp[99].y][9][0]= temp[99].val;
goto fin;
}
}
}
fin:
count=0;
for (i=0;i<9;i++) // compte le nombre de possibilités restantes.
{ for(j=0;j<9;j++)
{ if(tab[i][j][9][0]>=10)
{
count++;
} } }
/////////////////////////////////
if(tempo==count)
{ for(i=0; i<9; i++)
{ for(j=0; j<9; j++)
{ if(tab[i][j][9][0]>9)
{ for(kk=0; kk<9; kk++)
{ if(tab[i][j][kk][1]==2)
{
if(bloquer>=1)
{
for(bl=0; bl<bloquer; bl++)
{
if(i!= temp[bl].x && j!=temp[bl].y && kk!= temp[bl].k)
{
tab[i][j][9][0]=tab[i][j][kk][0];
temp[bloquer].x=i;
temp[bloquer].y=j;
temp[bloquer].k=kk;
bloquer++;
goto fin2;
}
}
}
else
{
tab[i][j][9][0]=tab[i][j][kk][0];
temp[bloquer].x= i;
temp[bloquer].y= j;
temp[bloquer].k= kk;
// for(kk=0; kk<9; kk++)printf("\n\ntab[%d][%d][%d][%d]= %d\n\n",i,j,kk,0,tab[i][j][kk][0]);
bloquer++;
// printf("\a");
// system("pause");
goto fin2;
}
} } } } } }
if(tempo == count && bloquer>=1)
{
if(count==0) goto fin2;
retry++;
// printf("\a");
goto debut;
}
tempo=count;
fin2:
//printf("\n>>%d<<\n",count);
if(count==0)
{
printf("\n");
affiche(0,0,tab, 0);
system("pause");
return 0;
}
/////////////////////////////////
//printf("continuer ? (o/n)");
//rep=fgetc(stdin);
if(rep=='n') return 0;
if(rep=='a')
{
point=bouger(tab, 0, 0);
if(point.test==0)
{
tab[point.x][point.y][9][0]=point.val;
}
}
if(rep=='r')
{
retry++;
goto debut;
}
}
}
fin(char *pMsg)
{
puts(pMsg);
}
Conclusion
compilé sous visual c ++ mais devrait fonctionner sur les autres compilateurs.
Merci pour vos commentaires et critiques. Votre aide pour perfectionner ce programme est la bienvenue.
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Résolution du jeu sudoku [ par marik7335 ]
Salut tout le monde,J'aimerais avoir quelques quelques pistes pour pouvoir résoudre le jeu du sudoku en C. J'ai du mal à établir l'algo
Sudoku [ par MasterShadows ]
Bonjour à tous et à toutes,alors voilà, je dois coder en C pour Linux un petit programme permettant de générer une grille de
Creation d'une grille en SDL [ par lamiae89 ]
Salut; Je suis en train de faire un jeu de Kakuro en langage c , je me pose encore quelques questions de conception de la grille , faut-il creer une
Projet d'été sur SUDOKU!! Aidez-nous s'il vous plait... [ par Naruttibayo ]
Au préalable, nous tenons à remercier tous ceux qui contribuerons à notre projet...On nous demande d'écrire un programme C qui permet de Générer des G
Probleme avec backtracking [ par sda2 ]
Bonsoir à tous, Je vous expose vite mon probleme, je souhaite realiser un sudoku (9x9), cependant il ne resoud que les sudokus facile, moyen et lui re
Probleme backtracking [ par sda2 ]
Bonsoir à tous, Je vous expose vite mon probleme, je souhaite realiser un sudoku (9x9), cependant il ne resoud que les sudokus facile, moyen et lui r
[A SUPPRIMER]Algorithmes de résolution sudoku en Java [ par janicp ]
Bonjour, J'ai commencer un cours en programmation Java par correspondance, j'ai de la difficulté à commencer, vous pouvez m'éclairer S.V.P. Je dois
Jeu sur console [ par hdx75 ]
Bonjour je suis en seconde et je débute en C Je dois faire un jeu sur console sous forme de tableau 10x10 du genre jewels où il faut faire des groupes
Probleme avec un sudoku [ par thomasvd ]
Bonjour!je dois réaliser un jeu sudoku et je rencontre quelques problemes dont un qui m'embette particulierement et j'aimerais bien que quelqu'un m'or
menu de jeu [ par crousti42 ]
Bonour tout le monde !!!Je souhaiterais pouvoir créer un menu semblable à ceux que l'on trouve dans les jeux d'aujourd'hui (nouvelle partie, charger p
|
Derniers Blogs
IMAGINE CUP 2012, MAKE A SIGN EN FINALEIMAGINE CUP 2012, MAKE A SIGN EN FINALE par junarnoalg
Voilà qui est fait, la nouvelle est officielle ! L'équipe belge "Make a Sign" va au pays des kangourous défendre son projet dans la catégorie Software Design. http://www.imaginecup.com/CompetitionsContent/Competition/WorldwideFinalists.aspx V...
Cliquez pour lire la suite de l'article par junarnoalg KINECT 1.5 IS OUT !KINECT 1.5 IS OUT ! par Vko
La version 1.5 du Kinect For Microsoft vient tout juste de sortir ! Plein de nouveautés: Tracking de squelette en Near Mode Détection en position assise Détection faciale avec un SDK dédié Documentation et des guideline (enfin) Un out...
Cliquez pour lire la suite de l'article par Vko LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) LES ACTUALITéS DE LA SEMAINE SUR C2I.FR (14 MAI - 20 MAI) par richardc
Mise à jour des Web API du 14 Mai
Réservez dès maintenant votre journée du 20 juin pour le Windows Azure Dev Camp 2012 à Paris
Mise à jour de Team Foundation Service
MechCommander 2 sur Windows 8
Entity Framework 5 Release Candidate e...
Cliquez pour lire la suite de l'article par richardc REACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITERREACTIVE EXTENSIONS : CONSOMMER DES SERVICES AVEC RX PARTIE 3, LES PIèGES à éVITER par Groc
Une mauvaise utilisation de rx lors de l'écriture d'une couche d'accès à des services peut conduire à des cas embarassants avec des erreurs mal gérées, des appels qui ne partent lorsqu'ils le devraient, et même des résultats incorrects . le tout nuis...
Cliquez pour lire la suite de l'article par Groc SHAREPOINT BLOG SITE, PROBLèME D'ARCHIVESSHAREPOINT BLOG SITE, PROBLèME D'ARCHIVES par junarnoalg
Dernièrement, nous avons migré le site
myTIC
vers un nouveau serveur SharePoint 2010. Dans les contenus que nous vouloins récupérer, nous avions un certain nombre de blogs.
Nous avons utilisé les commandes Power...
Cliquez pour lire la suite de l'article par junarnoalg
Forum
RE : SAC A DOS RE : SAC A DOS par hadjkaddour
Cliquez pour lire la suite par hadjkaddour
Logiciels
sDEVIS-FACTURES vlPRO (8.1.0.3)SDEVIS-FACTURES VLPRO (8.1.0.3)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO 974 Application Server (12.2.4.6)974 APPLICATION SERVER (12.2.4.6)Développez de puissantes applications dans un environnement de 'cloud computing', clusterisé, séc... Cliquez pour télécharger 974 Application Server vPicture (1.4.2.1)VPICTURE (1.4.2.1)Avec vPicture, hébergez vos images facilement et rapidement.
vPicture est un utilitaire simple, ... Cliquez pour télécharger vPicture Easy-Planning (2.2.1.6)EASY-PLANNING (2.2.1.6)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté au... Cliquez pour télécharger Easy-Planning COM-BACKUP (2.0)COM-BACKUP (2.0)
COM-BACKUP est un logiciel de sauvegarde qui permet de planifier les sauvegardes de vos dossiers ...
Cliquez pour télécharger COM-BACKUP
|