This commit is contained in:
Victor 2024-06-22 00:30:22 +02:00
parent e3eda3a457
commit 7d4074bded
3 changed files with 33 additions and 30 deletions

View File

@ -7,19 +7,23 @@ public class Chessboard {
public static final int SIZE = 8;
private final int[][] gameBoard = new int[SIZE][SIZE];
private final List<Position> queensPosition = new ArrayList<>();
private static final String ANSI_RED = "\u001B[31m";
private static final String ANSI_RESET = "\u001B[0m";
public Chessboard() {
// Constructeur vide
}
public void placeQueen(int x, int y) {
if(VerifAccessible(x,y)){
gameBoard[x][y] = 1;
queensPosition.add(new Position(x, y));
}
}
public void removeQueen(int x, int y) {
gameBoard[x][y] = 0;
queensPosition.removeIf(pos -> pos.x() == x && pos.y() == y); // Utilise removeIf pour supprimer l'objet correspondant
queensPosition.removeIf(pos -> pos.x() == x && pos.y() == y);
}
public Boolean VerifAccessible(int x, int y) {
@ -45,4 +49,22 @@ public class Chessboard {
public int getNumberOfQueen() {
return queensPosition.size();
}
public void printChessboard() {
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
if (gameBoard[j][i] == 1) {
System.out.print(ANSI_RED+"|♕|"+ANSI_RESET);
} else{
if(VerifAccessible(i, j)){
System.out.print("[ ]");
}
else{
System.out.print("[X]");
}
}
//System.out.print(" ");
}
System.out.println();
}
}
}

View File

@ -4,7 +4,12 @@ public class EightQueensSolver {
private Chessboard chessboard = new Chessboard();
public EightQueensSolver() {
System.out.println("Début");
System.out.println(Solver());
System.out.println("Fin");
chessboard.printChessboard();
}
public void main(String[] args){
}

View File

@ -19,29 +19,5 @@ class ChessboardTest {
assertEquals(1, this.chessboard.getNumberOfQueen());
}
/*@Test
void CaptureTiles(){
int Qx = 4;
int Qy = 4;
int Vx,Vy;
this.chessboard.placeQueen(Qx,Qy);
for (int i = 0; i < SIZE*SIZE; i++) {
Vx = i % SIZE;
Vy = i / SIZE;
if(Vx == Qx && Vy == Qy){
assertEquals(1, this.chessboard.gameBoard[Qx][Qy]);
continue;
}
if(Vx == Qx || Vy == Qy){
assertEquals(2, this.chessboard.gameBoard[Qx][Qy]);
continue;
}
If(Vx - Vy == Qx - Qy || Vx + Vy == Qx + Qy){
assertEquals(2, this.chessboard.gameBoard[Qx][Qy]);
continue;
}
assertEquals(0, this.chessboard.gameBoard[Qx][Qy]);
}
}*/
}