From 7d4074bded9dd99f71ed69d3e09d4a716302593b Mon Sep 17 00:00:00 2001 From: Victor Date: Sat, 22 Jun 2024 00:30:22 +0200 Subject: [PATCH] changes --- .../fr/iut_fbleau/but3/dev6_2/Chessboard.java | 28 +++++++++++++++++-- .../but3/dev6_2/EightQueensSolver.java | 9 ++++-- .../but3/dev6_2/ChessboardTest.java | 26 +---------------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/main/java/fr/iut_fbleau/but3/dev6_2/Chessboard.java b/src/main/java/fr/iut_fbleau/but3/dev6_2/Chessboard.java index c1645b5..cb8d70d 100644 --- a/src/main/java/fr/iut_fbleau/but3/dev6_2/Chessboard.java +++ b/src/main/java/fr/iut_fbleau/but3/dev6_2/Chessboard.java @@ -7,19 +7,23 @@ public class Chessboard { public static final int SIZE = 8; private final int[][] gameBoard = new int[SIZE][SIZE]; private final List 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) { - gameBoard[x][y] = 1; - queensPosition.add(new Position(x, 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(); + } + } } diff --git a/src/main/java/fr/iut_fbleau/but3/dev6_2/EightQueensSolver.java b/src/main/java/fr/iut_fbleau/but3/dev6_2/EightQueensSolver.java index 076e8cd..a5e2690 100644 --- a/src/main/java/fr/iut_fbleau/but3/dev6_2/EightQueensSolver.java +++ b/src/main/java/fr/iut_fbleau/but3/dev6_2/EightQueensSolver.java @@ -4,8 +4,13 @@ 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){ + } private Boolean Solver() { @@ -30,4 +35,4 @@ public class EightQueensSolver { public Chessboard getChessboard() { return chessboard; } -} +} \ No newline at end of file diff --git a/src/test/java/fr/iut_fbleau/but3/dev6_2/ChessboardTest.java b/src/test/java/fr/iut_fbleau/but3/dev6_2/ChessboardTest.java index f9182f4..d1c8384 100644 --- a/src/test/java/fr/iut_fbleau/but3/dev6_2/ChessboardTest.java +++ b/src/test/java/fr/iut_fbleau/but3/dev6_2/ChessboardTest.java @@ -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]); - } - }*/ + } \ No newline at end of file