From 096a49e0a8d0dd080107c05a3b52da2d72892081 Mon Sep 17 00:00:00 2001 From: peet Date: Wed, 5 Jun 2024 00:11:35 +0200 Subject: [PATCH] implemented ue06 --- bin/uebung06/Field.class | Bin 0 -> 2173 bytes bin/uebung06/Sudoku.class | Bin 0 -> 2263 bytes bin/uebung06/SudokuApp.class | Bin 0 -> 920 bytes bin/uebung06/VALUE.class | Bin 0 -> 2402 bytes src/uebung06/Field.java | 87 +++++++++++++++++++++++++++++++++++ src/uebung06/Sudoku.java | 66 ++++++++++++++++++++++++++ src/uebung06/SudokuApp.java | 28 +++++++++++ src/uebung06/VALUE.java | 50 ++++++++++++++++++++ 8 files changed, 231 insertions(+) create mode 100644 bin/uebung06/Field.class create mode 100644 bin/uebung06/Sudoku.class create mode 100644 bin/uebung06/SudokuApp.class create mode 100644 bin/uebung06/VALUE.class create mode 100644 src/uebung06/Field.java create mode 100644 src/uebung06/Sudoku.java create mode 100644 src/uebung06/SudokuApp.java create mode 100644 src/uebung06/VALUE.java diff --git a/bin/uebung06/Field.class b/bin/uebung06/Field.class new file mode 100644 index 0000000000000000000000000000000000000000..b923c7dd43e0fd62483a34f1a5f1d8696c64db1b GIT binary patch literal 2173 zcmZux%W@l45It9tC3!S{$&c8vj2|%|$%&N^NB}>AiEU7j?SK-6WH+{^%p|hpl4nwQ z&yTQTlSQaPP61UclPcEy17DHA={sX-EPF9?@7&vcy8E2&`TN};e*sv-lLR6P{hqz+ z)%UO8Dr`D-t(rhgVeqN-+$z+p`hH<&_o=<-D#VYxYU7!wFjQ(gl=ab)g8Gq9kwd?MY-0L8o>(mM*=g8%KZ`s+eTdvon`&`%catBW5 zxwJ}$c(rk0Idz4BkagJ>tl6_CA$LC;?Y`{P9d}h>EZad3iYgX!6@}Q{M%6YD#U&HN z7*~j9bCq5wTsC1KCA*A?9>it$o{0pKvYRo{i=?FG)a`BWVApOwuy$)KD_v^rS+$DQ zbmTiYjJZEJnvpiMeu-pc-*)|k6o#|8b6GM&T9AF_M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X6*_^PeCBvDuoF$GLj!|`} z_3`1oSzeJ?#y%ItdA!NCFlsfk%BIQuFJB*BJ`9#o`Jz9JizKgyahU>T+`qK<$@pJg zW;@NcYdCd*o;?6}A`0lTK`o+6{G!MWB%vQ9U^^!Sh$p+r%6?9Ya%6K2b3m4YQ%) zLxG_^Bwqzv!^Z-B|82@LcpP~UDLk8)N#zy8k;XA^9=;=--Qup`w>z~3Jr$3{Bflc5 z{DfF)6CFQrLxDU4olyA>@vR|F=Po)Qjm z3(+eFe@Y+$SFR(j(p^-%8#+Zv@H<2pqhut3d91TOFa;+u?6TH)@r<~vQ?%L-^(lhl zDSvjlwq0<%k$i|xnMo?K@)()9Eo2K4<#gcE22Q3W)lf?QY+h@>=p^6>c|>CSPvl#n(F&*qYALyEr5x9Lq>ktOs9=BP1{B&efQu%D!l z;RKaDO)bxJ{uXDqNM)KexKEoUQg2mc#U~zy$sgNmq@?2`R{{kcIO|FfpeNfB;b(|x z$ha!>g_Lddgk(=lFooB_zYtQ8rsIK&lKyC5Ox-}Qgq_TFtGRSy^k-aWo3LK%s_0gI zLVvXh@O!Ir1Ed6srtmJ&2qlIw!as)rj!=gQBl8>Z?~De<8sAK>zy~nPaD8HuGPDE Xk6+on@AH|%JZJKsiThOb6ZHHGzp=yW literal 0 HcmV?d00001 diff --git a/bin/uebung06/SudokuApp.class b/bin/uebung06/SudokuApp.class new file mode 100644 index 0000000000000000000000000000000000000000..ae884d287da076de979d6ea7cacaaeaf045bdcc8 GIT binary patch literal 920 zcmZuvYj4s}7=8{EO1lm^u5+7HrgQC3YK-wR%o1GUqCuI#kdVa>1sd#xmOyKwpZyj7 zi_L^3-r{HD{*v)M2jd*`%iH(zyqD)W{qgJ5Hvm;wG9nD=&}oNW@8%t=5qAC8VRbl^ zAu;F&_8Z&k+g{JAw-207zz`jWU516)Oh<(w{=oIzV4EO@*<_G*{H~)Sia8B35)7%D z>p9QDLE9Om&bpSQt-+hGh}Bs&`q>N8rZJKkT>>gr?)kNk?Zv; zW>ZFn_RO57B8@o()TAMXI1d*!T)+~8$}e{9zWa`@i5dHk&8C7Ctjf4}hJ54gIB*6U zF5xoK^Fz`hH{I|0)*dYn=mf_eRQT{U4OeiLArbh~!-$MwoJ5rhaf{BYE99=TlZJjf07;}MQlMjjGStjUG?F);d`7x;jO<6`j*!!z ze^Faex!#fz^_Cuwkx}$G*?I0Jsi3EHUP=p_7qx;!iA9cD(G{|*9Ja<$>%6kTTTOv4 z>AY0t&|3m}Tcq!a^nDKA;(%?Dt@6HyqO>ExyJFiDKDf?nds2OZ!V#9~@Ck|&te=Xo zMU+8WsYE-j1JU*a+LoDJe;l5)DKe7Cea3?6?I?Z9YK{kT& EZ?0>*tpET3 literal 0 HcmV?d00001 diff --git a/bin/uebung06/VALUE.class b/bin/uebung06/VALUE.class new file mode 100644 index 0000000000000000000000000000000000000000..af2e8e15585153a963a3a0515de2a8bf1e146fde GIT binary patch literal 2402 zcmZ`(-%}G;6#g~|*-czDEdByfTM8Ni1yO#8pn@165)x$t7@)OFh!~6s4T+VR_O&zZ zt22G;b7%UL#+l0W2h*oM^rin%+wa^YkV?BVXTSaKJ@?-8opbj7@z+lW0H&~~!=>S5 zDZNq3ZCx7~Se}Y5g>`s1w(Y!h2C`0WYapB}z0lxU4KKzu1fu_T9@pTG$HIIkRyf_1 zm|F~!d1m5Eivp2lnX@C0IcJBL!!cqwGCP;xWGo^JJG$(ZNMd^KNn+|=G~89+zDvcT z!L=6Aa3UOATBwfL8d}zl2VqR4vYA|_c!#G2dzQKTbbd2!pveynZ6?}rL4$Xq=5jU| zJfeAy1PskM$J|TV~Jtq7@P6+8UaYBeG zWWanfN3rX_N+x@AZ%g=vl{e#VKb9+ zvMPNM15CO$Xkeaj-M|9jh5;5>8#3^SFl>O8&_)a_5k?KH5N;Ys62=Uy5w2-ywu?^c z`GT`k)8NWK)zBJ@^c*jsE3?TpJl6Zt$(GX8)5;j%_48vBPjxUIfrbL^?H1E7Ol;wq z2A@+XID4u5&Yp%)W0~U{+v!wsJkpSu`VdRc45)MC46v(lS*<&cMJ&0`n#h3v#&F|; z>8!K6JKk{0;SNU;%P%!9<<3hzTBH!4nsBh8gTmX79AkOAlzKLkNoP01g+jidqeX+? z&X)?Q^h`$D!ms|5epy2Cc4jN*6iWq8bT)(_=S{qu%RA$fgFM*Ho4}lGldcDdYV%Gvy$3ewz1gf4x zij4$(YTanS|10BgSI}W6Jr!KGlT8(L+DUH(-F8y1AZRCz3VQ8ifJ6NRjtvqxI7IMO zFlxWS*bkKC!Z_dkyaPay%}i@M6LOUa7-9;hcx%LXS*&w@n^(gtdVI+eOsJKznio|y zNf_j~6h{yBcD%*yqs_f^Ky8t!zIEJ@tn>RWCTq(NxS9B^?qe$SBkuQqPr@fobJ6^? zA=)VI7VS1|k~U47p+#s>Yp!fPC|l986)Rg0%hqDqN|deTvh}!Zt(NKGZjjqT85SdG z#XZ(K%xcfE+VeO^$>;G1ZAehw3N9+S)yP+Ck*{+v-l7w(`olzhgpX@lej|#O_4cZW z6@Cl%(QeR0gQWc~P2!)W&C^7y&4QL$PFgoDNb9Bb(*|inv{72eyJ|X_oi5x&H>176 z%v{BN1gWS8QH1aiy;ReO#~5f(vyLbDglE>&47uwMBjw*+Q!~P*kiwp=U@STB4jm*X zr2iJ&7xt0rlQ^nPRIRh7_LqwJc-w5(_6XIg>$kMfKAtl{|GO?=$emwZrzLo@WbWGv za>?J}DX;8f=inFre2A%FmjrzA@8DS>>lNm$vmlvKC!;duud~Z!O?5ITQ-_ZI!u0xF zH`yWSBstu@gTzyHOTIy_%;pTRRW71{OH6t%u@A#6Mge1#GDDnY32b75P2vzYkVT%j zgFSps{DS}0SH!RJ8s8ABjoSF@NJ^zpQ#doHqxd&_RwK%*fT+CY|KsauLd~idYf<7x LF1*BN3Sa#LA9AM( literal 0 HcmV?d00001 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; + } + } +}