Compare commits

..

No commits in common. "b90d94bf4149bb0fc9646e299c57e7974684f0f8" and "a84a407c31e8c34d97d8c3d5ee874dcd4a348b8a" have entirely different histories.

8 changed files with 0 additions and 231 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,87 +0,0 @@
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<Field> dependents;
private Set<VALUE> 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<Field> getDependents() {
if (dependents == null) {
dependents = calculateDependents();
}
return dependents;
}
public Set<VALUE> getDomainSet() {
return domain;
}
public boolean isEmpty() {
return value == null;
}
@Override
public String toString() {
if (value != null) {
return value.toString();
} else {
return ".";
}
}
//TODO
private List<Field> calculateDependents() {
List<Field> 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;
}
}

View File

@ -1,66 +0,0 @@
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;
}
}

View File

@ -1,28 +0,0 @@
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());
}
}

View File

@ -1,50 +0,0 @@
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;
}
}
}