2021-01-27 12:24:17 +01:00
|
|
|
package othello;
|
|
|
|
|
2021-02-25 13:57:49 +01:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
|
2021-02-24 11:52:16 +01:00
|
|
|
import othello.players.AlphaBetaPlayer;
|
2021-02-26 11:54:26 +01:00
|
|
|
import othello.players.NegamaxPlayer;
|
2021-02-16 13:41:20 +01:00
|
|
|
import othello.players.Player;
|
2021-02-12 09:18:03 +01:00
|
|
|
|
2021-01-27 12:24:17 +01:00
|
|
|
public class Main {
|
|
|
|
|
2021-02-20 18:54:38 +01:00
|
|
|
|
2021-02-26 11:54:26 +01:00
|
|
|
public static void main(String[] args) {
|
|
|
|
Player[] players = extractArgs(args);
|
|
|
|
Player p1 = players[0];
|
|
|
|
Player p2 = players[1];
|
|
|
|
Player[][] board = initializeBoard(p1, p2);
|
2021-02-10 11:21:33 +01:00
|
|
|
State game = new State(board, p1, p2);
|
2021-02-12 09:38:18 +01:00
|
|
|
System.out.println("joueur 1: " + p1);
|
|
|
|
System.out.println("joueur 2: " + p2);
|
2021-02-12 09:18:03 +01:00
|
|
|
while(!game.isOver()) {
|
2021-02-16 13:41:20 +01:00
|
|
|
Player player = game.getCurrentPlayer();
|
2021-02-12 09:38:18 +01:00
|
|
|
System.out.println(game.toString());
|
2021-02-22 21:23:03 +01:00
|
|
|
game = game.play(player.play(game));
|
2021-02-12 09:18:03 +01:00
|
|
|
}
|
2021-02-26 11:54:26 +01:00
|
|
|
endGame(game);
|
2021-02-24 11:27:50 +01:00
|
|
|
|
2021-01-27 12:24:17 +01:00
|
|
|
}
|
2021-02-26 11:54:26 +01:00
|
|
|
|
|
|
|
public static Player[] extractArgs(String[] args) {
|
|
|
|
Player p1;
|
|
|
|
Player p2;
|
|
|
|
int depthP1 = 4;
|
|
|
|
int depthP2 = 4;
|
|
|
|
boolean useAlphaBeta = false;
|
|
|
|
try {
|
|
|
|
if(args.length >= 3) { // les paramètres > 3 sont ignorés
|
|
|
|
depthP1 = Integer.parseInt(args[0]);
|
|
|
|
depthP2 = Integer.parseInt(args[1]);
|
|
|
|
useAlphaBeta = Boolean.parseBoolean(args[2]);
|
|
|
|
}
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
System.out.println("Les arguments de lancement ne pas corrects (pas des nombres entiers)");
|
|
|
|
System.out.println("Utilisation des paramètres par défaut ( 4 4 true )");
|
|
|
|
} finally {
|
|
|
|
if(useAlphaBeta) {
|
|
|
|
p1 = new AlphaBetaPlayer(depthP1);
|
|
|
|
p2 = new AlphaBetaPlayer(depthP2);
|
|
|
|
} else {
|
|
|
|
p1 = new NegamaxPlayer(depthP1);
|
|
|
|
p2 = new NegamaxPlayer(depthP2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new Player[]{p1, p2};
|
|
|
|
}
|
2021-01-27 12:24:17 +01:00
|
|
|
|
2021-02-26 11:54:26 +01:00
|
|
|
public static Player[][] initializeBoard(Player p1, Player p2){
|
2021-02-16 13:41:20 +01:00
|
|
|
Player[][] board = new Player[7][7];
|
2021-01-27 12:24:17 +01:00
|
|
|
board[0][0] = p2;
|
|
|
|
board[0][6] = p1;
|
|
|
|
board[6][0] = p1;
|
|
|
|
board[6][6] = p2;
|
|
|
|
return board;
|
|
|
|
}
|
2021-02-26 11:54:26 +01:00
|
|
|
|
|
|
|
public static void endGame(State game) {
|
|
|
|
System.out.println(game.toString());
|
|
|
|
System.out.println(game.getN1()+" "+ game.getN2());
|
|
|
|
System.out.println(game.getWinner() + " a gagné la partie");
|
|
|
|
System.out.println("Score joueur 1 -> " + game.getN1());
|
|
|
|
System.out.println("Score joueur 2 -> "+ game.getN2());
|
|
|
|
}
|
|
|
|
|
2021-01-27 12:24:17 +01:00
|
|
|
}
|