diff --git a/src/othello/Main.java b/src/othello/Main.java index 827b346..654946f 100644 --- a/src/othello/Main.java +++ b/src/othello/Main.java @@ -1,14 +1,14 @@ package othello; -import othello.players.NegamaxPlayer; import othello.players.Player; +import othello.players.RandomPlayer; public class Main { public static void main(String[] args) { - Player p1 = new NegamaxPlayer(100); - Player p2 = new NegamaxPlayer(100); + Player p1 = new RandomPlayer(10); + Player p2 = new RandomPlayer(10); Player[][] board = initialize(p1, p2); State game = new State(board, p1, p2); System.out.println("joueur 1: " + p1); diff --git a/src/othello/State.java b/src/othello/State.java index ce1fe27..fc5047d 100644 --- a/src/othello/State.java +++ b/src/othello/State.java @@ -29,10 +29,6 @@ public class State { return n1 == 0 || n2 == 0 || (getMove(player1).isEmpty() && getMove(player2).isEmpty()); } - public Player[][] getBoard(){ - return this.board; - } - public LinkedList> getMove(Player player) { // Pair LinkedList> moves = new LinkedList<>(); @@ -51,7 +47,7 @@ public class State { moves.add(new Pair<>(current, new Point(y + deltaY, x + deltaX))); } Point other = new Point(y + 2 * deltaY, x + 2 * deltaX); - if(this.board[other.getY()][other.getX()] == null && current.isJump(other,getBoard())) + if(this.board[other.getY()][other.getX()] == null && current.isJump(other,this.board)) moves.add(new Pair<>(current, other)); } catch(ArrayIndexOutOfBoundsException ignored) {} } @@ -78,20 +74,23 @@ public class State { public State play(Pair move) { State copy = this.copy(); copy.board[move.getRight().getY()][move.getRight().getX()] = copy.getCurrentPlayer(); + if(move.getLeft().isJump(move.getRight(),copy.board)){ + copy.board[move.getLeft().getY()][move.getLeft().getX()] = null; + } for(int i = -1; i < 2; i++){ for(int z = -1; z < 2; z++){ try { - copy.board[move.getRight().getY() + i][move.getRight().getX() + z] = copy.getCurrentPlayer(); - } catch (IndexOutOfBoundsException ignored) {} + copy.board[move.getRight().getY() + i][move.getRight().getX() + z] = copy.getCurrentPlayer(); + }catch (IndexOutOfBoundsException ignored) {} } } int ni = 0, nj = 0; - for (Player[] players : board) { + for (Player[] players : copy.board) { for (Player player : players) { - if (player == player1) { + if (player == copy.player1) { ni++; } - else if (player == player2) { + else if (player == copy.player2) { nj++; } }