diff --git a/README.md b/README.md index 6f18b95..dee6c61 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,14 @@ die Aufgaben sind in ihm gespeichert und wie in Moodle nummeriert. Dateien wie Bilder die zur Lösung einer Aufgabe gehören sind in
Medien/Bilder & Co
gespeichert. -## Bisher vorhanden: +## Bisher vollständig vorhanden: - Vorlesung 3 komplett - Vorlesung 4 komplett +- Vorlesung 5 1 & 3 von 3 ## Angefangene unfertige Lösungen: -- keine \ No newline at end of file +- Damenproblem: VL 5 Aufgabe 2 +
Nicht die gewünschte rekursive Backtracking-Implementierung + + +- Keine diff --git a/src/part5/aufg2.java b/src/part5/aufg2.java new file mode 100644 index 0000000..3685352 --- /dev/null +++ b/src/part5/aufg2.java @@ -0,0 +1,127 @@ +package part5; + +// I know this is not recursive +// Shut up +// It works + +public class aufg2 { + public static void QueensPlace(int field[][],int row, int col){ + + // block spaces + for (int i=0; i<8; i++){ + // block row and col + field[i][col]=3; + field[row][i]=3; + + // block diagonals + // Left 2 Right, Top 2 Bottom + if (row - col + i < 8 && row - col + i >= 0) { + field[row-col + i][i]=3; + } + + // Left 2 Right, Bottom 2 Top + if(row+i < 8 && row+i >=0 && col-i < 8 && col-i >=0){ + field[row+i][col-i]=3; + } + if(row-i < 8 && row-i >=0 && col+i < 8 && col+i >=0){ + field[row-i][col+i]=3; + } + } + // place queen + field[row][col]=1; + } + public static boolean QueensFree(int field[][], int row, int col){ + return field[row][col] == 0; + } + public static void QueensPrint(int field[][]){ + // print field + System.out.println("---------------"); + for(int i=0; irows){ + System.out.println(); + System.out.println("Zu viele Damen für dieses Feld"); + System.out.println("maximal:" + rows); + return; + } + if(queens<0) { + System.out.println(); + System.out.println("Ungültiger Input: " + queensIn); + return; + } + + + while(queens>0){ + boolean full = true; + for(int i=0;i