checkRising is the filthy Criminal

This commit is contained in:
Matti 2024-05-20 21:54:30 +02:00
parent f53f29200e
commit 4286d01786
2 changed files with 21 additions and 7 deletions

View File

@ -3,12 +3,21 @@ package part5.aufg2;
public class Demo { public class Demo {
public static void main(String[] args) { public static void main(String[] args) {
Queenproblem Q = new Queenproblem(); Queenproblem Q = new Queenproblem();
Q.setField(new int[]{0, 0, 0, 0, 0, 0, 0, 0}); Q.setField(new int[]{2,4,6,8,1,3,5,0});
Q.print(); Q.print();
System.out.println("============="); System.out.println("============= ALL");
Q.solve(0); System.out.println(Q.isPossible(7,8));
System.out.println("============= Horiz");
System.out.println(Q.checkHorizontal(7));
System.out.println("============= Vert");
System.out.println(Q.checkVertical(8));
System.out.println("============= Rising");
System.out.println(Q.checkRisingDiagonal(7,8));
System.out.println("============= Falling");
System.out.println(Q.checkFallingDiagonal(7,8));
}
}
} }

View File

@ -6,7 +6,7 @@ public class Queenproblem {
// 0 means empty // 0 means empty
// 1-8 is the y position of the Queen // 1-8 is the y position of the Queen
int[] field; int[] field;
int[][] field2D;
public Queenproblem(){ public Queenproblem(){
this.field = new int[8]; this.field = new int[8];
} }
@ -144,10 +144,14 @@ public class Queenproblem {
} }
public void solve(int queensPlaced){ public void solve(int queensPlaced){
if (queensPlaced == 7){ field2D = make2D();
this.print(); if (queensPlaced == 6){
System.out.println("solved 6");
} }
for (int col = 1; col < 9; col++) { for (int col = 1; col < 9; col++) {
if(col == 8) {
System.out.println("solving the last one");
}
if (this.field[col-1] == 0) { if (this.field[col-1] == 0) {
for (int row = 1; row < 9; row++) { for (int row = 1; row < 9; row++) {
if (isPossible(row,col)) { if (isPossible(row,col)) {
@ -161,5 +165,6 @@ public class Queenproblem {
return; return;
} }
} }
this.print();
} }
} }