added getScore
This commit is contained in:
parent
3d87d7234f
commit
2263d0614b
@ -9,7 +9,7 @@ public class Main {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int p1 = 1, p2 = 2;
|
int p1 = 1, p2 = 2;
|
||||||
int[][] board = initialize(p1, p2);
|
int[][] board = initialize(p1, p2);
|
||||||
State game = new State(board, p1, p2);
|
State game = new State(board, p1, p2,0,0);
|
||||||
while(!game.isOver()) {
|
while(!game.isOver()) {
|
||||||
int player = game.getCurrentPlayer();
|
int player = game.getCurrentPlayer();
|
||||||
|
|
||||||
|
@ -9,12 +9,16 @@ public class State {
|
|||||||
private int player1;
|
private int player1;
|
||||||
private int player2;
|
private int player2;
|
||||||
private int currentPlayer;
|
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.board = board;
|
||||||
this.player1 = p1;
|
this.player1 = p1;
|
||||||
this.player2 = p2;
|
this.player2 = p2;
|
||||||
currentPlayer = p1;
|
currentPlayer = p1;
|
||||||
|
this.n1 = n1+2;
|
||||||
|
this.n2 = n2+2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOver() {
|
public boolean isOver() {
|
||||||
@ -33,9 +37,9 @@ public class State {
|
|||||||
System.out.println("recherche");
|
System.out.println("recherche");
|
||||||
for (int k=-1; k<2;k++) {
|
for (int k=-1; k<2;k++) {
|
||||||
for (int l=-1; l<2; l++) {
|
for (int l=-1; l<2; l++) {
|
||||||
// La position du pion trouvé est exclue
|
// La position du pion trouv<EFBFBD> est exclue
|
||||||
if (k!=0 || l!=0) {
|
if (k!=0 || l!=0) {
|
||||||
// Si une place libre est trouvée elle est ajouté à la liste de coups
|
// Si une place libre est trouv<EFBFBD>e elle est ajout<EFBFBD> <EFBFBD> la liste de coups
|
||||||
System.out.println("close");
|
System.out.println("close");
|
||||||
if ( (this.board[i+k][j+l]==0) && (i+k >= 0) && (i+k < 7 ) && (j+l >= 0) && (j+l < 7 ) ) {
|
if ( (this.board[i+k][j+l]==0) && (i+k >= 0) && (i+k < 7 ) && (j+l >= 0) && (j+l < 7 ) ) {
|
||||||
System.out.println("jadd");
|
System.out.println("jadd");
|
||||||
@ -55,16 +59,34 @@ public class State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getScore(int player) {
|
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) {
|
public State play(int x, int y) {
|
||||||
State copie = this.copie();
|
State copie = this.copie();
|
||||||
copie.board[x][y] = copie.getCurrentPlayer();
|
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();
|
copie.switchPlayer();
|
||||||
return copie;
|
return copie;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentPlayer() {
|
public int getCurrentPlayer() {
|
||||||
return currentPlayer;
|
return currentPlayer;
|
||||||
}
|
}
|
||||||
@ -74,7 +96,7 @@ public class State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public State copie () {
|
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 i=0; i<this.board.length;i++) {
|
||||||
for (int j=0; j<this.board.length; j++) {
|
for (int j=0; j<this.board.length; j++) {
|
||||||
copie.board[i][j] = this.board[i][j];
|
copie.board[i][j] = this.board[i][j];
|
||||||
|
Loading…
Reference in New Issue
Block a user