diff --git a/bin/uebung06/Field.class b/bin/uebung06/Field.class new file mode 100644 index 0000000..b923c7d Binary files /dev/null and b/bin/uebung06/Field.class differ diff --git a/bin/uebung06/Sudoku.class b/bin/uebung06/Sudoku.class new file mode 100644 index 0000000..fd2512a Binary files /dev/null and b/bin/uebung06/Sudoku.class differ diff --git a/bin/uebung06/SudokuApp.class b/bin/uebung06/SudokuApp.class new file mode 100644 index 0000000..ae884d2 Binary files /dev/null and b/bin/uebung06/SudokuApp.class differ diff --git a/bin/uebung06/VALUE.class b/bin/uebung06/VALUE.class new file mode 100644 index 0000000..af2e8e1 Binary files /dev/null and b/bin/uebung06/VALUE.class differ diff --git a/src/uebung06/Field.java b/src/uebung06/Field.java new file mode 100644 index 0000000..54f4f4e --- /dev/null +++ b/src/uebung06/Field.java @@ -0,0 +1,87 @@ +package uebung06; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +public class Field { + private Sudoku sudoku; + private int x; + private int y; + private VALUE value = null; + + private List dependents; + private Set domain; + + + public Field(Sudoku sudoku, int x, int y) { + this.sudoku = sudoku; + this.x = x; + this.y = y; + } + + public Sudoku getSudoku() { + return sudoku; + } + + public int getx() { + return x; + } + + public int gety() { + return y; + } + + public VALUE getValue() { + return value; + } + + public void setValue(VALUE value) { + this.value = value; + } + + public List getDependents() { + if (dependents == null) { + dependents = calculateDependents(); + } + return dependents; + } + + public Set getDomainSet() { + return domain; + } + + public boolean isEmpty() { + return value == null; + } + + @Override + public String toString() { + if (value != null) { + return value.toString(); + } else { + return "."; + } + } + + + //TODO + private List calculateDependents() { + List rtn = new ArrayList<>(); + + //add all the ones in the same col + for (int i = 0; i < 9; i++) { + rtn.add(sudoku.getField(x, i)); + } + + // //add all the ones in the same row + for (int i = 0; i < 9; i++) { + rtn.add(sudoku.getField(i, y)); + } + + + + + return rtn; + } +} diff --git a/src/uebung06/Sudoku.java b/src/uebung06/Sudoku.java new file mode 100644 index 0000000..657ce23 --- /dev/null +++ b/src/uebung06/Sudoku.java @@ -0,0 +1,66 @@ +package uebung06; + +public class Sudoku { + private Field[][] board; + + public Sudoku() { + board = new Field[9][9]; + createEmptyboard(); + } + + public Field getField(int x, int y){ + return board[x][y]; + } + + public void setField(int x, int y, VALUE value){ + board[x][y].setValue(value); + } + + private void createEmptyboard() { + for (int i = 0; i < 9; i++) { + for (int j = 0; j < 9 ; j++) { + board[i][j] = new Field(this, i, j); + } + } + } + + @Override + public String toString() { + StringBuilder str = new StringBuilder(); + + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board.length; j++) { + str.append(board[i][j].toString() + " "); + + if (j == 2 || j == 5) { + str.append("| "); + } + } + str.append("\n"); + + if (i == 2 || i ==5) { + str.append("------+-------+------\n"); + } + } + + return str.toString(); + } + + public void initialize(int[] values) { + int c = 0; + + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board.length; j++) { + board[i][j].setValue(VALUE.of(values[c])); + c++; + } + } + } + + public boolean solve() { + + + + return true; + } +} diff --git a/src/uebung06/SudokuApp.java b/src/uebung06/SudokuApp.java new file mode 100644 index 0000000..8f5f7ea --- /dev/null +++ b/src/uebung06/SudokuApp.java @@ -0,0 +1,28 @@ +package uebung06; + + +public class SudokuApp { + private static Sudoku sud; + public static void main(String[] args) { + sud = new Sudoku(); + // sud1.setField(0, 0, VALUE.FOUR); + // sud1.setField(0, 1, VALUE.FIVE); + // sud1.setField(0, 6, VALUE.TWO); + // sud1.setField(0, 0, VALUE.FOUR); + // sud1.setField(0, 0, VALUE.FOUR); + // sud1.setField(0, 0, VALUE.FOUR); + + sud.initialize(new int[]{ + 4, 5, 0, 0, 0, 0, 2, 0, 0, + 6, 0, 0, 0, 2, 4, 8, 0, 0, + 8, 0, 0, 0, 6, 1, 3, 0, 0, + 0, 9, 0, 4, 0, 0, 0, 5, 0, + 0, 1, 0, 2, 0, 8, 0, 7, 0, + 0, 3, 0, 0, 0, 9, 0, 8, 0, + 0, 0, 7, 1, 4, 0, 0, 0, 8, + 0, 0, 2, 7, 9, 0, 0, 0, 6, + 0, 0, 5, 0, 0, 0, 0, 2, 1}); + + System.out.println(sud.toString()); + } +} diff --git a/src/uebung06/VALUE.java b/src/uebung06/VALUE.java new file mode 100644 index 0000000..81fbcf3 --- /dev/null +++ b/src/uebung06/VALUE.java @@ -0,0 +1,50 @@ +package uebung06; + +public enum VALUE { + ZERO, + ONE, + TWO, + THREE, + FOUR, + FIVE, + SIX, + SEVEN, + EIGHT, + NINE; + + @Override + public String toString() { + switch (this) { + case ONE: return "1"; + case TWO: return "2"; + case THREE: return "3"; + case FOUR: return "4"; + case FIVE: return "5"; + case SIX: return "6"; + case SEVEN: return "7"; + case EIGHT: return "8"; + case NINE: return "9"; + + default: + return "0"; + } + } + + public static VALUE of(int id) { + switch (id) { + // case 0: return null; handle via default + case 1: return ONE; + case 2: return TWO; + case 3: return THREE; + case 4: return FOUR; + case 5: return FIVE; + case 6: return SIX; + case 7: return SEVEN; + case 8: return EIGHT; + case 9: return NINE; + + default: + return ZERO; + } + } +}