begin process at 2012 05 27 19:27:16
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Jeux

 > SUDOKU NIVEAU FACIL, MOYEN DIFFICILE (GOOGLE) PAS AU PLUS

SUDOKU NIVEAU FACIL, MOYEN DIFFICILE (GOOGLE) PAS AU PLUS


 Information sur la source

Note :
Aucune note
Catégorie :Jeux Classé sous :sudoku, jeu, résolution, grille, logique Niveau :Débutant Date de création :16/07/2010 Vu / téléchargé :4 207 / 231

Auteur : cool2source

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
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.

 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources de la même categorie

Source avec Zip Source avec une capture JEU DES CARTES par eapaceinfo
PROGRAMME DE JEU DE MPT par KerizGarmm
Source avec Zip Source avec une capture JEUX SERPENT par antho974
Source avec Zip Source avec une capture PENDU EN SDL par Damsou91
Source avec Zip STATE MACHINE MODIFICATION MATH BUCKHAM par billybones79

 Sources en rapport avec celle ci

Source avec Zip JEU PUISSANCE IV par ElendilAranwe
Source avec Zip Source avec une capture SUDOKID, C'EST UN SUDOKU AVEC SEULEMENT 16 CASES. par ndubien
Source avec une capture C-DOKU (C - SUDOKU) par chewney
Source avec Zip SUDOKU LOGIQUE par dave83
Source avec Zip CREATION DE SUDOKU DIFFERENTS NIVEAUX ET RESOLUTION par sullyper

Commentaires et avis

Commentaire de CptPingu le 16/07/2010 09:49:42 administrateur CS

Utilisation peu judicieuse du "goto", fonction monolithique, signature du main incorrect, et j'en passe: Le code n'est vraiment pas propre !

De plus, quelque soit le niveau de difficulté, il est possible de résoudre un soduko par une méthode de "backtracking". Ça prend surement moins de ligne que ce que tu as fais, et c'est bien plus efficace.

Enfin, avant de poster, tu aurais du regarder si ce type de code n'était pas déjà présent. Il y a déjà une bonne vingtaine de sudokus sur ce site !

Tiens, au moins 3 sudokus tout à fait correct:
http://www.cppfrance.com/codes/RESOLUTION-CREATIONS-SUDOKUS_34778.aspx
http://www.cppfrance.com/codes/SUDOKU-AVEC-BACKTRACKING-DANCING-LINK_47910.aspx
http://www.cppfrance.com/codes/SUDOKU-SOLVER_37983.aspx

 Ajouter un commentaire


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&#233;soudre le jeu du sudoku en C. J'ai du mal &#224; &#233;tablir l'algo Sudoku [ par MasterShadows ] Bonjour &#224; tous et &#224; toutes,alors voil&#224;, je dois coder en C pour Linux un petit programme permettant de g&#233;n&#233;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


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,889 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales