-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine2.cpp
54 lines (41 loc) · 854 Bytes
/
machine2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<iostream>
#include"machine.h"
#include"grille.h"
#include"machine2.h"
using namespace std;
bool Machine2::resoudre(Grille g)
{
return Resoudre(g,0);
}
bool Machine2::Resoudre(Grille g, int e)
{
if (e == 81)
{
solution=new Grille;
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
solution->setCase2(i,j,g.getCase(i,j).getval(),g.getCase(i,j).getmodif());
}
}
return true;
}
else{
int i = e/9;
int j = e%9;
if (g.getCase(i,j).getmodif()==false)
return(Resoudre(g,e+1));
for (int k=1; k <= 9; k++)
{
if (g.valeurvalider(i,j,k))
{
g.setCase1(i,j,k);
cout<<g;
if ( Resoudre(g,e+1) )
return true;
}
}
g.setCase1(i,j,0);
return false;}
}