Merge branch 'master' of https://gitlab.isima.fr/audorival/gomoku
This commit is contained in:
@@ -3,50 +3,52 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class GomokuAI extends Player{
|
||||
|
||||
public class GomokuAI extends Player {
|
||||
|
||||
//------------------Constructors--------------------------
|
||||
// ------------------Constructors--------------------------
|
||||
|
||||
/**
|
||||
* The constructor of the GomokuAI.
|
||||
* @param name The name of the player.
|
||||
* @param color The color of the player.
|
||||
*/
|
||||
public GomokuAI(String name,Color color){
|
||||
super(name,color);
|
||||
public GomokuAI(String name, Color color) {
|
||||
super(name, color);
|
||||
}
|
||||
|
||||
/**
|
||||
* This class is an extends of the class Player, this allows the GomokuAI to choose his move.
|
||||
*/
|
||||
* This class is an extends of the class Player, this allows the GomokuAI to
|
||||
* choose his move.
|
||||
*/
|
||||
|
||||
/** The random initialization */
|
||||
Random random = new Random();
|
||||
/** The difficulty of the GomokuAI */
|
||||
int difficulty = 0;
|
||||
|
||||
//------------------Methods--------------------------
|
||||
// ------------------Methods--------------------------
|
||||
/**
|
||||
* Return the coordinate of the move played by the Gomoku AI.
|
||||
* @param board The actual Gomoku board.
|
||||
* @return The Cell of the move played.
|
||||
*/
|
||||
public GomokuCell chooseMove(GomokuBoard board){
|
||||
|
||||
* Return the coordinate of the move played by the Gomoku AI.
|
||||
*
|
||||
* @param board The actual Gomoku board.
|
||||
* @return The Cell of the move played.
|
||||
*/
|
||||
@Override
|
||||
public GomokuCell chooseMove(GomokuBoard board) {
|
||||
|
||||
List<GomokuCell> playableCell = board.getPlayableCells();
|
||||
GomokuCell playCell;
|
||||
int x=0,y=0;
|
||||
|
||||
int x = 0, y = 0;
|
||||
|
||||
switch (difficulty) {
|
||||
case 0:
|
||||
playCell = playableCell.get(random.nextInt(playableCell.size()));
|
||||
break;
|
||||
case 1:
|
||||
Map<GomokuCell, Integer> map = GetCellPoint(board);
|
||||
int max=0;
|
||||
int max = 0;
|
||||
for (Map.Entry<GomokuCell, Integer> entry : map.entrySet()) {
|
||||
if(entry.getValue() > max){
|
||||
if (entry.getValue() > max) {
|
||||
max = entry.getValue();
|
||||
playCell = entry.getKey();
|
||||
}
|
||||
@@ -55,25 +57,25 @@ public class GomokuAI extends Player{
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
System.out.println("L'IA à choisi : "+ x+", "+ y);
|
||||
System.out.println("L'IA à choisi : " + x + ", " + y);
|
||||
|
||||
|
||||
return playCell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Map of all Cell playable, and their point.
|
||||
* @param board The actual Gomoku board.
|
||||
* @return the Map of all Cell playable, and their point.
|
||||
*/
|
||||
public Map<GomokuCell, Integer> GetCellPoint(GomokuBoard board){
|
||||
|
||||
* Return a Map of all Cell playable, and their point.
|
||||
*
|
||||
* @param board The actual Gomoku board.
|
||||
* @return the Map of all Cell playable, and their point.
|
||||
*/
|
||||
public Map<GomokuCell, Integer> GetCellPoint(GomokuBoard board) {
|
||||
|
||||
List<GomokuCell> playableCell = board.getPlayableCells();
|
||||
Map<GomokuCell, Integer> map = new HashMap<>();
|
||||
|
||||
for (GomokuCell gomokuCell : playableCell) {
|
||||
|
||||
switch(this.color){
|
||||
switch (this.color) {
|
||||
|
||||
case Color.WHITE:
|
||||
gomokuCell.setState(Color.BLACK);
|
||||
@@ -93,6 +95,4 @@ public class GomokuAI extends Player{
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user