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
88930734
Commit
88930734
authored
May 01, 2020
by
TRAN Alain
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
1206c04c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
126 additions
and
0 deletions
+126
-0
AlgoRechercheMinMax_9x9.java
src/tictactoecodingame/AlgoRechercheMinMax_9x9.java
+126
-0
No files found.
src/tictactoecodingame/AlgoRechercheMinMax_9x9.java
0 → 100644
View file @
88930734
/*
* 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_9x9
extends
AlgoRecherche
{
Joueur
humain
;
Joueur
ordi
;
public
AlgoRechercheMinMax_9x9
(
Joueur
_ordi1
,
Joueur
_joueur1
){
ordi
=
_ordi1
;
humain
=
_joueur1
;
}
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
(
ordi
);
for
(
int
i
=
0
;
i
<
coups
.
size
();
i
++){
_plateau
.
sauvegardePosition
(
0
);
_plateau
.
joueCoup
(
coups
.
get
(
i
));
// System.out.println(_plateau);
// System.out.println("coup initial");
double
score
=
minimax
(
_plateau
,
humain
,
1
,
false
);
//False car l'ordi a déjà placé son premier coup
Coup
coup_provisoire
=
coups
.
get
(
i
);
_plateau
.
restaurePosition
(
0
);
// System.out.println("annule coup initial");
// System.out.println(_plateau);
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
.
partieNulle
()){
// System.out.println("Partie nulle");
return
0
;
}
else
{
Joueur
gagnant
=
_plateau
.
vainqueur
();
//Il faudrait connaitre le vainqueur
// System.out.println("gagnant " + gagnant);
if
(
gagnant
!=
null
){
int
resultat
=
gagnant
.
getIdJoueur
();
// System.out.println("resultat " + resultat);
return
scores
[
resultat
];}
else
{
// return 0;
}
}
}
if
(
profondeur
>
1
){
return
scores
[
1
];
}
if
(
isMaximizing
)
{
//ordi qui joue
double
inf
=
Double
.
POSITIVE_INFINITY
;
double
bestScore
=
-
1
*
inf
;
ArrayList
<
Coup
>
coups
=
_plateau
.
getListeCoups
(
ordi
);
for
(
int
i
=
0
;
i
<
coups
.
size
();
i
++){
_plateau
.
sauvegardePosition
(
profondeur
);
_plateau
.
joueCoup
(
coups
.
get
(
i
));
// System.out.println(_plateau);
// System.out.println("coup ordi placé " + coups.get(i));
// System.out.println("Gagnant provisoire " + _plateau.vainqueur());
double
score
=
minimax
(
_plateau
,
humain
,
profondeur
+
1
,
false
);
// System.out.println("dernier coup ordi " + _plateau.getDernierCoup());
_plateau
.
restaurePosition
(
profondeur
);
// System.out.println(_plateau);
// System.out.println("coup ordi annulé");
// System.out.println("dernier coup ordi " + _plateau.getDernierCoup());
bestScore
=
max
(
score
,
bestScore
);
}
return
bestScore
;
}
else
{
// Humain ou autre ordi qui joue
double
inf
=
Double
.
POSITIVE_INFINITY
;
double
bestScore
=
inf
;
ArrayList
<
Coup
>
coups
=
_plateau
.
getListeCoups
(
humain
);
for
(
int
i
=
0
;
i
<
coups
.
size
();
i
++){
_plateau
.
sauvegardePosition
(
profondeur
);
_plateau
.
joueCoup
(
coups
.
get
(
i
));
// System.out.println(_plateau);
// System.out.println("coup humain placé " + coups.get(i));
// System.out.println("Gagnant provisoire " + _plateau.vainqueur());
double
score
=
minimax
(
_plateau
,
ordi
,
profondeur
+
1
,
true
);
// System.out.println("dernier coup humain " + _plateau.getDernierCoup());
// _plateau.annuleDernierCoup();
_plateau
.
restaurePosition
(
profondeur
);
// System.out.println(_plateau);
// System.out.println("coup humain annulé");
// System.out.println("dernier coup humain " + _plateau.getDernierCoup());
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