début methode clonage

This commit is contained in:
Antonin Boyon 2021-02-10 09:49:32 +01:00
commit a28cb1daa5
3 changed files with 38 additions and 6 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/bin/
.project
.classpath
.metadata/

View File

@ -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();

View File

@ -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<EFBFBD> est exclue
if (k!=0 || l!=0) {
// Si une place libre est trouv<EFBFBD>e elle est ajout<EFBFBD> <EFBFBD> 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<this.board.length;i++) {
for (int j=0; j<this.board.length; j++) {
copie.board[i][j] = this.board[i][j];