debut de l'ia 2

This commit is contained in:
Cyprien111
2025-04-14 10:58:41 +02:00
parent dc843729e0
commit 7cd1f5ca3c

View File

@@ -24,7 +24,7 @@ public class GomokuAI extends Player {
/** The random initialization */ /** The random initialization */
Random random = new Random(); Random random = new Random();
/** The difficulty of the GomokuAI */ /** The difficulty of the GomokuAI */
private int difficulty = 1; private int difficulty = 2;
// ------------------Methods-------------------------- // ------------------Methods--------------------------
/** /**
@@ -45,7 +45,7 @@ public class GomokuAI extends Player {
playCell = playableCell.get(random.nextInt(playableCell.size())); playCell = playableCell.get(random.nextInt(playableCell.size()));
break; break;
case 1: case 1:
Map<GomokuCell, Integer> map = GetCellPoint(board); Map<GomokuCell, Integer> map = GetCellPoint(board,this.color);
int max = 0; int max = 0;
for (Map.Entry<GomokuCell, Integer> entry : map.entrySet()) { for (Map.Entry<GomokuCell, Integer> entry : map.entrySet()) {
if (entry.getValue() > max) { if (entry.getValue() > max) {
@@ -53,6 +53,35 @@ public class GomokuAI extends Player {
playCell = entry.getKey(); playCell = entry.getKey();
} }
} }
break;
case 2:
Map<GomokuCell, Integer> map2 = GetCellPoint(board,this.color);
Color other = null;
if(this.color == Color.WHITE) {
other = Color.BLACK;
}
else{
other = Color.WHITE;
}
Map<GomokuCell, Integer> map3 = GetCellPoint(board,other);
int max3 = 0;
int max2 = 0;
for (Map.Entry<GomokuCell, Integer> entry : map2.entrySet()) {
if (entry.getValue() > max2) {
max2 = entry.getValue();
playCell = entry.getKey();
}
}
for (Map.Entry<GomokuCell, Integer> entry : map3.entrySet()) {
if (entry.getValue() > max3) {
max3 = entry.getValue();
playCell = entry.getKey();
}
}
break; break;
default: default:
throw new AssertionError(); throw new AssertionError();
@@ -69,8 +98,8 @@ public class GomokuAI extends Player {
* @param board The actual Gomoku board. * @param board The actual Gomoku board.
* @return the Map of all Cell playable, and their point. * @return the Map of all Cell playable, and their point.
*/ */
public Map<GomokuCell, Integer> GetCellPoint(GomokuBoard board) { public Map<GomokuCell, Integer> GetCellPoint(GomokuBoard board,Color color) {
// Prout
List<GomokuCell> playableCell = board.getPlayableCells(); List<GomokuCell> playableCell = board.getPlayableCells();
Map<GomokuCell, Integer> map = new HashMap<>(); Map<GomokuCell, Integer> map = new HashMap<>();