debut d'une ia par point
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class GomokuAI{
|
||||
public class GomokuAI extends Player{
|
||||
|
||||
/**
|
||||
* This class is an extends of the class Player, this allows the GomokuAI to choose his move.
|
||||
@@ -16,7 +18,7 @@ public class GomokuAI{
|
||||
/**
|
||||
* Return the coordinate of the move played by the Gomoku AI.
|
||||
* @param Board The actual Gomoku board.
|
||||
* @return The coordinate of the move played.
|
||||
* @return The Cell of the move played.
|
||||
*/
|
||||
public GomokuCell chooseMove(GomokuBoard board){
|
||||
|
||||
@@ -39,4 +41,37 @@ public class GomokuAI{
|
||||
|
||||
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){
|
||||
|
||||
List<GomokuCell> playableCell = board.getPlayableCells();
|
||||
Map<GomokuCell, Integer> map = new HashMap<>();
|
||||
|
||||
for (GomokuCell gomokuCell : playableCell) {
|
||||
|
||||
switch(this.color){
|
||||
|
||||
case Color.WHITE:
|
||||
gomokuCell.setState(Color.BLACK);
|
||||
break;
|
||||
case Color.BLACK:
|
||||
gomokuCell.setState(Color.WHITE);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
map.put(gomokuCell, board.countMax(board.countAlignedCells(gomokuCell)));
|
||||
|
||||
gomokuCell.setState(Color.NIL);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -75,12 +75,12 @@ public class GomokuBoard{
|
||||
return output;
|
||||
|
||||
}
|
||||
//-------------------Methods-------------------------
|
||||
/**
|
||||
* This method return a Map of number aligned cells.
|
||||
* @param cell A cell.
|
||||
* @return Map of number aligned cells.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This method return a Map of number aligned cells.
|
||||
* @param cell A cell.
|
||||
* @return Map of number aligned cells.
|
||||
*/
|
||||
public Map<Cardinal, Integer> countAlignedCells(GomokuCell cell){
|
||||
|
||||
Map<Cardinal, Integer> map = new HashMap<>();
|
||||
@@ -94,6 +94,23 @@ public class GomokuBoard{
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method return the number max of the aligned Cells.
|
||||
* @param mapColor A map of number aligned cells.
|
||||
* @return int, the number max of the aligned Cells.
|
||||
*/
|
||||
public int countMax(Map<Cardinal, Integer> mapColor){
|
||||
|
||||
Map<Cardinal, Integer> map = new HashMap<>();
|
||||
int max = 0;
|
||||
for (Map.Entry<Cardinal, Integer> entry : map.entrySet()) {
|
||||
if(entry.getValue() > max){
|
||||
max = entry.getValue();
|
||||
}
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
//------------------Overides--------------------------
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
import java.io.Console;
|
||||
import javax.swing.plaf.basic.BasicBorders;
|
||||
|
||||
public class Human extends Player{
|
||||
|
||||
@@ -12,7 +11,7 @@ public class Human extends Player{
|
||||
/**
|
||||
* Return the coordinate of the move played by the player.
|
||||
* @param Board The actual Gomoku board.
|
||||
* @return The coordinate of the move played.
|
||||
* @return The cell of the move played.
|
||||
*/
|
||||
public GomokuCell chooseMove(GomokuBoard board){
|
||||
|
||||
|
||||
@@ -10,15 +10,20 @@ abstract class Player{
|
||||
/** The name of the Player */
|
||||
private String name;
|
||||
|
||||
/** The color of the Player */
|
||||
protected Color color;
|
||||
|
||||
|
||||
//------------------Constructors--------------------------
|
||||
|
||||
/**
|
||||
* The constructor of the Player.
|
||||
* @param name The name of the player.
|
||||
* @param color The color of the player.
|
||||
*/
|
||||
public void Player(String name){
|
||||
public void Player(String name,Color color){
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
//------------------Gets--------------------------
|
||||
@@ -28,7 +33,14 @@ abstract class Player{
|
||||
* @return The name of the player.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
return this.name;
|
||||
}
|
||||
/**
|
||||
* Return the color of the player.
|
||||
* @return The color of the player.
|
||||
*/
|
||||
public Color getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
//------------------Methods--------------------------
|
||||
@@ -36,7 +48,7 @@ abstract class Player{
|
||||
/**
|
||||
* Return the coordinate of the move played by the player.
|
||||
* @param Board The actual Gomoku board.
|
||||
* @return The coordinate of the move played.
|
||||
* @return The cell of the move played.
|
||||
*/
|
||||
public abstract GomokuCell chooseMove(GomokuBoard board);
|
||||
}
|
||||
Reference in New Issue
Block a user