methode play, copie, switchPlayer

This commit is contained in:
Antonin Boyon 2021-01-27 13:00:52 +01:00
parent 3ca489c5bc
commit 4d1f90bf16

View File

@ -1,14 +1,15 @@
package othello; package othello;
import java.util.ArrayList;
public class State { public class State {
private int[][] plateau;
private String[][] board; private int[][] board;
private String player1; private int player1;
private String player2; private int player2;
private String currentPlayer; private int currentPlayer;
public State(String[][] board, String p1, String p2) { public State(int[][] board, int p1, int p2) {
this.board = board; this.board = board;
this.player1 = p1; this.player1 = p1;
this.player2 = p2; this.player2 = p2;
@ -19,20 +20,46 @@ public class State {
return false; return false;
} }
public void getMove(String player) { public ArrayList<int[][]> getMove(String player) {
return null;
} }
public int getScore(String player) { public int getScore(String player) {
return 0; return 0;
} }
public void play(int move) { public State play(int x, int y) {
State copie = this.copie();
copie.board[x][y] = copie.getCurrentPlayer();
copie.switchPlayer();
return copie;
} }
public String getCurrentPlayer() { public int getCurrentPlayer() {
return currentPlayer; return currentPlayer;
} }
public void setCurrentPlayer(int currentPlayer) {
this.currentPlayer = currentPlayer;
}
public State copie () {
State copie = new State (this.board, this.player1, this.player2);
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];
}
}
return copie;
}
public void switchPlayer () {
if (getCurrentPlayer()==this.player1) {
setCurrentPlayer(player2);
}
else {
setCurrentPlayer(player1);
}
}
} }