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
96fdf0b8
Commit
96fdf0b8
authored
Apr 20, 2020
by
MACE Lloyd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Class Util
parent
a035b988
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
0 deletions
+99
-0
Util.java
src/mcts/Util.java
+99
-0
No files found.
src/mcts/Util.java
0 → 100644
View file @
96fdf0b8
/*
* 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
mcts
;
import
java.util.ArrayList
;
import
tictactoecodingame.Coup
;
import
tictactoecodingame.GrilleTicTacToe3x3
;
import
tictactoecodingame.Joueur
;
import
tictactoecodingame.Plateau
;
/**
*
* @author Lloyd
*/
public
class
Util
{
public
static
Coup
getMeilleurCoup
(
Noeud
racine
,
Joueur
joueur
)
{
ArrayList
<
Coup
>
listeCoupsRacine
=
racine
.
getEtat
().
getPlateau
().
getListeCoups
(
joueur
);
/*System.out.println(getMeilleurNoeud(racine)==null);
System.out.println(getMeilleurNoeud(racine).getEtat().getPlateau()==null);
System.out.println(getMeilleurNoeud(racine).getEtat().getPlateau().getListeCoups(joueur)==null);*/
if
(
listeCoupsRacine
.
size
()
==
1
)
{
return
listeCoupsRacine
.
get
(
0
);
}
else
{
ArrayList
<
Coup
>
listeCoupsEnfant
=
getMeilleurNoeud
(
racine
).
getEtat
().
getPlateau
().
getListeCoups
(
joueur
);
for
(
int
i
=
0
;
i
<
listeCoupsRacine
.
size
()
-
1
;
i
++)
{
/*
System.out.println(listeCoupsRacine);
System.out.println(listeCoupsEnfant);
System.out.println(test);
System.out.println(listeCoupsEnfant.get(i));
*/
if
(!
listeCoupsRacine
.
get
(
i
).
equals
(
listeCoupsEnfant
.
get
(
i
)))
{
return
listeCoupsRacine
.
get
(
i
);
}
}
return
listeCoupsRacine
.
get
(
listeCoupsRacine
.
size
()
-
1
);
}
}
public
static
Noeud
getMeilleurNoeud
(
Noeud
racine
)
{
Noeud
meilleurNoeud
=
null
;
double
score
;
double
meilleurScore
=
Integer
.
MIN_VALUE
;
for
(
Noeud
enfant
:
racine
.
getListeEnfant
())
{
score
=
enfant
.
getEtat
().
getNbVictoire
()
/
enfant
.
getEtat
().
getNbVisite
();
if
(
score
>
meilleurScore
)
{
meilleurScore
=
score
;
meilleurNoeud
=
enfant
;
}
}
return
meilleurNoeud
;
}
public
static
Plateau
copyPlateau
(
Plateau
plateau
)
{
Plateau
nouveauPlateau
=
new
GrilleTicTacToe3x3
();
for
(
int
i
=
0
;
i
<
plateau
.
getNbLignes
();
i
++)
{
for
(
int
j
=
0
;
j
<
plateau
.
getNbColonnes
();
j
++)
{
if
(
nouveauPlateau
.
getGrille
()[
i
][
j
]
!=
plateau
.
getGrille
()[
i
][
j
])
{
nouveauPlateau
.
getGrille
()[
i
][
j
]
=
plateau
.
getGrille
()[
i
][
j
];
}
}
}
return
nouveauPlateau
;
}
public
static
ArrayList
<
Coup
>
copyCoupsPossibles
(
Noeud
noeud
,
Joueur
joueur
)
{
ArrayList
<
Coup
>
coupsPossibles
=
new
ArrayList
();
for
(
Coup
coup
:
noeud
.
getEtat
().
getPlateau
().
getListeCoups
(
joueur
))
{
coupsPossibles
.
add
(
coup
);
}
return
coupsPossibles
;
}
public
static
Joueur
getAdversaire
(
Joueur
joueur
)
{
joueur
.
setIdJoueur
(
1
-
joueur
.
getIdJoueur
());
return
joueur
;
}
public
static
void
setAdversaire
(
Joueur
joueur
)
{
joueur
.
setIdJoueur
(
1
-
joueur
.
getIdJoueur
());
}
public
static
int
getNumAdversaire
(
int
numJoueur
)
{
return
1
-
numJoueur
;
}
public
static
void
setNumAdversaire
(
int
numJoueur
)
{
numJoueur
=
1
-
numJoueur
;
}
}
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