fixed bugs and crash
This commit is contained in:
parent
10fae688ad
commit
a62e3f77ba
@ -19,7 +19,7 @@ public class Main {
|
||||
AbstractPlayer player = game.getCurrentPlayer();
|
||||
ArrayList<Pair<Point, Point>> moves = game.getMove(player);
|
||||
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é");
|
||||
}
|
||||
|
@ -13,9 +13,11 @@ public class Point {
|
||||
public boolean isJump(Point other) {
|
||||
return Math.pow(other.x - this.x, 2) + Math.pow(other.y - this.y, 2) == 4;
|
||||
}
|
||||
|
||||
public int getX(){
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY(){
|
||||
return y;
|
||||
}
|
||||
|
@ -42,15 +42,17 @@ public class State {
|
||||
// Recherche autour du pion du joueur courant
|
||||
for (int deltaY = -1; deltaY < 2; deltaY++) {
|
||||
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) {
|
||||
// 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 {
|
||||
if (this.board[y+deltaY][x+deltaX] == null) {
|
||||
moves.add(new Pair<Point, Point>(new Point(y, x), new Point(y+deltaY, x+deltaX)));
|
||||
} else {
|
||||
if(this.board[y+2*deltaY][x+2*deltaX] == null)
|
||||
moves.add(new Pair<Point, Point>(new Point(y, x), new Point(y+2*deltaY, x+2*deltaX)));
|
||||
Point current = new Point(y, x);
|
||||
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) {}
|
||||
}
|
||||
@ -89,7 +91,7 @@ public class State {
|
||||
} catch (IndexOutOfBoundsException ignored) {}
|
||||
}
|
||||
}
|
||||
if (currentPlayer == player1)
|
||||
if (copy.currentPlayer == player1)
|
||||
copy.n1 += increment;
|
||||
else
|
||||
copy.n2 += increment;
|
||||
@ -112,6 +114,7 @@ public class State {
|
||||
copy.board[i][j] = this.board[i][j];
|
||||
}
|
||||
}
|
||||
copy.setCurrentPlayer(this.currentPlayer);
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user