From c818eec943cfc3fb9a35e1a8b5e02e7d967c8ff0 Mon Sep 17 00:00:00 2001 From: dick Date: Sat, 6 Apr 2024 20:23:50 +0200 Subject: [PATCH] v2 --- Enter$1.class | Bin 2049 -> 0 bytes Enter.class | Bin 2206 -> 0 bytes Enter.java | 120 ------------------------------- GenerateurSudoku.class | Bin 0 -> 720 bytes GenerateurSudoku.java | 20 ++++++ GrilleSudokuDessin.class | Bin 0 -> 1307 bytes GrilleSudokuDessin.java | 46 ++++++++++++ Main$1.class | Bin 1477 -> 1297 bytes Main$2.class | Bin 0 -> 610 bytes Main.class | Bin 1501 -> 1603 bytes Main.java | 80 +++++++++++---------- Reinitialiser.class | Bin 0 -> 720 bytes Reinitialiser.java | 22 ++++++ Reset.class | Bin 675 -> 0 bytes Reset.java | 22 ------ Resolve.class => Resolveur.class | Bin 846 -> 855 bytes Resolve.java => Resolveur.java | 38 +++++----- SaisieGrille$1.class | Bin 0 -> 1938 bytes SaisieGrille.class | Bin 0 -> 2264 bytes SaisieGrille.java | 87 ++++++++++++++++++++++ SudokuDraw.class | Bin 1275 -> 0 bytes SudokuDraw.java | 46 ------------ SudokuGenerator.class | Bin 2861 -> 0 bytes SudokuGenerator.java | 114 ----------------------------- 24 files changed, 237 insertions(+), 358 deletions(-) delete mode 100644 Enter$1.class delete mode 100644 Enter.class delete mode 100644 Enter.java create mode 100644 GenerateurSudoku.class create mode 100644 GenerateurSudoku.java create mode 100644 GrilleSudokuDessin.class create mode 100644 GrilleSudokuDessin.java create mode 100644 Main$2.class create mode 100644 Reinitialiser.class create mode 100644 Reinitialiser.java delete mode 100644 Reset.class delete mode 100644 Reset.java rename Resolve.class => Resolveur.class (67%) rename Resolve.java => Resolveur.java (60%) create mode 100644 SaisieGrille$1.class create mode 100644 SaisieGrille.class create mode 100644 SaisieGrille.java delete mode 100644 SudokuDraw.class delete mode 100644 SudokuDraw.java delete mode 100644 SudokuGenerator.class delete mode 100644 SudokuGenerator.java diff --git a/Enter$1.class b/Enter$1.class deleted file mode 100644 index ebe0cedee3edfb311a3082a675d5a577fd014d0a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2049 zcma)6-&Yey6#fQCHiWeV6cGhoC6oj(QERm&YO4`6mR}W$0{!8TjA3Q7lkQGH|BF7h z_05NRd}?ihqCKbQ^w=l+ANkPs&TcHBr9I6#nS1xnz2DsX-8=L0_vb$YI1goDxE0+P z(aXs=4j~gq5?Q^RY6Zh-y_{*qTR7WE5%0wDE=IL27sG`(F5*%g@8SJ8SuX44N(^~z zzG`4BhVdA#8MtoX219I(JIS(Vml&FtmI@3}wPO3pQw+w$n5%@BBhv-jwbdnteW|*Q zJk#?GEqPfI4DA!PE2e6dW#P^7Wrr+gMb>&NL-Op`O4$f5Y%sv z;&u!RCKj<|;A0b?;8PQy;V{FA0Nx_+NZWG&QT> zy28sl-1mjgaAdDmT`ut|9m3GF*KW{AB5;i4XmnEbQE5&E15+02HceV8O_SC_ z9}5g^uW7p}*BKaX{AI~YXE*8tUx^CE%Nn(~D;z3YW@qRyMMnx=$;Gh>it5d4X8adV zbW4al_r()ojan%-VzD$scZIKtymX6P-LlmRX};pFqVf->3Waot9JC^=gl@t9pt{|s z5sg)SwnNS7stno*$nDC_3Ms@(Ghef~?f#Jy?z^LoT+sZml< zVxy2=q&huOIAGD*8TE8In5*+U}ZM71@yLuq)%dsHFG6 z0HqzBkaD#~AzwC9Tn`HG>UHjx9N{NJ&qj{w{cB)tSK!=(s@TJQslk5_mg^9C?l`ly z5;+4jIRpPFXs_JpHT-WsSoG*0qF22skV1f3y@}RG_@VD1 zzU|Z6lc5bX^=-n?vUd})@6oE&jnJ}z*mJ~zEwqJJv%YyIl(Ed$xWhX4ZR3s6mY$Yv zw4aOUovvWr0og+0EA-P&^WWmTBGcNkg^tH)Wu2Yd*#8)9qY>8G6{uu8NXkBWt$m0QR|(=ON!Ae};VjWGiGGyHBJn2Hh{G?C!Z%3cI}8&>mQYUOCuHyo zPT^Oa#!HIoC$!^;{y|Pr1KkFaj2Rdpc3&ZK#lV4AFq$HW5TtI>AVGq7W&}GFSQrW< ZJ87?*r2e`1oKon)+oZ?H^Bn!p{|Oww4KDxy diff --git a/Enter.class b/Enter.class deleted file mode 100644 index 43fa073b3ed59a161b5142586862de6dcc52dd80..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2206 zcmZ8iOK%fb6#i~JLQ!&+e$^1ibADsShS@$ZIMz`iB00>B)O;|5rmF@DGbQdgBpf{2;p4~ zNu}>&AczKBlA6nsqyiYmND!kKljKSeQ$;JbdE4ytX( zF4$&v$kSE3R@O=vtju_BnR{DOB9|5LpOvP)WFkD-K1oN3T*eZpOWBS!va~R3<*%Bv zS!!w~3TFE5u(?>0Yv-&&vNDbuY4@V*w#&rrjF-LioJ=O$rv+*kP1`9Xatn(&$8rh+ zJ0qz(<~_5^TrPAC<;}%;JMH$gPikNq!HL{bK5Y%!GIVgjDOmYVY0LsfEVnRh$;@0G zQC!mz!G0a>k{m&sj-zN3Xehhxw-+qOwR4Vu>N%39-q$gOX&u*bLqPM?t;glYO&uTL zmX5b^LZGqiWGlaTzm6F&ji&O}Mbov@6NP;4t|cAJ>PRD_!@_M1b2{c>Yq+E1F0win zq|(um!=jE4kuT->QJ1@HJ9Ax^#!SazTk6WrH~q4)5!oD-SjsizT7|K^b=%74t;~dd zpBU|`0JB^%(d4wzcrce^M5d*-CX({1?kV*>WM(qMxh2<1*>1t&cnTb>aB1DM zoI=-s3_RxnPQg}=jgj{4hHff*I8c#6885&rwhWsp9GC2*$&O6kT$Xdkj>w_$O06wJ z!GX;&EA?XPLgF$p*pB7xFjRfncB@@<%DAPIjTK=xkCda1^McT&cRp*f6HJQ@VIueB z9UQ$aU__Fo@+u4%G$^y)GT-V#rHQNq2l;Y@c~vzuV;}ZI-~gp6>YH)sfAZl9xs^5? zYR{H)?X4VlZ{@^uRp={<7-cy}8)(|Kn7*&d>rdFSd z#@0|%MD2H8M#o6cpq8|jSyUsyN3#}nXhc0LZQvbkT1iWddDzt5j(VSMEZUX@5&bK!*2w%F~4HIO609ifDt6 z@B?4_x)npAz2X(TZ<8~W&b<#&Z73~YLG?XeQCRZJvL%7>>7JP)_O7Ue z@`)Gc(e_}DbMU|iU*!WI#4X}F!z($)|MazT$H G1N;lU7Scxm diff --git a/Enter.java b/Enter.java deleted file mode 100644 index 36a1403..0000000 --- a/Enter.java +++ /dev/null @@ -1,120 +0,0 @@ -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; - -public class Enter extends JPanel { - private static final int GRID_SIZE = 3; - private static final int REGION_SIZE = 3; - private static final int CELL_SIZE = 50; - private int[][] grid; - private int[][] initialGrid; // Pour stocker la grille initiale - private int selectedRow = -1; - private int selectedCol = -1; - - public Enter(int[][] grid) { - this.grid = grid; - // Copie de la grille initiale - this.initialGrid = new int[grid.length][grid[0].length]; - for (int i = 0; i < grid.length; i++) { - for (int j = 0; j < grid[i].length; j++) { - this.initialGrid[i][j] = grid[i][j]; - } - } - setPreferredSize(new Dimension(GRID_SIZE * REGION_SIZE * CELL_SIZE, GRID_SIZE * REGION_SIZE * CELL_SIZE)); - setFocusable(true); // Permet au JPanel de recevoir les événements de souris - - addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - int x = e.getX() / CELL_SIZE; - int y = e.getY() / CELL_SIZE; - if (x >= 0 && x < GRID_SIZE * REGION_SIZE && y >= 0 && y < GRID_SIZE * REGION_SIZE) { - selectedRow = y; - selectedCol = x; - System.out.println("Case sélectionnée : (" + selectedRow + ", " + selectedCol + ")"); - if (initialGrid[selectedRow][selectedCol] == 0) { // Ne permet la modification que pour les cellules vides - String valueStr = JOptionPane.showInputDialog(null, "Enter value for the selected cell:"); - try { - int value = Integer.parseInt(valueStr); - if (isValidValue(value, selectedRow, selectedCol)) { - grid[selectedRow][selectedCol] = value; - repaint(); - } else { - JOptionPane.showMessageDialog(null, "Not possible."); - } - } catch (NumberFormatException ex) { - JOptionPane.showMessageDialog(null, "Invalid input. Please enter a number."); - } - } else { - JOptionPane.showMessageDialog(null, "You can't edit the default value."); - } - } - } - }); - } - - public int[][] getInitialGrid() { - return initialGrid; - } - - private boolean isValidValue(int value, int row, int col) { - // Vérifier la ligne - for (int i = 0; i < grid[row].length; i++) { - if (grid[row][i] == value && i != col) { - return false; - } - } - - // Vérifier la colonne - for (int i = 0; i < grid.length; i++) { - if (grid[i][col] == value && i != row) { - return false; - } - } - - // Vérifier la région - int regionRow = row / REGION_SIZE * REGION_SIZE; - int regionCol = col / REGION_SIZE * REGION_SIZE; - for (int i = regionRow; i < regionRow + REGION_SIZE; i++) { - for (int j = regionCol; j < regionCol + REGION_SIZE; j++) { - if (grid[i][j] == value && (i != row || j != col)) { - return false; - } - } - } - - return true; - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - // Dessiner les contours de la grille (en gras) - Graphics2D g2d = (Graphics2D) g; - Stroke oldStroke = g2d.getStroke(); // Sauvegarder le style de ligne précédent - g2d.setStroke(new BasicStroke(4)); // Épaisseur de ligne de 4 pixels - - for (int i = 0; i <= GRID_SIZE * REGION_SIZE; i++) { - if (i % REGION_SIZE == 0) { - g2d.drawLine(0, i * CELL_SIZE, GRID_SIZE * REGION_SIZE * CELL_SIZE, i * CELL_SIZE); - g2d.drawLine(i * CELL_SIZE, 0, i * CELL_SIZE, GRID_SIZE * REGION_SIZE * CELL_SIZE); - } - } - - // Rétablir le style de ligne précédent - g2d.setStroke(oldStroke); - - // Dessiner les cases de la grille - for (int i = 0; i < GRID_SIZE * REGION_SIZE; i++) { - for (int j = 0; j < GRID_SIZE * REGION_SIZE; j++) { - g.setColor(Color.BLACK); - g.drawRect(j * CELL_SIZE, i * CELL_SIZE, CELL_SIZE, CELL_SIZE); - int value = grid[i][j]; - if (value != 0) { - g.drawString(String.valueOf(value), j * CELL_SIZE + CELL_SIZE / 2, i * CELL_SIZE + CELL_SIZE / 2); - } - } - } - } -} diff --git a/GenerateurSudoku.class b/GenerateurSudoku.class new file mode 100644 index 0000000000000000000000000000000000000000..d9f681a11b2d34af195bf4992e0dc8c79dfd5756 GIT binary patch literal 720 zcmZXSzfQw25XR5VAG@KY28oe@t?fV;M#O?dg+OEoLW(-2tyQIzREip&3l=~KcmQUe z2l1VgmQoV=V&DDl?z5fG@7E6^I-;F`Txv?%mei7@1^LHmmM%^NIqlAkAop}WHiBB0 zX=bj9yP?Uili>`W=EP(sH+er#XT0{>ox$K-P!P?Fd}Pj2cJB2VN*1QbqhdV2Ee@y2 zebOM0d_gtF^(FxqGrd`oO?u&QYDNn>AO|Y>sS!Gn4=b_S$5-I%b)QK*Vj@Vva+r`( z#~WY{RD8k0D_(T{oocb8>u*8qIAQE!co;s0)b%h{DvUL+v}B`X7{zXhBjWlME`cMi zw8b@+74L!f{+DOMCU8+-qfEv7;Qf;4_J8z%LjR>4+e$g$A#^Dp;gx(BxGm2{T1^&L zzqnW7P;G%Vo|6=WMXb-(M{O&Ib=mU)qEKP|cvud4S)O-QCLj|vsvYxQ%LC57h-vB00MFD3GTD)Ok6>rMjTRPqrn7+DE zt<_2&RCeS`KvWqkdTzI8xxMRFyKgH@tvo00lq%KBb%EG{uvn_quGLDCRS<~W@tt_6L++NY!>v*p1_5_Zl zYxk`CR^Hn05F_)nb^Rlj-rVzlysC$RPerzs)>uZWTJ-cgNi=RclRClPX6K*%eC8_ zVp=w=rK`d0;$6FU#kX(UzHhf0&L^_hu_28*38ti`%TgPqCM<_lj*-Jyz?^LP*8Yy& zYbv2~O4oW=7n@nFvfW?}2i5ENv)}g~bC=+hVt@ zg-tX2eRk z7o4VHjCZwTQODyG-RJ?Fk zYcY{Nz;rG|icU=U5Q`x}l?2ui64aKWg@gx+c=*qw>?6bmI6~*l514rJ4a&-@np7o7 z6$sCSyQI3ZswK5Au#in^KOvq}nL0lIq0GtG05cC%+Wj7w4rRv^LC19tS@x}Qlm>@9 zhk3@2;{-=}j$98luJSS6aNC#QyE+U literal 0 HcmV?d00001 diff --git a/GrilleSudokuDessin.java b/GrilleSudokuDessin.java new file mode 100644 index 0000000..9c27d7c --- /dev/null +++ b/GrilleSudokuDessin.java @@ -0,0 +1,46 @@ +import javax.swing.*; +import java.awt.*; + +public class GrilleSudokuDessin extends JPanel { + private static final int TAILLE_GRILLE = 3; + private static final int TAILLE_REGION = 3; + private static final int TAILLE_CELLULE = 50; + + private int[][] grille; + + public GrilleSudokuDessin(int[][] grille) { + this.grille = grille; + setPreferredSize(new Dimension(TAILLE_GRILLE * TAILLE_REGION * TAILLE_CELLULE, TAILLE_GRILLE * TAILLE_REGION * TAILLE_CELLULE)); + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + Graphics2D g2d = (Graphics2D) g; + // Définir l'épaisseur de la ligne + g2d.setStroke(new BasicStroke(20)); // Épaisseur de ligne de 4 pixels + + // Dessiner les lignes de la grille (en gras pour les contours) + for (int i = 0; i <= TAILLE_GRILLE * TAILLE_REGION; i++) { + if (i % TAILLE_REGION == 0) { + g2d.drawRect(0, i * TAILLE_CELLULE - 2, TAILLE_GRILLE * TAILLE_REGION * TAILLE_CELLULE, 4); + g2d.drawRect(i * TAILLE_CELLULE - 2, 0, 4, TAILLE_GRILLE * TAILLE_REGION * TAILLE_CELLULE); + } else { + g2d.drawRect(0, i * TAILLE_CELLULE - 1, TAILLE_GRILLE * TAILLE_REGION * TAILLE_CELLULE, 2); + g2d.drawRect(i * TAILLE_CELLULE - 1, 0, 2, TAILLE_GRILLE * TAILLE_REGION * TAILLE_CELLULE); + } + } + + // Dessiner les valeurs de la grille + g.setColor(Color.BLACK); + for (int i = 0; i < grille.length; i++) { + for (int j = 0; j < grille[i].length; j++) { + int valeur = grille[i][j]; + if (valeur != 0) { + g.drawString(String.valueOf(valeur), j * TAILLE_CELLULE + TAILLE_CELLULE / 2, i * TAILLE_CELLULE + TAILLE_CELLULE / 2); + } + } + } + } +} diff --git a/Main$1.class b/Main$1.class index 1fcd9019109e0365f30ca1896a211016fa80aabd..f029fb0295c8861a7da18db7d0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|nEs5~pm%#+17Duc<;ccK`+3Ulv zoe-f(HbNQdUEemFHY~t-ri>0cJYPy=t=-T^ZRTuSUHnF1Fc}mYMykc2aSmUgDlqpn zsjgdb&{m%8sJds`_4=!yjHg0Rcukh?8&%g~Lm6*U;9652sfrHkGXC0+54kh33}Z5J zwXjhqS=_x&QTw3mt`{KVAD2o zMiuJ&a94396Tc6%=^3hPwwX-Dl!OaeyljnHG!#f1znVzz>WX6gU7$mFnF^tFgj|l4nWD< zlSp15{(Dk-^SynO2xBNFgEp^BM diff --git a/Main$2.class b/Main$2.class new file mode 100644 index 0000000000000000000000000000000000000000..0a6b6156e452418d8a909c9f3e4279d12df013f0 GIT binary patch literal 610 zcmZuu-AWrl7(KIz*|@GrY;9U?tyr3a!qgdRrj(Q5&7?2+UT=`FC1770B*|0}2*f z+Nh)RQBOrDvS+U-%6_6l^F>A9!f2!h0*lqwnH`L-4FI^lWL zR|nb(Otz&q8%7>3>9|gP zk6rK!L0-|KlWBjkoIagjSj_rQ7Aj?j+xXEpwPCpa(#pHiLS?2HC=%m-Sm@lVo857^ z%Z#E)m#VDky6IQD@!2q54u#UNxuKl+6A$y_y^M3;t|S9O|A_B$LzA zquGD2A2k_X^u2DdrS(5)D4MFf8+94y#yVvI^cO?v2N&#?Q@gMdj_<0WK1!h2C74)E zQqOKu5=*IaC2NZIKKg3(F4btt7@o1rnp};wRhpM^b8btG)=b=sFS9PUyC+qnt;+h} z$_A|@yu>n|C^a^U;2B=L%BCsdgyvL_+g@dJ$}`+8nyYM0sVdu2MwRWKh`AkAj8&7* zw983ZKg5$IJ{@dY1vks~bMMBcN~!?>XE)N_OMgfmBRh2uqhIB!Mp8#*K*BYZL7f0YD%Uk`=mZ(i7*@HdQ$>e_TPn9TMx^?V#;D4$ zPCa8%I<7LI6XmX4oD55xk}$0?qcW>9_x9s{R3R{D<(*k;Z{4!<1}(Iz+%uTxzT2QQ zS1lN%SX5auc)+s4kUOtLs!u+}_D$Q#*s*jWwwc-3&RDj)t#mH6uxRj*6$Rf|*0F49 z_(&nVV;-1?UHKQ8>{i#*NWpP(Ss_W~b`LBO7p%PHD1`n~&6`$?vSUsca2~DH2vW(rL>gRF%^-Zw*V4CfFcEo2;$Py#$BRq6Fb^$igNFh zaN&$Zq3R(Iz#H%?2m!Npgc1p@G&4It-+VLk{rBYrz&-*Od0Z*L!Br!!xwwuSE~;2J z)=dW+4sJQvWXN@u?DYhLeR$YpC=PfO2|j9bIh5pGY^BzVB&$LB4`n3vV}=!<3g)A= zcMO@Q@e$RPS~3!^M*WUZZ+XYymw2dU9K9CmeXRQ8h+)HT9rIIO=O1)koQg=-pCl>I zjNLF`#kS_*$xA+%Vz}*iq(bpr8o#nlS85I87L2n*z(|F!GnjQgWDdqamT@q zhh6v{YS<#wxk83=!lK8cZvCKhEJDq&{$FA(In*K&ik9UYdfx1A7?!$1r+aFqyohAh zuO)k(>Cqk&N}r*?mEz+t9*h}+=_+POG@9vl=3GtF)=^@>Wu&o5r_FGqZx zJkfMKlqg!J-vjd7q)Wj!u;A`FtYGgP_GfYtZ;};cNajfv=($w7K#>ZTrvN9&B>?;O zqiXO4*5o6$N!wqMsouAZ=bxHfAbV!9Pk(--2|3fnO1i8eOLm#Cm#{;64=Y4%l_bm% PzhJSSbR$MCQ?m9KUMrt3 literal 0 HcmV?d00001 diff --git a/Reinitialiser.java b/Reinitialiser.java new file mode 100644 index 0000000..a5c8bc3 --- /dev/null +++ b/Reinitialiser.java @@ -0,0 +1,22 @@ +import javax.swing.*; +import java.awt.event.*; + +public class Reinitialiser implements ActionListener { + private int[][] grille; + private SaisieGrille panneauSaisie; + + public Reinitialiser(int[][] grille, SaisieGrille panneauSaisie) { + this.grille = grille; + this.panneauSaisie = panneauSaisie; + } + + @Override + public void actionPerformed(ActionEvent e) { + // Réinitialiser la grille en copiant la grille initiale + for (int i = 0; i < grille.length; i++) { + System.arraycopy(panneauSaisie.getGrilleInitiale()[i], 0, grille[i], 0, grille[i].length); + } + // Redessiner le panneau + panneauSaisie.repaint(); + } +} diff --git a/Reset.class b/Reset.class deleted file mode 100644 index bba0690e83bd88cea0fa641d3db88a6c990152e6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 675 zcmZuu-)j>=5dP*amrJgfCaqe3rPkJ3FK02J1s|edW#fUF`+FaLgZE_d3+e+U3 zOMLNJuvUD?AK-uBzapZ}Zi7^ig_+rJXTEP{_S>(o69D%S2PolU89puvwagvY5gm^me8R=I0bO--HZ6oF@ITC56vCO|!0yDwk!!z=CI%Z7kxf@jZwZ^x5 zjJxcs@d+rteGDgFKZg5}A;KKnc@)@|*p~SOTsp%q^Efvp*hkS4Y`72W@h3Qw_gH1` zenz2w*EPsrH~9kZokJgfe?Ltq8WqQ?EWqQq#@usQW515`+}Z`UFhl%=LqGUOh#^z5 F@CT|EjMo4F diff --git a/Reset.java b/Reset.java deleted file mode 100644 index 7030942..0000000 --- a/Reset.java +++ /dev/null @@ -1,22 +0,0 @@ -import javax.swing.*; -import java.awt.event.*; - -public class Reset implements ActionListener { - private int[][] grid; - private Enter enterPanel; - - public Reset(int[][] grid, Enter enterPanel) { - this.grid = grid; - this.enterPanel = enterPanel; - } - - @Override - public void actionPerformed(ActionEvent e) { - // Réinitialiser la grille en copiant la grille initiale - for (int i = 0; i < grid.length; i++) { - System.arraycopy(enterPanel.getInitialGrid()[i], 0, grid[i], 0, grid[i].length); - } - // Redessiner le panneau - enterPanel.repaint(); - } -} diff --git a/Resolve.class b/Resolveur.class similarity index 67% rename from Resolve.class rename to Resolveur.class index 4e532ce490f784acf4752ebdca3d04eb5ecafe87..fe239e32db23f8c2e829c59bd792d5b6303c8ee9 100644 GIT binary patch delta 92 zcmX@dcAbsm)W2Q(7#J8#CUQ7(@D-&N=a;4wP4rXcJkZAk0E!(PLI3~& delta 107 zcmcc4c8-nX)W2Q(7#JALCvrHlau?_4luZm&_2tei4ol3*O!3VxOJ!u>)QFDu1Om+{ zMh33n{L-T2RJY6=paf4)Do97FURGjRA`b%_13M1`9|J!R0~Z4~BLh2BcH_xDCIIk| B9zFm7 diff --git a/Resolve.java b/Resolveur.java similarity index 60% rename from Resolve.java rename to Resolveur.java index 29e570b..44fd1e6 100644 --- a/Resolve.java +++ b/Resolveur.java @@ -1,40 +1,40 @@ -public class Resolve { - public static boolean solveSudoku(int[][] grid) { +public class Resolveur { + public static boolean resoudreSudoku(int[][] grille) { int row = -1; int col = -1; - boolean isEmpty = true; + boolean estVide = true; // Recherche d'une cellule vide dans la grille - for (int i = 0; i < grid.length; i++) { - for (int j = 0; j < grid[i].length; j++) { - if (grid[i][j] == 0) { + for (int i = 0; i < grille.length; i++) { + for (int j = 0; j < grille[i].length; j++) { + if (grille[i][j] == 0) { row = i; col = j; // Cellule vide trouvée - isEmpty = false; + estVide = false; break; } } - if (!isEmpty) { + if (!estVide) { break; } } - // Si la grille est pleine, le sudoku est résolu - if (isEmpty) { + // Si la grille est pleine, le Sudoku est résolu + if (estVide) { return true; } // Essayer de placer les chiffres de 1 à 9 dans la cellule vide for (int num = 1; num <= 9; num++) { - if (isValidMove(grid, row, col, num)) { - grid[row][col] = num; - // Résoudre récursivement le sudoku - if (solveSudoku(grid)) { + if (estCoupValide(grille, row, col, num)) { + grille[row][col] = num; + // Résoudre récursivement le Sudoku + if (resoudreSudoku(grille)) { return true; } // Annuler la valeur si la solution n'est pas possible - grid[row][col] = 0; + grille[row][col] = 0; } } // Aucune solution n'est possible pour cette cellule @@ -42,17 +42,17 @@ public class Resolve { } // Vérifie si un nombre peut être placé dans une cellule spécifique - private static boolean isValidMove(int[][] grid, int row, int col, int num) { + private static boolean estCoupValide(int[][] grille, int row, int col, int num) { // Vérifie la ligne for (int x = 0; x < 9; x++) { - if (grid[row][x] == num) { + if (grille[row][x] == num) { return false; } } // Vérifie la colonne for (int y = 0; y < 9; y++) { - if (grid[y][col] == num) { + if (grille[y][col] == num) { return false; } } @@ -62,7 +62,7 @@ public class Resolve { int regionColStart = col - col % 3; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { - if (grid[i + regionRowStart][j + regionColStart] == num) { + if (grille[i + regionRowStart][j + regionColStart] == num) { return false; } } diff --git a/SaisieGrille$1.class b/SaisieGrille$1.class new file mode 100644 index 0000000000000000000000000000000000000000..5ad4860d1700e487ca613cdc54e233c936d0f430 GIT binary patch literal 1938 zcma)7-%}e!9RF-cxNyCeB!Cqg=&4Z?pb5l^3Z=D8p{7DXsn8a+F3A!OE_dhM1!!M= z?3<7FtuHMz&UDJOX{L_8;FEun59)U>ASuO}W+waH@2}m@_q(6n`}6M?zXLdny9z$+ zKtImP;Ug8NF{A5Ipm!c?0<#H60QlC{v zW;iiD&kfHIR|5AqdCnP@;h$&dPQUD;ybLWCF4$#SrgPe`#I;&=S-98vvRqiJ+BHuU zOrx|e$_)MK={3H=b9~d!i49@-xf$u7l+$s!(D8Ynm)2*v6XXY27Zu!~5(x3UU2{uf z%8(1kTM=gEqO|>_RWfbQuqrdcU$x5`Qn*PNT0=FwgLgIPcw2gJDOl97gl{x_D~IoJ zTf_Ibt$=G-Mv38MfY;u-EZWH^i>$sNs2-DcrxS36 ztJf^uva8Fk$ZFWa9fte@osez`32KAl9Pa5=yKJl&6x{-uyLx$ddxh8hED@-+<*5-m zgQ8^#w_tM56CT5N7SkSwC~<$=;bFRV@k78Qu4KCSI{70qKkD22J?T!rnnl}n1>JiY zK7-=OVoc&k&r$H@W3ku2yxgYiFwEfb2rkN2&fBCrlDj$^5N?iJ@>TFw?aiX))cnf^ zH*LBHV=d1>!LB;CCGUSrn`W2S=u#cgIjSLkz<{FVi;84S)ZwltNd2D@sF8{*98P7@ z0us**(ScXQKBCO)B3huQqn{paAQX$qX9OTgZ;G_gKZW<`&3&I{ACTTgvU6bY8A1a? z&(JpT9N{NqV&nwcNdj-tm`0|V#HJ{voveQh))9&2%?Xn2B+n=BV<#Ewcz|E}?&DFP zoIMzLicntz%A%Yk8;CCMpyOAlH=pBJLaXDrv^Q{~j?P5vKQ%7Z1gUj&)zRII>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1=`98AzmE_sI|$w;zcYiP%{2Hx^Xz(Yrc(}-+TV?2>TO}M` z4=}@HFVCaxCeN^mvef~cv^FoVbR|IGbg`NJujPno_%yMj{+PK!RaTsHp&LgHVfY4JZ&kAA#YZY=fZqduwX z_~EOR+P7TR-hu?b|3Bcm-M}BPq_U1{Z+F+Y1G_?Zje3SndNb-9nhCI!K~_-5?zM4N Kc}U~TzyAOa&()Fu literal 0 HcmV?d00001 diff --git a/SaisieGrille.java b/SaisieGrille.java new file mode 100644 index 0000000..aa1947b --- /dev/null +++ b/SaisieGrille.java @@ -0,0 +1,87 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; + +public class SaisieGrille extends JPanel { + private static final int TAILLE_GRILLE = 3; + private static final int TAILLE_REGION = 3; + private static final int TAILLE_CELLULE = 50; + private int[][] grille; + private int[][] grilleInitiale; // Pour stocker la grille initiale + private int ligneSelectionnee = -1; + private int colonneSelectionnee = -1; + + public SaisieGrille(int[][] grille) { + this.grille = grille; + // Copie de la grille initiale + this.grilleInitiale = new int[grille.length][grille[0].length]; + for (int i = 0; i < grille.length; i++) { + for (int j = 0; j < grille[i].length; j++) { + this.grilleInitiale[i][j] = grille[i][j]; + } + } + setPreferredSize(new Dimension(TAILLE_GRILLE * TAILLE_REGION * TAILLE_CELLULE, TAILLE_GRILLE * TAILLE_REGION * TAILLE_CELLULE)); + setFocusable(true); // Permet au JPanel de recevoir les événements de souris + + addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + int x = e.getX() / TAILLE_CELLULE; + int y = e.getY() / TAILLE_CELLULE; + if (x >= 0 && x < TAILLE_GRILLE * TAILLE_REGION && y >= 0 && y < TAILLE_GRILLE * TAILLE_REGION) { + ligneSelectionnee = y; + colonneSelectionnee = x; + System.out.println("Case sélectionnée : (" + ligneSelectionnee + ", " + colonneSelectionnee + ")"); + if (grilleInitiale[ligneSelectionnee][colonneSelectionnee] == 0) { // Ne permet la modification que pour les cellules vides + String valeurStr = JOptionPane.showInputDialog(null, "Entrez la valeur pour la cellule sélectionnée :"); + try { + int valeur = Integer.parseInt(valeurStr); + grille[ligneSelectionnee][colonneSelectionnee] = valeur; + repaint(); + } catch (NumberFormatException ex) { + JOptionPane.showMessageDialog(null, "Saisie invalide. Veuillez entrer un nombre."); + } + } else { + JOptionPane.showMessageDialog(null, "Vous ne pouvez pas modifier la valeur par défaut."); + } + } + } + }); + } + + public int[][] getGrilleInitiale() { + return grilleInitiale; + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + // Dessiner les contours de la grille (en gras) + Graphics2D g2d = (Graphics2D) g; + Stroke ancienStroke = g2d.getStroke(); // Sauvegarder le style de ligne précédent + g2d.setStroke(new BasicStroke(4)); // Épaisseur de ligne de 4 pixels + + for (int i = 0; i <= TAILLE_GRILLE * TAILLE_REGION; i++) { + if (i % TAILLE_REGION == 0) { + g2d.drawLine(0, i * TAILLE_CELLULE, TAILLE_GRILLE * TAILLE_REGION * TAILLE_CELLULE, i * TAILLE_CELLULE); + g2d.drawLine(i * TAILLE_CELLULE, 0, i * TAILLE_CELLULE, TAILLE_GRILLE * TAILLE_REGION * TAILLE_CELLULE); + } + } + + // Rétablir le style de ligne précédent + g2d.setStroke(ancienStroke); + + // Dessiner les cellules de la grille + for (int i = 0; i < TAILLE_GRILLE * TAILLE_REGION; i++) { + for (int j = 0; j < TAILLE_GRILLE * TAILLE_REGION; j++) { + g.setColor(Color.BLACK); + g.drawRect(j * TAILLE_CELLULE, i * TAILLE_CELLULE, TAILLE_CELLULE, TAILLE_CELLULE); + int valeur = grille[i][j]; + if (valeur != 0) { + g.drawString(String.valueOf(valeur), j * TAILLE_CELLULE + TAILLE_CELLULE / 2, i * TAILLE_CELLULE + TAILLE_CELLULE / 2); + } + } + } + } +} diff --git a/SudokuDraw.class b/SudokuDraw.class deleted file mode 100644 index bff4ac38dcd852c9133256917ebddd87cad6a334..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1275 zcmZ8g-*XdH7(KVU+fBCHHcbh&)TqS*X%ZRjO}b}Rt>6diMHjqLCM=|d#>#U0!K5oyVgCc zVC@HmP2XzYaT=W!Sz^2%SdHB+t9_7Z)V;3Xuq%!%Gg+;>c@;DU+QFfTAYNH`pzSQa=k@UB}Or%?}lZ`YQ&@0wV} zMHBB~O~<;463RL@OjNL`<9!oVTrzPPwS!4MD|Gf9_jcjZRm-(olq@5+(=ydis6@vO zuKM;Z+xP8e-T9om%?v3r*dUZd%~WJ=oH@}roN|a9`9fx_No98I1_jpHDe5&b*r?>S zJfB0X*Vamx1rjf=AdIXCObxh)nh3<$_aJk6sBM%Y2TO!WEsNW77B0>1_vD+pa!VkU zsV+u+h6wCr$WagJhr16`Kp%>VF9LwJ@PzKW15czJ1N zzCv^n8Y945whxib{fv?9V<^|B#2@_n(0Uks$gsexJd-le}jd*l1>!wXiYZKdl=70NYRN2 zA7DNrsFJ`rB7)jfw1{wD5fA=-lzW7U9wu2i`x8cm%6&r!w- zMf{MSCjED@fKM6u0w?h$PT?zL@GTbcBk`~F|Bll*&T47I|HiD2n8>I9g7%!obBu|z NwE0oW*TeP;{{bsb4uJpw diff --git a/SudokuDraw.java b/SudokuDraw.java deleted file mode 100644 index d6216e3..0000000 --- a/SudokuDraw.java +++ /dev/null @@ -1,46 +0,0 @@ -import javax.swing.*; -import java.awt.*; - -public class SudokuDraw extends JPanel { - private static final int GRID_SIZE = 3; - private static final int REGION_SIZE = 3; - private static final int CELL_SIZE = 50; - - private int[][] grid; - - public SudokuDraw(int[][] grid) { - this.grid = grid; - setPreferredSize(new Dimension(GRID_SIZE * REGION_SIZE * CELL_SIZE, GRID_SIZE * REGION_SIZE * CELL_SIZE)); - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - Graphics2D g2d = (Graphics2D) g; - // Définir l'épaisseur de la ligne - g2d.setStroke(new BasicStroke(20)); // Épaisseur de ligne de 4 pixels - - // Dessiner les lignes de la grille (en gras pour les contours) - for (int i = 0; i <= GRID_SIZE * REGION_SIZE; i++) { - if (i % REGION_SIZE == 0) { - g2d.drawRect(0, i * CELL_SIZE - 2, GRID_SIZE * REGION_SIZE * CELL_SIZE, 4); - g2d.drawRect(i * CELL_SIZE - 2, 0, 4, GRID_SIZE * REGION_SIZE * CELL_SIZE); - } else { - g2d.drawRect(0, i * CELL_SIZE - 1, GRID_SIZE * REGION_SIZE * CELL_SIZE, 2); - g2d.drawRect(i * CELL_SIZE - 1, 0, 2, GRID_SIZE * REGION_SIZE * CELL_SIZE); - } - } - - // Dessiner les valeurs de la grille - g.setColor(Color.BLACK); - for (int i = 0; i < grid.length; i++) { - for (int j = 0; j < grid[i].length; j++) { - int value = grid[i][j]; - if (value != 0) { - g.drawString(String.valueOf(value), j * CELL_SIZE + CELL_SIZE / 2, i * CELL_SIZE + CELL_SIZE / 2); - } - } - } - } -} diff --git a/SudokuGenerator.class b/SudokuGenerator.class deleted file mode 100644 index 0511a21b740143845a73aa087242f0fd692ebb99..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2861 zcmb7G-)~db9sk_;-g}&j0VlyBCb)Iit~dsg5!%o?khX*$4Ft^M6fm@-7yHIGIKI}k z-Slbd1Mhp8G*PLVMjs+geP9m_5tQwTZkjgjWzrt1O?#R4Hx#k4&-YwA38<}td_UjsIrskYzxRI&;0SIwcmb0NhZSB^c-?`CNg1YOIHK@|!kZ5Ik#i8mvB!Wjo6I4kmb8P3UYULmh=!GL|V z)~K~-3`8c6y-rE2;x)X$ZF{GKTG@b=8M}IQ&Okiy z+_H#H1^)7>nrLn>wB6Fpb8b^xD*RYs!N9g!OVlp9buqUyv>v-+z^Szs{FSa$iIif6 z0^QVFvwpp^+~{uddBLmH{NA%u@H;`t3uEpobjtqC&gl@NAB^8{KXPMu5orT`f-|Dg zj)?f1Ul(vlZ=BuBJHB3&U*Ju8Ku#BdEC#_%#;iNQrWhU+LPlwHR>GdqD6|72liIKccC@PgO1|kePSo7GPwDQ=ytZ^#+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9+VmnS@ z7f!Q6?-Icr5u7FKC&~1AjbaGqf1nf&lB+$0Vuon=D*S#lsmam*3r&G&7K!FPqPa*k zmx$&v(Oe;#MWXrO`_S;6+(q*>xrvg}#ZkL%SC5U_O}jcHJmt*2asc<*AKt+msVO^Q zr)0TL9~^sJjvGssG!rUhPFAGOCUt+)$LZ@WWt$>U@I%CA@na}skRKx{EU|PIwqO-g xY~dN)z}u*k-X%7<$0l#;6kdV-6bap9hQYo%s2kEDy)R0o!+&P;Bi$s2{s*BZMT!6b diff --git a/SudokuGenerator.java b/SudokuGenerator.java deleted file mode 100644 index 6ffa151..0000000 --- a/SudokuGenerator.java +++ /dev/null @@ -1,114 +0,0 @@ -import javax.swing.*; -import java.io.*; - -public class SudokuGenerator { - public static int[][] generateGrid() { - // grille par défaut - int[][] grid = { - {0, 0, 0, 9, 0, 5, 0, 0, 4}, - {5, 0, 3, 0, 0, 4, 0, 8, 7}, - {0, 0, 0, 7, 0, 0, 6, 0, 3}, - {9, 0, 0, 0, 3, 4, 0, 8, 0}, - {0, 4, 0, 0, 1, 0, 0, 7, 0}, - {0, 2, 0, 5, 7, 0, 0, 0, 6}, - {4, 0, 9, 0, 0, 2, 0, 0, 0}, - {6, 0, 7, 9, 0, 3, 0, 2, 1}, - {2, 0, 0, 6, 5, 0, 0, 0, 0} - }; - - return grid; - } - - public static int[][] readGridFromFile() { - int[][] grid = new int[9][9]; - JFileChooser fileChooser = new JFileChooser(); - int result = fileChooser.showOpenDialog(null); - if (result == JFileChooser.APPROVE_OPTION) { - File selectedFile = fileChooser.getSelectedFile(); - try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) { - for (int i = 0; i < 9; i++) { - String line = reader.readLine(); - // Vérifier la longueur de la ligne lue - if (line.length() != 9) { - JOptionPane.showMessageDialog(null, "Invalid file format. Please select a file with correct Sudoku grid format."); - return generateGrid(); // Charger la grille par défaut en cas d'erreur - } - for (int j = 0; j < 9; j++) { - char ch = line.charAt(j); - if (ch >= '1' && ch <= '9') { - grid[i][j] = Character.getNumericValue(ch); - } else { - grid[i][j] = 0; - } - } - } - if (!isGridValid(grid)) { - JOptionPane.showMessageDialog(null, "Invalid Sudoku grid. Loading default grid."); - return generateGrid(); // Charger la grille par défaut en cas de grille invalide - } - } catch (IOException e) { - e.printStackTrace(); - } - } - return grid; - } - - // Méthode pour vérifier si la grille est valide - private static boolean isGridValid(int[][] grid) { - for (int i = 0; i < 9; i++) { - if (!isRowValid(grid, i) || !isColumnValid(grid, i) || !isRegionValid(grid, i)) { - return false; - } - } - return true; - } - - // Méthode pour vérifier s'il n'y a pas de chiffres en double sur une ligne donnée - private static boolean isRowValid(int[][] grid, int row) { - boolean[] seen = new boolean[10]; // Tableau pour suivre les chiffres déjà rencontrés - for (int i = 0; i < 9; i++) { - int num = grid[row][i]; - if (num != 0) { - if (seen[num]) { - return false; // Le chiffre est déjà apparu sur cette ligne - } - seen[num] = true; - } - } - return true; // Aucun chiffre en double sur la ligne - } - - // Méthode pour vérifier s'il n'y a pas de chiffres en double sur une colonne donnée - private static boolean isColumnValid(int[][] grid, int col) { - boolean[] seen = new boolean[10]; // Tableau pour suivre les chiffres déjà rencontrés - for (int i = 0; i < 9; i++) { - int num = grid[i][col]; - if (num != 0) { - if (seen[num]) { - return false; // Le chiffre est déjà apparu sur cette colonne - } - seen[num] = true; - } - } - return true; // Aucun chiffre en double sur la colonne - } - - // Méthode pour vérifier s'il n'y a pas de chiffres en double dans une région donnée - private static boolean isRegionValid(int[][] grid, int region) { - int rowOffset = (region / 3) * 3; - int colOffset = (region % 3) * 3; - boolean[] seen = new boolean[10]; // Tableau pour suivre les chiffres déjà rencontrés - for (int i = rowOffset; i < rowOffset + 3; i++) { - for (int j = colOffset; j < colOffset + 3; j++) { - int num = grid[i][j]; - if (num != 0) { - if (seen[num]) { - return false; // Le chiffre est déjà apparu dans cette région - } - seen[num] = true; - } - } - } - return true; // Aucun chiffre en double dans la région - } -}