fixed bugs and crash

This commit is contained in:
Quentin Legot 2021-02-12 09:57:05 +01:00
parent 10fae688ad
commit a62e3f77ba
3 changed files with 18 additions and 13 deletions

View File

@ -19,7 +19,7 @@ public class Main {
AbstractPlayer player = game.getCurrentPlayer(); AbstractPlayer player = game.getCurrentPlayer();
ArrayList<Pair<Point, Point>> moves = game.getMove(player); ArrayList<Pair<Point, Point>> moves = game.getMove(player);
System.out.println(game.toString()); System.out.println(game.toString());
game.play(player.play(moves)); game = game.play(player.play(moves));
} }
System.out.println("C'est " + game.getWinner() + " qui a gagné"); System.out.println("C'est " + game.getWinner() + " qui a gagné");
} }

View File

@ -13,9 +13,11 @@ public class Point {
public boolean isJump(Point other) { public boolean isJump(Point other) {
return Math.pow(other.x - this.x, 2) + Math.pow(other.y - this.y, 2) == 4; return Math.pow(other.x - this.x, 2) + Math.pow(other.y - this.y, 2) == 4;
} }
public int getX(){ public int getX(){
return x; return x;
} }
public int getY(){ public int getY(){
return y; return y;
} }

View File

@ -42,15 +42,17 @@ public class State {
// Recherche autour du pion du joueur courant // Recherche autour du pion du joueur courant
for (int deltaY = -1; deltaY < 2; deltaY++) { for (int deltaY = -1; deltaY < 2; deltaY++) {
for (int deltaX = -1; deltaX < 2; deltaX++) { for (int deltaX = -1; deltaX < 2; deltaX++) {
// La position du pion trouv<EFBFBD> est exclue // La position du pion trouvée est exclue
if (deltaY != 0 && deltaX != 0) { if (deltaY != 0 && deltaX != 0) {
// Si une place libre est trouv<EFBFBD>e elle est ajout<EFBFBD>e à la liste des coups // Si une place libre est trouvée elle est ajoutée à la liste des coups
try { try {
if (this.board[y+deltaY][x+deltaX] == null) { if (this.board[y+deltaY][x+deltaX] == null) {
moves.add(new Pair<Point, Point>(new Point(y, x), new Point(y+deltaY, x+deltaX))); moves.add(new Pair<Point, Point>(new Point(y, x), new Point(y+deltaY, x+deltaX)));
} else { } else {
if(this.board[y+2*deltaY][x+2*deltaX] == null) Point current = new Point(y, x);
moves.add(new Pair<Point, Point>(new Point(y, x), new Point(y+2*deltaY, x+2*deltaX))); Point other = new Point(y + 2 * deltaY, x + 2 * deltaX);
if(this.board[y+2*deltaY][x+2*deltaX] == null && current.isJump(other))
moves.add(new Pair<Point, Point>(current, other));
} }
} catch(ArrayIndexOutOfBoundsException ignored) {} } catch(ArrayIndexOutOfBoundsException ignored) {}
} }
@ -89,7 +91,7 @@ public class State {
} catch (IndexOutOfBoundsException ignored) {} } catch (IndexOutOfBoundsException ignored) {}
} }
} }
if (currentPlayer == player1) if (copy.currentPlayer == player1)
copy.n1 += increment; copy.n1 += increment;
else else
copy.n2 += increment; copy.n2 += increment;
@ -112,6 +114,7 @@ public class State {
copy.board[i][j] = this.board[i][j]; copy.board[i][j] = this.board[i][j];
} }
} }
copy.setCurrentPlayer(this.currentPlayer);
return copy; return copy;
} }