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 348cbd8..9d9b672 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 @@ -10,14 +10,36 @@ public class Chessboard { private final List queensPosition = new ArrayList<>(); public Chessboard(){ - + } + + public void placeQueen(int x, int y){ gameBoard[x][y] = 1; queensPosition.add(new Position(x,y)); } + public Boolean VerifAccessible(int x, int y){ + for (int i = 0; i < SIZE; i++) { + int DigonaleAscendante = y - (x - i); + int DigonaleDescendante = y + (x - i); + if(gameBoard[i][y] != 0){ + return false; + } + if(gameBoard[x][i] != 0){ + return false; + } + if (DigonaleAscendante >= 0 && DigonaleAscendante < SIZE && gameBoard[i][DigonaleAscendante] == 1) { + return false; + } + if (DigonaleDescendante >= 0 && DigonaleAscendante < SIZE && gameBoard[i][DigonaleDescendante] == 1) { + return false; + } + } + return true; + } + public int getNumberOfQueen() { return queensPosition.size(); } 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 e5b2a11..faa493c 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,9 +4,12 @@ public class EightQueensSolver { private Chessboard chessboard = new Chessboard(); public EightQueensSolver(){ + } + + public Chessboard getChessboard() { return chessboard; } 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 e1bd675..a04223b 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,4 +19,30 @@ class ChessboardTest { this.chessboard.placeQueen(0,0); 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