Othello/src/othello/State.java

91 lines
1.7 KiB
Java
Raw Normal View History

2021-01-27 11:49:49 +01:00
package othello;
import java.awt.Point;
2021-01-27 13:00:52 +01:00
import java.util.ArrayList;
2021-01-27 11:49:49 +01:00
public class State {
2021-01-27 13:00:52 +01:00
private int[][] board;
private int player1;
private int player2;
private int currentPlayer;
2021-01-27 12:24:17 +01:00
2021-01-27 13:00:52 +01:00
public State(int[][] board, int p1, int p2) {
2021-01-27 12:24:17 +01:00
this.board = board;
this.player1 = p1;
this.player2 = p2;
currentPlayer = p1;
}
2021-01-27 11:49:49 +01:00
public boolean isOver() {
return false;
}
2021-01-27 18:27:28 +01:00
public ArrayList<Point> getMove(int player) {
ArrayList<Point> moves = null;
// Clonage
// Parcours du plateau de jeu
for (int i=0; i<this.board.length;i++) {
for (int j=0; j<this.board.length; j++) {
if (this.board[i][j] == this.currentPlayer) {
// Recherche autour du pion du joueur courant
2021-01-27 18:27:28 +01:00
System.out.println("recherche");
for (int k=-1; k<2;k++) {
for (int l=-1; l<2; l++) {
2021-02-10 09:48:23 +01:00
if (k!=0 || l!=0) {
moves.add(new Point(i+k, j+l));
2021-02-10 09:48:23 +01:00
}
}
}
}
}
}
// Saut
return moves;
2021-01-27 11:49:49 +01:00
}
2021-01-27 18:27:28 +01:00
public int getScore(int player) {
2021-01-27 11:49:49 +01:00
return 0;
}
2021-01-27 13:00:52 +01:00
public State play(int x, int y) {
State copie = this.copie();
copie.board[x][y] = copie.getCurrentPlayer();
copie.switchPlayer();
return copie;
2021-01-27 11:49:49 +01:00
}
2021-01-27 12:24:17 +01:00
2021-01-27 13:00:52 +01:00
public int getCurrentPlayer() {
2021-01-27 12:24:17 +01:00
return currentPlayer;
}
2021-01-27 11:49:49 +01:00
2021-01-27 13:00:52 +01:00
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);
}
}
2021-01-27 11:49:49 +01:00
}