Compare commits

..

No commits in common. "9ff0ded7ea784060bf115e975e4ec4af9730708b" and "4286d01786a7a881c1a81f2166c39bd2dc629bc8" have entirely different histories.

2 changed files with 22 additions and 5 deletions

View File

@ -3,8 +3,18 @@ package part5.aufg2;
public class Demo {
public static void main(String[] args) {
Queenproblem Q = new Queenproblem();
Q.setField(new int[]{1,0,0,0,0,0,0,0});
Q.solve(0);
Q.setField(new int[]{2,4,6,8,1,3,5,0});
Q.print();
System.out.println("============= ALL");
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

@ -102,7 +102,7 @@ public class Queenproblem {
for (int i = 0; i < 8; i++) {
try {
if (this.field[col-1+i] != 0) {
if (this.field[col-1+i] == row-i) {
if (this.field[col - 1 + i] == row - i) {
return false;
}
}
@ -110,8 +110,8 @@ public class Queenproblem {
;
}
try {
if (this.field[col-1-i] != 0) {
if (this.field[col-1-i] == row+i) {
if (this.field[col-1-1] != 0) {
if (this.field[col - 1 - i] == row + 1) {
return false;
}
}
@ -144,7 +144,14 @@ public class Queenproblem {
}
public void solve(int queensPlaced){
field2D = make2D();
if (queensPlaced == 6){
System.out.println("solved 6");
}
for (int col = 1; col < 9; col++) {
if(col == 8) {
System.out.println("solving the last one");
}
if (this.field[col-1] == 0) {
for (int row = 1; row < 9; row++) {
if (isPossible(row,col)) {