diff --git a/.gitignore b/.gitignore index 5694dc5..e1dc06c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /bin/ .project -.classpath \ No newline at end of file +.classpath +.metadata/ \ No newline at end of file diff --git a/src/othello/Main.java b/src/othello/Main.java index 06e1046..a26c71b 100644 --- a/src/othello/Main.java +++ b/src/othello/Main.java @@ -17,7 +17,7 @@ public class Main { } int p1 = 1, p2 = 2; int[][] board = initialize(p1, p2); - State game = new State(board, p1, p2); + State game = new State(board, p1, p2,0,0); while(!game.isOver()) { int player = game.getCurrentPlayer(); diff --git a/src/othello/State.java b/src/othello/State.java index 35a9fa6..b5f5eaf 100644 --- a/src/othello/State.java +++ b/src/othello/State.java @@ -9,12 +9,16 @@ public class State { private int player1; private int player2; private int currentPlayer; + private int n1; + private int n2; - public State(int[][] board, int p1, int p2) { + public State(int[][] board, int p1, int p2, int n1,int n2) { this.board = board; this.player1 = p1; this.player2 = p2; currentPlayer = p1; + this.n1 = n1+2; + this.n2 = n2+2; } public boolean isOver() { @@ -33,7 +37,16 @@ public class State { System.out.println("recherche"); for (int k=-1; k<2;k++) { for (int l=-1; l<2; l++) { +<<<<<<< HEAD if (k!=0 || l!=0) { +======= + // La position du pion trouv� est exclue + if (k!=0 || l!=0) { + // Si une place libre est trouv�e elle est ajout� � la liste de coups + System.out.println("close"); + if ( (this.board[i+k][j+l]==0) && (i+k >= 0) && (i+k < 7 ) && (j+l >= 0) && (j+l < 7 ) ) { + System.out.println("jadd"); +>>>>>>> 2263d0614b420497f888985e269e89cd19670bab moves.add(new Point(i+k, j+l)); } @@ -50,16 +63,34 @@ public class State { } public int getScore(int player) { - return 0; + if (currentPlayer == 1) + return n1/(n1+n2); + else + return n2/(n2+n1); } public State play(int x, int y) { State copie = this.copie(); copie.board[x][y] = copie.getCurrentPlayer(); + int increment = 0; + for(int i = -1; i<2;i++){ + for(int z = -1;z<2;z++){ + try { + copie.board[x+i][y+z] = copie.getCurrentPlayer(); + increment+=1; + } catch (Exception e) { + + } + } + } + if (currentPlayer == 1){ + copie.n1 += increment; + }else{ + copie.n2 += increment; + } copie.switchPlayer(); return copie; } - public int getCurrentPlayer() { return currentPlayer; } @@ -69,7 +100,7 @@ public class State { } public State copie () { - State copie = new State (this.board, this.player1, this.player2); + State copie = new State (this.board, this.player1, this.player2,this.n1,this.n2); for (int i=0; i