tout ca tout ca
This commit is contained in:
parent
de585edfb7
commit
7c755a5ce3
@ -5,7 +5,7 @@ import java.util.List;
|
||||
|
||||
public class Chessboard {
|
||||
public static final int SIZE = 8;
|
||||
private final int[][] gameBoard = new int[SIZE][SIZE];
|
||||
public 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";
|
||||
|
@ -1,7 +1,7 @@
|
||||
package fr.iut_fbleau.but3.dev6_2;
|
||||
|
||||
public class EightQueensSolver {
|
||||
private Chessboard chessboard = new Chessboard();
|
||||
public Chessboard chessboard = new Chessboard();
|
||||
|
||||
public EightQueensSolver() {
|
||||
|
||||
@ -26,7 +26,7 @@ public class EightQueensSolver {
|
||||
|
||||
long startTimeVictor = System.currentTimeMillis();
|
||||
System.out.println("Début Victor");
|
||||
System.out.println(solver.Solver(0));
|
||||
System.out.println(solver.SolverVic(0));
|
||||
System.out.println("Fin Victor");
|
||||
long endTimeVictor = System.currentTimeMillis();
|
||||
System.out.println("Temps d'exécution Victor: " + (endTimeVictor - startTimeVictor) + " ms");
|
||||
@ -34,7 +34,7 @@ public class EightQueensSolver {
|
||||
|
||||
}
|
||||
|
||||
private Boolean Solver(int level) {
|
||||
public Boolean SolverVic(int level) {
|
||||
if (chessboard.getNumberOfQueen() == Chessboard.SIZE) {
|
||||
return true;
|
||||
}
|
||||
@ -43,7 +43,7 @@ public class EightQueensSolver {
|
||||
int y = i / Chessboard.SIZE;
|
||||
if (chessboard.VerifAccessible(x, y)) {
|
||||
chessboard.placeQueen(x, y);
|
||||
if (!Solver(y)) {
|
||||
if (!SolverVic(y)) {
|
||||
chessboard.removeQueen(x, y);
|
||||
} else {
|
||||
return true;
|
||||
@ -53,7 +53,7 @@ public class EightQueensSolver {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean SolverSim(int line){
|
||||
public boolean SolverSim(int line){
|
||||
if(chessboard.getNumberOfQueen() == Chessboard.SIZE){
|
||||
return true;
|
||||
}
|
||||
|
@ -9,10 +9,12 @@ import org.junit.jupiter.api.Test;
|
||||
class ChessboardTest {
|
||||
|
||||
private Chessboard chessboard;
|
||||
private EightQueensSolver solver;
|
||||
|
||||
@BeforeEach
|
||||
public void beforeEach() {
|
||||
this.chessboard = new Chessboard();
|
||||
this.solver = new EightQueensSolver();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -74,14 +76,40 @@ class ChessboardTest {
|
||||
return x >= 0 && x < Chessboard.SIZE && y >= 0 && y < Chessboard.SIZE;
|
||||
}
|
||||
|
||||
|
||||
void testWinningSolution(Chessboard chessboard) {
|
||||
assertEquals(Chessboard.SIZE, chessboard.getNumberOfQueen(),"Devrait etre egal a "+Chessboard.SIZE);
|
||||
for(int i = 0; i< Chessboard.SIZE ;i++){
|
||||
for(int j = 0; j< Chessboard.SIZE ;j++){
|
||||
if(chessboard.gameBoard[i][j] != 0){
|
||||
chessboard.removeQueen(i,j);
|
||||
assertTrue(chessboard.VerifAccessible(i,j));
|
||||
chessboard.placeQueen(i,j);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWinningSolution() {
|
||||
// Placer les reines aux positions données
|
||||
void TestSolverSim() {
|
||||
solver.SolverSim(0);
|
||||
testWinningSolution(solver.chessboard);
|
||||
}
|
||||
|
||||
@Test
|
||||
void TestSolverVic() {
|
||||
solver.SolverVic(0);
|
||||
testWinningSolution(solver.chessboard);
|
||||
}
|
||||
|
||||
@Test
|
||||
void TestKnownedWinningSolution(){
|
||||
|
||||
int[][] positions = {
|
||||
{0, 0}, {1, 4}, {2, 7}, {3, 5},
|
||||
{4, 2}, {5, 6}, {6, 1}, {7, 3}
|
||||
};
|
||||
|
||||
|
||||
for (int[] pos : positions) {
|
||||
assertTrue(this.chessboard.VerifAccessible(pos[0], pos[1]),
|
||||
"La position (" + pos[0] + "," + pos[1] + ") devrait être accessible.");
|
||||
@ -89,7 +117,8 @@ class ChessboardTest {
|
||||
assertFalse(this.chessboard.VerifAccessible(pos[0], pos[1]),
|
||||
"La position (" + pos[0] + "," + pos[1] + ") ne devrait plus être accessible.");
|
||||
}
|
||||
|
||||
testWinningSolution(this.chessboard);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user