fonction de clonage des pions pour la méthode getMove

This commit is contained in:
Antonin Boyon 2021-01-27 16:55:50 +01:00
parent 4d1f90bf16
commit c7688feaa3
2 changed files with 34 additions and 7 deletions

View File

@ -4,17 +4,17 @@ public class Main {
public static void main(String[] args) { public static void main(String[] args) {
String p1 = "B", p2 = "R"; int p1 = 1, p2 = 2;
String[][] board = initialize(p1, p2); int[][] board = initialize(p1, p2);
State game = new State(board, p1, p2); State game = new State(board, p1, p2);
while(!game.isOver()) { while(!game.isOver()) {
String player = game.getCurrentPlayer(); int player = game.getCurrentPlayer();
} }
} }
public static String[][] initialize(String p1, String p2){ public static int[][] initialize(int p1, int p2){
String[][] board = new String[7][7]; int[][] board = new int[7][7];
board[0][0] = p2; board[0][0] = p2;
board[0][6] = p1; board[0][6] = p1;
board[6][0] = p1; board[6][0] = p1;

View File

@ -1,5 +1,6 @@
package othello; package othello;
import java.awt.Point;
import java.util.ArrayList; import java.util.ArrayList;
public class State { public class State {
@ -20,8 +21,34 @@ public class State {
return false; return false;
} }
public ArrayList<int[][]> getMove(String player) { public ArrayList<Point> getMove(String player) {
return null; 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
for (int k=-1; k<2;k++) {
for (int l=-1; l<2; l++) {
// 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
if (this.board[i+k][j+l]==0) {
moves.add(new Point(i+k, j+l));
}
}
}
}
}
}
}
// Saut
return moves;
} }
public int getScore(String player) { public int getScore(String player) {