Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Projet_info
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TRAN Alain
Projet_info
Commits
4dc02de6
Commit
4dc02de6
authored
Apr 20, 2020
by
TRAN Alain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
7e992b95
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
0 deletions
+83
-0
AlgoRechercheMinMax.java
src/AlgoRechercheminmax/AlgoRechercheMinMax.java
+83
-0
No files found.
src/AlgoRechercheminmax/AlgoRechercheMinMax.java
0 → 100644
View file @
4dc02de6
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package
tictactoecodingame
;
import
static
java
.
lang
.
Math
.
max
;
/**
*
* @author Alain
*/
public
class
AlgoRechercheMinMax
{
String
[][]
grille
=
{{
""
,
""
,
""
},{
""
,
""
,
""
},{
""
,
""
,
""
}};
int
[]
scores
=
{
1
,-
1
,
0
};
public
Coup
meilleur_coup_minmax
(){
double
inf
=
Double
.
POSITIVE_INFINITY
;
double
bestScore
=
-
1
*
inf
;
int
[]
meilleur_coup
=
new
int
[
2
]
;
for
(
int
i
=
0
;
i
<
3
;
i
++){
for
(
int
j
=
0
;
j
<
3
;
j
++){
if
(
grille
[
i
][
j
]
==
""
)
{
grille
[
i
][
j
]
=
"X"
;}
int
score
=
minimax
(
grille
,
0
,
false
);
grille
[
i
][
j
]
=
""
;
if
(
score
>
bestScore
){
bestScore
=
score
;
meilleur_coup
[
0
]
=
i
;
meilleur_coup
[
1
]
=
j
;
}
}
}
grille
[
meilleur_coup
[
0
]][
meilleur_coup
[
1
]]
=
"X"
;
// changer le tour du joueur ?
}
public
int
minimax
(
grille
,
profondeur
,
isMaximizing
){
Joueur
gagnant
=
grille
.
vainqueur
();
//Il faudrait connaitre le vainqueur
int
resultat
=
gagnant
.
getIdJoueur
();
if
(
resultat
!==
null
)
{
return
scores
[
resultat
];
}
if
(
isMaximizing
)
{
double
inf
=
Double
.
POSITIVE_INFINITY
;
double
bestScore
=
-
1
*
inf
;
for
(
int
i
=
0
;
i
<
3
;
i
++){
for
(
int
j
=
0
;
j
<
3
;
j
++){
if
(
grille
[
i
][
j
]
==
""
)
{
grille
[
i
][
j
]
=
"X"
;
double
score
=
minimax
(
grille
,
profondeur
+
1
,
false
);
grille
[
i
][
j
]
=
""
;
bestScore
=
max
(
score
,
bestScore
);
}
}
}
return
bestScore
;
}
else
{
double
inf
=
Double
.
POSITIVE_INFINITY
;
double
bestScore
=
inf
;
for
(
int
i
=
0
;
i
<
3
;
i
++){
for
(
int
j
=
0
;
j
<
3
;
j
++){
if
(
grille
[
i
][
j
]
==
""
)
{
grille
[
i
][
j
]
=
"X"
;
double
score
=
minimax
(
grille
,
profondeur
+
1
,
true
);
grille
[
i
][
j
]
=
""
;
bestScore
=
min
(
score
,
bestScore
);
}
}
}
return
bestScore
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment