tout ca tout ca

This commit is contained in:
Victor 2024-06-26 22:49:23 +02:00
parent 7c755a5ce3
commit c0bdf85434
2 changed files with 16 additions and 2 deletions

View File

@ -5,7 +5,7 @@ import java.util.List;
public class Chessboard { public class Chessboard {
public static final int SIZE = 8; public static final int SIZE = 8;
public final int[][] gameBoard = new int[SIZE][SIZE]; private final int[][] gameBoard = new int[SIZE][SIZE];
private final List<Position> queensPosition = new ArrayList<>(); private final List<Position> queensPosition = new ArrayList<>();
private static final String ANSI_RED = "\u001B[31m"; private static final String ANSI_RED = "\u001B[31m";
private static final String ANSI_RESET = "\u001B[0m"; private static final String ANSI_RESET = "\u001B[0m";
@ -14,6 +14,10 @@ public class Chessboard {
// Constructeur vide // Constructeur vide
} }
public int getTile(int x,int y){
return gameBoard[x][y];
}
public void placeQueen(int x, int y) { public void placeQueen(int x, int y) {
if(VerifAccessible(x,y)){ if(VerifAccessible(x,y)){
gameBoard[x][y] = 1; gameBoard[x][y] = 1;

View File

@ -39,6 +39,16 @@ class ChessboardTest {
this.chessboard.placeQueen(1, 2); this.chessboard.placeQueen(1, 2);
this.chessboard.placeQueen(2, 4); this.chessboard.placeQueen(2, 4);
assertEquals(3, this.chessboard.getNumberOfQueen()); assertEquals(3, this.chessboard.getNumberOfQueen());
int cpt=0;
//double test to assure getNumberOfQueen works
for(int i = 0; i< Chessboard.SIZE ;i++){
for(int j = 0; j< Chessboard.SIZE ;j++){
if(this.chessboard.getTile(i, j) == 1){
cpt += 1;
; }
}
}
assertEquals(3, cpt);
} }
@Test @Test
@ -81,7 +91,7 @@ class ChessboardTest {
assertEquals(Chessboard.SIZE, chessboard.getNumberOfQueen(),"Devrait etre egal a "+Chessboard.SIZE); assertEquals(Chessboard.SIZE, chessboard.getNumberOfQueen(),"Devrait etre egal a "+Chessboard.SIZE);
for(int i = 0; i< Chessboard.SIZE ;i++){ for(int i = 0; i< Chessboard.SIZE ;i++){
for(int j = 0; j< Chessboard.SIZE ;j++){ for(int j = 0; j< Chessboard.SIZE ;j++){
if(chessboard.gameBoard[i][j] != 0){ if(chessboard.getTile(i,j) != 0){
chessboard.removeQueen(i,j); chessboard.removeQueen(i,j);
assertTrue(chessboard.VerifAccessible(i,j)); assertTrue(chessboard.VerifAccessible(i,j));
chessboard.placeQueen(i,j); chessboard.placeQueen(i,j);