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
f63e7648
Commit
f63e7648
authored
Apr 21, 2020
by
TRAN Alain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
813d3fc1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
AlgoRechercheMinMax.java
src/tictactoecodingame/AlgoRechercheMinMax.java
+82
-0
No files found.
src/tictactoecodingame/AlgoRechercheMinMax.java
0 → 100644
View file @
f63e7648
/*
* 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
;
import
static
java
.
lang
.
Math
.
min
;
import
java.util.ArrayList
;
/**
*
* @author Alain
*/
public
class
AlgoRechercheMinMax
extends
AlgoRecherche
{
String
[][]
grille
=
{{
""
,
""
,
""
},{
""
,
""
,
""
},{
""
,
""
,
""
}};
double
[]
scores
=
{
1
,-
1
,
0
};
@Override
public
Coup
meilleurCoup
(
Plateau
_plateau
,
Joueur
_joueur
,
boolean
ponder
){
double
inf
=
Double
.
POSITIVE_INFINITY
;
double
bestScore
=
-
1
*
inf
;
CoupTicTacToe
meilleur_coup
=
null
;
ArrayList
<
Coup
>
coups
=
_plateau
.
getListeCoups
(
_joueur
);
for
(
int
i
=
0
;
i
<
coups
.
size
();
i
++){
_plateau
.
joueCoup
(
coups
.
get
(
i
));
double
score
=
minimax
(
_plateau
,
_joueur
,
0
,
false
);
Coup
coup_provisoire
=
coups
.
get
(
i
);
_plateau
.
annuleDernierCoup
();
if
(
score
>
bestScore
){
bestScore
=
score
;
meilleur_coup
=
(
CoupTicTacToe
)
coup_provisoire
;
}
}
return
meilleur_coup
;
// changer le tour du joueur ?
}
public
double
minimax
(
Plateau
_plateau
,
Joueur
_joueur
,
int
profondeur
,
boolean
isMaximizing
){
if
(
_plateau
.
partieTerminee
()){
if
(
_plateau
.
partieGagnee
()){
Joueur
gagnant
=
_plateau
.
vainqueur
();
//Il faudrait connaitre le vainqueur
int
resultat
=
gagnant
.
getIdJoueur
();
return
scores
[
resultat
];
}
else
{
return
0
;
}
}
if
(
isMaximizing
)
{
double
inf
=
Double
.
POSITIVE_INFINITY
;
double
bestScore
=
-
1
*
inf
;
ArrayList
<
Coup
>
coups
=
_plateau
.
getListeCoups
(
_joueur
);
for
(
int
i
=
0
;
i
<
3
;
i
++){
_plateau
.
joueCoup
(
coups
.
get
(
i
));
double
score
=
minimax
(
_plateau
,
_joueur
,
profondeur
+
1
,
false
);
_plateau
.
annuleDernierCoup
();
bestScore
=
max
(
score
,
bestScore
);
}
return
bestScore
;
}
else
{
double
inf
=
Double
.
POSITIVE_INFINITY
;
double
bestScore
=
inf
;
ArrayList
<
Coup
>
coups
=
_plateau
.
getListeCoups
(
_joueur
);
for
(
int
i
=
0
;
i
<
coups
.
size
();
i
++){
_plateau
.
joueCoup
(
coups
.
get
(
i
));
double
score
=
minimax
(
_plateau
,
_joueur
,
profondeur
+
1
,
true
);
_plateau
.
annuleDernierCoup
();
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