Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Projet_sudoku
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jolibois Simon
Projet_sudoku
Commits
465b8bf8
Commit
465b8bf8
authored
Apr 8, 2021
by
Jolibois Simon
Browse files
Options
Downloads
Patches
Plain Diff
Delete grille.cpp
parent
97d2a1f1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
grille.cpp
+0
-191
0 additions, 191 deletions
grille.cpp
with
0 additions
and
191 deletions
grille.cpp
deleted
100644 → 0
+
0
−
191
View file @
97d2a1f1
#include
"grille.h"
Grille
::
Grille
(
int
vd
)
{
Alloc
();
Init
(
vd
);
}
Grille
::
Grille
(
const
Grille
&
D
)
{
Alloc
();
for
(
int
i
=
0
;
i
<
9
;
i
++
)
for
(
int
j
=
0
;
j
<
9
;
j
++
)
T
[
i
][
j
]
=
D
.
T
[
i
][
j
];
}
Grille
::~
Grille
(){
if
(
T
!=
NULL
)
{
Free
();
T
=
NULL
;
}
}
void
Grille
::
Free
(){
for
(
int
i
=
0
;
i
<
9
;
i
++
)
{
delete
[]
T
[
i
];
}
delete
[]
T
;
}
void
Grille
::
Alloc
(){
T
=
new
int
*
[
9
];
for
(
int
i
=
0
;
i
<
9
;
i
++
)
T
[
i
]
=
new
int
[
9
];
}
void
Grille
::
Print
(){
for
(
int
i
=
0
;
i
<
9
;
i
++
)
{
cout
<<
endl
;
for
(
int
j
=
0
;
j
<
9
;
j
++
)
cout
<<
T
[
i
][
j
]
<<
", "
;
}
cout
<<
endl
<<
endl
;
}
void
Grille
::
Init
(
int
value
){
for
(
int
i
=
0
;
i
<
9
;
i
++
)
for
(
int
j
=
0
;
j
<
9
;
j
++
)
T
[
i
][
j
]
=
value
;
}
void
Grille
::
Set
(
int
x
,
int
y
,
int
value
)
{
/* Modifie la valeur de la grille aux coordonnées (x,y) par value*/
if
(
x
<
9
&&
0
<=
x
&&
0
<=
y
&&
y
<
9
){
if
(
value
<=
9
&&
value
>
0
)
T
[
x
][
y
]
=
value
;
else
cout
<<
"La valeur n'est pas comprise entre 1 et 9."
<<
endl
<<
endl
;
}
else
cout
<<
"Les coordonnées ne sont pas adaptées."
<<
endl
<<
endl
;
}
int
Grille
::
Get
(
int
x
,
int
y
){
return
T
[
x
][
y
];
}
void
Grille
::
EssaiJoueur
(){
/* Appelée quand le joueur à sélectionné à la fois une case et un chiffre
* on vérifie alors avec les règles du sudoku (ligne/colonne/case) que le coup est permit*/
bool
essai
=
true
;
// on vérifie pour la colonne et la ligne
for
(
int
i
=
0
;
i
<
9
;
i
++
){
if
(
chiffre_actif
==
T
[
x_actif
][
i
]
){
essai
=
false
;
cout
<<
"Le chiffre "
<<
chiffre_actif
<<
" est déjà présent dans la ligne."
<<
endl
<<
endl
;
}
else
if
(
chiffre_actif
==
T
[
i
][
y_actif
]){
essai
=
false
;
cout
<<
"Le chiffre "
<<
chiffre_actif
<<
" est déjà présent dans la colonne."
<<
endl
<<
endl
;
}
}
//on vérifie pour la case de 3x3
int
case_3_x
=
floor
(
x_actif
/
3
);
int
case_3_y
=
floor
(
y_actif
/
3
);
for
(
int
i
=
3
*
case_3_x
;
i
<
3
*
case_3_x
+
3
;
i
++
)
for
(
int
j
=
3
*
case_3_y
;
j
<
3
*
case_3_y
+
3
;
j
++
){
if
(
T
[
i
][
j
]
==
chiffre_actif
){
essai
=
false
;
cout
<<
"Le chiffre "
<<
chiffre_actif
<<
" est déjà présent dans le carré 3x3."
<<
endl
<<
endl
;
}
}
// On indique si l'on peut remplir la case ou non et si oui, on le fait
if
(
essai
){
cout
<<
"L'essai est réussi."
<<
endl
<<
endl
;
Set
(
x_actif
,
y_actif
,
chiffre_actif
);
x_actif
=
0
;
y_actif
=
0
;
chiffre_actif
=
0
;
}
else
cout
<<
"L'essai a échoué."
<<
endl
<<
endl
;
}
void
Grille
::
SelectChiffre
(
int
c
){
/* On sélectionne le chiffre que l'on veut mettre par la suite.*/
if
(
1
<=
c
&&
c
<=
9
&&
c
!=
chiffre_actif
){
cout
<<
"Le chiffre selectionné est "
<<
c
<<
"."
<<
endl
<<
endl
;
chiffre_actif
=
c
;
}
else
if
(
c
==
chiffre_actif
){
chiffre_actif
=
0
;
//on déselectionne en tapant une deuxième fois sur le chiffre
}
else
{
cout
<<
"Le chiffre selectionné n'est pas compris entre 1 et 9."
<<
endl
;
}
}
void
Grille
::
SelectCase
(
int
x
,
int
y
){
/* On sélectionne la case que l'on veut mettre par la suite.*/
if
(
0
<=
x
&&
x
<
9
&&
0
<=
y
&&
y
<
9
){
// si on sélectionne la case déja active, on la déselectionne.
if
(
x_actif
==
x
&&
y_actif
==
y
){
x_actif
=
0
;
y_actif
=
0
;
cout
<<
"La case a été désélectionnée."
<<
endl
;
}
// si ce n'est pas le cas, on la sélectionne.
else
{
x_actif
=
x
;
y_actif
=
y
;
cout
<<
"La case sélectionnée est ("
<<
x_actif
<<
","
<<
y_actif
<<
")"
<<
endl
<<
endl
;
}
}
}
bool
Grille
::
TestWin
(){
/* on teste juste que toute la grille soit remplie.*/
for
(
int
i
=
0
;
i
<
9
;
i
++
)
for
(
int
j
=
0
;
j
<
9
;
j
++
)
if
(
Get
(
i
,
j
)
==
0
)
return
false
;
return
true
;
}
Grille
&
Grille
::
operator
=
(
const
Grille
&
D
){
if
(
this
!=
&
D
)
{
// protection autoréférence
Free
();
Alloc
();
for
(
int
i
=
0
;
i
<
9
;
i
++
)
for
(
int
j
=
0
;
j
<
9
;
j
++
)
T
[
i
][
j
]
=
D
.
T
[
i
][
j
];
}
return
*
this
;
}
ostream
&
operator
<<
(
ostream
&
sortie
,
Grille
&
V
)
{
sortie
<<
endl
;
for
(
int
i
=
0
;
i
<
9
;
i
++
)
{
sortie
<<
endl
;
for
(
int
j
=
0
;
j
<
9
;
j
++
)
sortie
<<
V
.
T
[
i
][
j
]
<<
", "
;
}
return
sortie
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment