diff --git a/src/othello/Main.java b/src/othello/Main.java index 04b21be..25f5d87 100644 --- a/src/othello/Main.java +++ b/src/othello/Main.java @@ -13,15 +13,15 @@ public class Main { AbstractPlayer p2 = new RandomPlayer(); AbstractPlayer[][] board = initialize(p1, p2); State game = new State(board, p1, p2); - // board[1][5]=game.getCurrentPlayer(); + System.out.println("joueur 1: " + p1); + System.out.println("joueur 2: " + p2); while(!game.isOver()) { AbstractPlayer player = game.getCurrentPlayer(); ArrayList> moves = game.getMove(player); - game.toString(); - player.play(moves); + System.out.println(game.toString()); + game.play(player.play(moves)); } - // ArrayList> moves = game.getMove(game.getCurrentPlayer()); - // System.out.println(moves.toString()); + System.out.println("C'est " + game.getWinner() + " qui a gagné"); } public static AbstractPlayer[][] initialize(AbstractPlayer p1, AbstractPlayer p2){ diff --git a/src/othello/State.java b/src/othello/State.java index bca19ae..e855be2 100644 --- a/src/othello/State.java +++ b/src/othello/State.java @@ -63,9 +63,18 @@ public class State { } public int getScore(AbstractPlayer player) { - return currentPlayer == player1 ? n1/(n1+n2) : n2/(n2+n1); + return player == player1 ? n1/(n1+n2) : n2/(n2+n1); } - + + public AbstractPlayer getWinner() { + int scoreP1 = getScore(player1), scoreP2 = getScore(player2); + if(scoreP1 > scoreP2) + return player1; + else if(scoreP2 > scoreP1) + return player2; + return null; + } + public State play(Pair pair) { State copy = this.copy(); copy.board[pair.getLeft().getX()][pair.getLeft().getY()] = copy.getCurrentPlayer(); @@ -115,7 +124,20 @@ public class State { */ @Override public String toString() { - return null; + StringBuilder str = new StringBuilder(); + for (int y = 0; y < board.length; y++) { + for (int x = 0; x < board.length; x++) { + if(board[y][x] == player1) + str.append("O"); + else if(board[y][x] == player2) + str.append("X"); + else + str.append("."); + str.append(" "); + } + str.append("\r\n"); + } + return str.toString(); } }