16 Commits

Author SHA1 Message Date
68d577a99a Merge pull request 'finished console interface' (#37) from osekour into master
All checks were successful
Linux arm64 / Build (push) Successful in 23m58s
Reviewed-on: #37
2025-02-01 20:48:26 +00:00
fa3124220d finished console interface
All checks were successful
Linux arm64 / Build (push) Successful in 5m14s
2025-02-01 20:43:01 +00:00
3a009256c5 Fixes #12
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2025-02-01 21:16:36 +01:00
d09bf6e9ce feat: allow user to be wrong
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2025-02-01 21:12:13 +01:00
5da915932d Fixes #31
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2025-02-01 21:00:59 +01:00
da422e78b8 Fixes #30
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2025-02-01 20:59:06 +01:00
f0a0a8e328 Fixes #23
All checks were successful
Linux arm64 / Build (push) Successful in 37s
2025-02-01 20:55:08 +01:00
436b641269 Fixes #34 2025-02-01 20:47:40 +01:00
34a59546e6 remove unused import
Some checks failed
Linux arm64 / Build (push) Has been cancelled
2025-02-01 20:46:06 +01:00
9e2421accf Fixes #25 2025-02-01 20:45:56 +01:00
52ca8b208c fix: sudoku save
All checks were successful
Linux arm64 / Build (push) Successful in 23m59s
2025-02-01 16:11:38 +00:00
Janet-Doe
140d37fbd9 update console interface
All checks were successful
Linux arm64 / Build (push) Successful in 37s
2025-02-01 15:51:45 +01:00
Janet-Doe
2b3581a400 fix
All checks were successful
Linux arm64 / Build (push) Successful in 37s
2025-02-01 14:56:45 +01:00
a6b1fae230 Merge branch 'gradle'
Some checks failed
Linux arm64 / Build (push) Failing after 23s
2025-02-01 14:49:54 +01:00
Janet-Doe
8c672e24ad merged version
Some checks failed
Linux arm64 / Build (push) Failing after 22s
2025-02-01 14:32:11 +01:00
Janet-Doe
815756b5e9 functional multidoku printer
# Conflicts:
#	app/src/main/java/sudoku/io/ConsoleInterface.java
#	app/src/main/java/sudoku/solver/Solver.java
2025-02-01 14:29:54 +01:00
91 changed files with 1087 additions and 1748 deletions

View File

@@ -33,7 +33,7 @@ dependencies {
application { application {
// Define the main class for the application. // Define the main class for the application.
mainClass = 'org.polytech.ryuk.gui.Main' mainClass = 'gui.Main'
} }
// Add libraries into the final jar // Add libraries into the final jar

View File

@@ -1,572 +0,0 @@
{
"cells": [
{
"blockID": 0,
"symbolIndex": -1
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 1
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 2,
"symbolIndex": -1
},
{
"blockID": 2,
"symbolIndex": -1
},
{
"blockID": 2,
"symbolIndex": -1
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 2
},
{
"blockID": 0,
"symbolIndex": -1
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 4
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 1,
"symbolIndex": 0
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 2,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 2,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 2,
"symbolIndex": -1
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 3
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 0,
"symbolIndex": -1
},
{
"blockID": 1,
"immutable": true,
"symbolIndex": 5
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 1,
"immutable": true,
"symbolIndex": 7
},
{
"blockID": 2,
"immutable": true,
"symbolIndex": 2
},
{
"blockID": 2,
"symbolIndex": -1
},
{
"blockID": 2,
"immutable": true,
"symbolIndex": 4
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 2
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 3
},
{
"blockID": 4,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 5,
"symbolIndex": -1
},
{
"blockID": 5,
"symbolIndex": -1
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 1
},
{
"blockID": 3,
"symbolIndex": -1
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 4
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 5
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 5,
"symbolIndex": -1
},
{
"blockID": 3,
"symbolIndex": -1
},
{
"blockID": 3,
"symbolIndex": -1
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 4,
"immutable": true,
"symbolIndex": 7
},
{
"blockID": 4,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 4
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 5
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 3
},
{
"blockID": 6,
"immutable": true,
"symbolIndex": 4
},
{
"blockID": 6,
"immutable": true,
"symbolIndex": 3
},
{
"blockID": 6,
"symbolIndex": -1
},
{
"blockID": 7,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 7,
"symbolIndex": -1
},
{
"blockID": 7,
"immutable": true,
"symbolIndex": 1
},
{
"blockID": 8,
"immutable": true,
"symbolIndex": 5
},
{
"blockID": 8,
"symbolIndex": -1
},
{
"blockID": 8,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 6,
"immutable": true,
"symbolIndex": 1
},
{
"blockID": 6,
"symbolIndex": -1
},
{
"blockID": 6,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 7,
"immutable": true,
"symbolIndex": 3
},
{
"blockID": 7,
"symbolIndex": -1
},
{
"blockID": 7,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 8,
"symbolIndex": -1
},
{
"blockID": 8,
"symbolIndex": -1
},
{
"blockID": 8,
"symbolIndex": -1
},
{
"blockID": 6,
"symbolIndex": -1
},
{
"blockID": 6,
"immutable": true,
"symbolIndex": 0
},
{
"blockID": 6,
"symbolIndex": -1
},
{
"blockID": 7,
"immutable": true,
"symbolIndex": 7
},
{
"blockID": 7,
"symbolIndex": -1
},
{
"blockID": 7,
"symbolIndex": -1
},
{
"blockID": 8,
"immutable": true,
"symbolIndex": 1
},
{
"blockID": 8,
"symbolIndex": -1
},
{
"blockID": 8,
"immutable": true,
"symbolIndex": 8
}
],
"blocks": [
{"cellIDs": [
0,
1,
2,
9,
10,
11,
18,
19,
20
]},
{"cellIDs": [
3,
4,
5,
12,
13,
14,
21,
22,
23
]},
{"cellIDs": [
6,
7,
8,
15,
16,
17,
24,
25,
26
]},
{"cellIDs": [
27,
28,
29,
36,
37,
38,
45,
46,
47
]},
{"cellIDs": [
30,
31,
32,
39,
40,
41,
48,
49,
50
]},
{"cellIDs": [
33,
34,
35,
42,
43,
44,
51,
52,
53
]},
{"cellIDs": [
54,
55,
56,
63,
64,
65,
72,
73,
74
]},
{"cellIDs": [
57,
58,
59,
66,
67,
68,
75,
76,
77
]},
{"cellIDs": [
60,
61,
62,
69,
70,
71,
78,
79,
80
]}
],
"multidoku": [{
"blockWidth": 3,
"cells": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80
],
"blocks": [
0,
1,
2,
3,
4,
5,
6,
7,
8
],
"constraints": [
0,
1,
2
]
}]
}

View File

@@ -1,572 +0,0 @@
{
"cells": [
{
"blockID": 0,
"symbolIndex": -1
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 1
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 2,
"symbolIndex": -1
},
{
"blockID": 2,
"symbolIndex": -1
},
{
"blockID": 2,
"symbolIndex": -1
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 2
},
{
"blockID": 0,
"symbolIndex": -1
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 4
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 2,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 2,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 2,
"symbolIndex": -1
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 3
},
{
"blockID": 0,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 0,
"symbolIndex": -1
},
{
"blockID": 1,
"immutable": true,
"symbolIndex": 5
},
{
"blockID": 1,
"symbolIndex": -1
},
{
"blockID": 1,
"immutable": true,
"symbolIndex": 7
},
{
"blockID": 2,
"immutable": true,
"symbolIndex": 2
},
{
"blockID": 2,
"symbolIndex": -1
},
{
"blockID": 2,
"immutable": true,
"symbolIndex": 4
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 2
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 3
},
{
"blockID": 4,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 5,
"symbolIndex": -1
},
{
"blockID": 5,
"symbolIndex": -1
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 1
},
{
"blockID": 3,
"symbolIndex": -1
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 4
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 5
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 5,
"symbolIndex": -1
},
{
"blockID": 3,
"symbolIndex": -1
},
{
"blockID": 3,
"symbolIndex": -1
},
{
"blockID": 3,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 4,
"symbolIndex": -1
},
{
"blockID": 4,
"immutable": true,
"symbolIndex": 7
},
{
"blockID": 4,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 4
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 5
},
{
"blockID": 5,
"immutable": true,
"symbolIndex": 3
},
{
"blockID": 6,
"immutable": true,
"symbolIndex": 4
},
{
"blockID": 6,
"immutable": true,
"symbolIndex": 3
},
{
"blockID": 6,
"symbolIndex": -1
},
{
"blockID": 7,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 7,
"symbolIndex": -1
},
{
"blockID": 7,
"immutable": true,
"symbolIndex": 1
},
{
"blockID": 8,
"immutable": true,
"symbolIndex": 5
},
{
"blockID": 8,
"symbolIndex": -1
},
{
"blockID": 8,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 6,
"immutable": true,
"symbolIndex": 1
},
{
"blockID": 6,
"symbolIndex": -1
},
{
"blockID": 6,
"immutable": true,
"symbolIndex": 8
},
{
"blockID": 7,
"immutable": true,
"symbolIndex": 3
},
{
"blockID": 7,
"symbolIndex": -1
},
{
"blockID": 7,
"immutable": true,
"symbolIndex": 6
},
{
"blockID": 8,
"symbolIndex": -1
},
{
"blockID": 8,
"symbolIndex": -1
},
{
"blockID": 8,
"symbolIndex": -1
},
{
"blockID": 6,
"symbolIndex": -1
},
{
"blockID": 6,
"immutable": true,
"symbolIndex": 0
},
{
"blockID": 6,
"symbolIndex": -1
},
{
"blockID": 7,
"immutable": true,
"symbolIndex": 7
},
{
"blockID": 7,
"symbolIndex": -1
},
{
"blockID": 7,
"symbolIndex": -1
},
{
"blockID": 8,
"immutable": true,
"symbolIndex": 1
},
{
"blockID": 8,
"symbolIndex": -1
},
{
"blockID": 8,
"immutable": true,
"symbolIndex": 8
}
],
"blocks": [
{"cellIDs": [
0,
1,
2,
9,
10,
11,
18,
19,
20
]},
{"cellIDs": [
3,
4,
5,
12,
13,
14,
21,
22,
23
]},
{"cellIDs": [
6,
7,
8,
15,
16,
17,
24,
25,
26
]},
{"cellIDs": [
27,
28,
29,
36,
37,
38,
45,
46,
47
]},
{"cellIDs": [
30,
31,
32,
39,
40,
41,
48,
49,
50
]},
{"cellIDs": [
33,
34,
35,
42,
43,
44,
51,
52,
53
]},
{"cellIDs": [
54,
55,
56,
63,
64,
65,
72,
73,
74
]},
{"cellIDs": [
57,
58,
59,
66,
67,
68,
75,
76,
77
]},
{"cellIDs": [
60,
61,
62,
69,
70,
71,
78,
79,
80
]}
],
"multidoku": [{
"blockWidth": 3,
"cells": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53,
54,
55,
56,
57,
58,
59,
60,
61,
62,
63,
64,
65,
66,
67,
68,
69,
70,
71,
72,
73,
74,
75,
76,
77,
78,
79,
80
],
"blocks": [
0,
1,
2,
3,
4,
5,
6,
7,
8
],
"constraints": [
0,
1,
2
]
}]
}

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.common; package common;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.common; package common;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.game; package game;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
@@ -7,7 +7,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.MultiDoku;
public class Game { public class Game {

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.game; package game;
import java.io.Serializable; import java.io.Serializable;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui; package gui;
import imgui.ImGui; import imgui.ImGui;
import imgui.ImVec2; import imgui.ImVec2;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui; package gui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui; package gui;
import imgui.ImFont; import imgui.ImFont;
import imgui.ImFontConfig; import imgui.ImFontConfig;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui; package gui;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;

View File

@@ -1,8 +1,7 @@
package org.polytech.ryuk.gui; package gui;
import org.polytech.ryuk.gui.menu.MainMenu;
import org.polytech.ryuk.gui.menu.StateMachine;
import gui.menu.MainMenu;
import gui.menu.StateMachine;
import imgui.app.Application; import imgui.app.Application;
import imgui.app.Configuration; import imgui.app.Configuration;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui; package gui;
public class Options { public class Options {

View File

@@ -1,15 +1,15 @@
package org.polytech.ryuk.gui; package gui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.polytech.ryuk.sudoku.structure.Block; import sudoku.structure.Block;
import org.polytech.ryuk.sudoku.structure.Cell; import sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.Coordinate; import sudoku.structure.Coordinate;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.MultiDoku;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.Sudoku;
public class RenderableMultidoku { public class RenderableMultidoku {
@@ -47,8 +47,6 @@ public class RenderableMultidoku {
return cells.get(index); return cells.get(index);
} }
private static record PositionConstraint(Sudoku sudoku1, Sudoku sudoku2, Coordinate offset) { private static record PositionConstraint(Sudoku sudoku1, Sudoku sudoku2, Coordinate offset) {
} }

View File

@@ -1,10 +1,10 @@
package org.polytech.ryuk.gui; package gui;
import java.util.List; import java.util.List;
import org.polytech.ryuk.sudoku.constraint.Constraint; import sudoku.constraint.Constraint;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.MultiDoku;
import org.polytech.ryuk.sudoku.structure.SudokuFactory;; import sudoku.structure.SudokuFactory;;
public enum SudokuType { public enum SudokuType {

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui; package gui;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui.menu; package gui.menu;
import imgui.ImGui; import imgui.ImGui;

View File

@@ -1,12 +1,11 @@
package org.polytech.ryuk.gui.menu; package gui.menu;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import org.polytech.ryuk.network.client.Client;
import org.polytech.ryuk.network.server.Server;
import imgui.ImGui; import imgui.ImGui;
import network.client.Client;
import network.server.Server;
public class ConnexionStatusView extends BaseView { public class ConnexionStatusView extends BaseView {

View File

@@ -1,12 +1,11 @@
package org.polytech.ryuk.gui.menu; package gui.menu;
import org.polytech.ryuk.game.Player;
import org.polytech.ryuk.gui.ColorGenerator;
import org.polytech.ryuk.gui.widget.SudokuRenderer;
import org.polytech.ryuk.sudoku.structure.MultiDoku;
import game.Player;
import gui.ColorGenerator;
import gui.widget.SudokuRenderer;
import imgui.ImGui; import imgui.ImGui;
import imgui.ImVec4; import imgui.ImVec4;
import sudoku.structure.MultiDoku;
public class EndGameView extends BaseView { public class EndGameView extends BaseView {

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui.menu; package gui.menu;
import imgui.ImGui; import imgui.ImGui;
import imgui.ImVec2; import imgui.ImVec2;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui.menu; package gui.menu;
import java.io.IOException; import java.io.IOException;
@@ -20,7 +20,8 @@ public class MultiMenu extends BaseView {
private void renderCreate() { private void renderCreate() {
ImVec2 displaySize = ImGui.getIO().getDisplaySize(); ImVec2 displaySize = ImGui.getIO().getDisplaySize();
ImGui.beginChild("##CreateGame", new ImVec2(displaySize.x / 2.0f, displaySize.y * 8.0f / 9.0f)); ImGui.beginChild("##CreateGame", new ImVec2(displaySize.x / 2.0f, displaySize.y * 8.0f / 9.0f));
ImGui.inputInt("Port", port); if (ImGui.inputInt("Port", port))
port.set(Math.clamp(port.get(), 1, 65535));
if (ImGui.button("Créer")) { if (ImGui.button("Créer")) {
try { try {
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, (short) port.get())); this.stateMachine.pushState(new ConnexionStatusView(stateMachine, (short) port.get()));
@@ -35,12 +36,12 @@ public class MultiMenu extends BaseView {
ImVec2 displaySize = ImGui.getIO().getDisplaySize(); ImVec2 displaySize = ImGui.getIO().getDisplaySize();
ImGui.beginChild("##JoinGame", new ImVec2(displaySize.x / 2.0f, displaySize.y * 8.0f / 9.0f)); ImGui.beginChild("##JoinGame", new ImVec2(displaySize.x / 2.0f, displaySize.y * 8.0f / 9.0f));
ImGui.inputText("Adresse", address); ImGui.inputText("Adresse", address);
ImGui.inputInt("Port", port); if (ImGui.inputInt("Port", port))
port.set(Math.clamp(port.get(), 1, 65535));
if (ImGui.button("Rejoindre")) { if (ImGui.button("Rejoindre")) {
try { try {
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, address.get(), (short) port.get())); this.stateMachine.pushState(new ConnexionStatusView(stateMachine, address.get(), (short) port.get()));
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@@ -1,18 +1,17 @@
package org.polytech.ryuk.gui.menu; package gui.menu;
import org.polytech.ryuk.game.Player;
import org.polytech.ryuk.gui.widget.LeaderboardRenderer;
import org.polytech.ryuk.gui.widget.MultiPlayerCompleteProgress;
import org.polytech.ryuk.gui.widget.SudokuRenderer;
import org.polytech.ryuk.gui.widget.TimerRenderer;
import org.polytech.ryuk.network.client.Client;
import org.polytech.ryuk.network.server.Server;
import org.polytech.ryuk.sudoku.solver.BacktrackingSolver;
import org.polytech.ryuk.sudoku.solver.Solver;
import org.polytech.ryuk.sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.MultiDoku;
import game.Player;
import gui.widget.LeaderboardRenderer;
import gui.widget.MultiPlayerCompleteProgress;
import gui.widget.SudokuRenderer;
import gui.widget.TimerRenderer;
import imgui.ImGui; import imgui.ImGui;
import network.client.Client;
import network.server.Server;
import sudoku.solver.BacktrackingSolver;
import sudoku.solver.Solver;
import sudoku.structure.Cell;
import sudoku.structure.MultiDoku;
public class MultiPlayerDokuView extends BaseView { public class MultiPlayerDokuView extends BaseView {

View File

@@ -1,13 +1,12 @@
package org.polytech.ryuk.gui.menu; package gui.menu;
import org.polytech.ryuk.game.Player;
import org.polytech.ryuk.gui.widget.SudokuSelector;
import org.polytech.ryuk.network.client.Client;
import org.polytech.ryuk.network.server.Server;
import org.polytech.ryuk.sudoku.structure.MultiDoku;
import game.Player;
import gui.widget.SudokuSelector;
import imgui.ImGui; import imgui.ImGui;
import imgui.type.ImInt; import imgui.type.ImInt;
import network.client.Client;
import network.server.Server;
import sudoku.structure.MultiDoku;
public class MultiPlayerView extends BaseView { public class MultiPlayerView extends BaseView {
@@ -69,7 +68,8 @@ public class MultiPlayerView extends BaseView {
} }
private void renderTimer() { private void renderTimer() {
ImGui.inputInt("Temps de la partie (minutes)", gameDurationMinutes); if (ImGui.inputInt("Temps de la partie (minutes)", gameDurationMinutes))
gameDurationMinutes.set(Math.clamp(gameDurationMinutes.get(), 1, 90));
} }
@Override @Override

View File

@@ -1,8 +1,7 @@
package org.polytech.ryuk.gui.menu; package gui.menu;
import org.polytech.ryuk.gui.Options;
import org.polytech.ryuk.gui.Symbols;
import gui.Options;
import gui.Symbols;
import imgui.ImGui; import imgui.ImGui;
import imgui.type.ImInt; import imgui.type.ImInt;

View File

@@ -1,9 +1,8 @@
package org.polytech.ryuk.gui.menu; package gui.menu;
import org.polytech.ryuk.gui.widget.SudokuSelector;
import org.polytech.ryuk.sudoku.structure.MultiDoku;
import gui.widget.SudokuSelector;
import imgui.ImGui; import imgui.ImGui;
import sudoku.structure.MultiDoku;
public class SoloMenu extends BaseView { public class SoloMenu extends BaseView {

View File

@@ -1,9 +1,8 @@
package org.polytech.ryuk.gui.menu; package gui.menu;
import java.util.Stack; import java.util.Stack;
import org.polytech.ryuk.gui.AnimatedBackground; import gui.AnimatedBackground;
import imgui.ImGui; import imgui.ImGui;
import imgui.ImVec2; import imgui.ImVec2;
import imgui.flag.ImGuiKey; import imgui.flag.ImGuiKey;

View File

@@ -1,17 +1,18 @@
package org.polytech.ryuk.gui.menu; package gui.menu;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import org.polytech.ryuk.gui.widget.SudokuRenderer; import gui.widget.SudokuRenderer;
import org.polytech.ryuk.sudoku.io.SudokuSerializer;
import org.polytech.ryuk.sudoku.solver.BacktrackingSolver;
import org.polytech.ryuk.sudoku.solver.HumanSolver;
import org.polytech.ryuk.sudoku.solver.MixedSolver;
import org.polytech.ryuk.sudoku.solver.Solver;
import org.polytech.ryuk.sudoku.structure.MultiDoku;
import imgui.ImGui; import imgui.ImGui;
import imgui.ImGuiStyle; import imgui.ImGuiStyle;
import sudoku.io.SudokuSerializer;
import sudoku.solver.BacktrackingSolver;
import sudoku.solver.HintHelper;
import sudoku.solver.HumanSolver;
import sudoku.solver.MixedSolver;
import sudoku.solver.Solver;
import sudoku.solver.HintHelper.Hint;
import sudoku.structure.MultiDoku;
public class SudokuView extends BaseView { public class SudokuView extends BaseView {
@@ -21,6 +22,8 @@ public class SudokuView extends BaseView {
private String lastSavePath = null; private String lastSavePath = null;
private boolean resolved = false; private boolean resolved = false;
// if the solver can't solve
private volatile boolean unresolved = false;
public SudokuView(StateMachine stateMachine, MultiDoku doku) { public SudokuView(StateMachine stateMachine, MultiDoku doku) {
super(stateMachine); super(stateMachine);
@@ -69,10 +72,26 @@ public class SudokuView extends BaseView {
stopResolve(); stopResolve();
} }
private void renderHintButton() {
if (!this.resolved && centeredButton("Indice")) {
Hint hint = HintHelper.getHint(this.doku, new BacktrackingSolver());
assert (hint != null);
hint.cell().setSymbolIndex(hint.newValue());
if (this.doku.isSolved())
this.sudokuRenderer.onResolve.emit();
}
}
private void renderUnsolvableText() {
if (this.unresolved)
ImGui.text("Impossible de résoudre avec l'algorithme actuel !");
}
private void startSolve(Solver solver) { private void startSolve(Solver solver) {
resolveThread = new Thread(() -> { resolveThread = new Thread(() -> {
try { try {
solver.solve(this.doku); unresolved = !solver.solve(this.doku);
} catch (CancellationException e) { } catch (CancellationException e) {
System.out.println("The user is bored !"); System.out.println("The user is bored !");
} }
@@ -80,6 +99,11 @@ public class SudokuView extends BaseView {
}); });
} }
private void renderResolvedText() {
if (this.resolved)
ImGui.text("Bravo !");
}
private void renderSolvePopup() { private void renderSolvePopup() {
if (ImGui.beginPopup("solve")) { if (ImGui.beginPopup("solve")) {
if (ImGui.button("Résoudre avec backtrace")) { if (ImGui.button("Résoudre avec backtrace")) {
@@ -103,16 +127,14 @@ public class SudokuView extends BaseView {
ImGui.beginDisabled(); ImGui.beginDisabled();
if (!this.resolved && centeredButton("Résoudre")) { if (!this.resolved && centeredButton("Résoudre")) {
// beginSolve = true;
ImGui.openPopup("solve"); ImGui.openPopup("solve");
} }
if (resolveThread != null) if (resolveThread != null)
ImGui.endDisabled(); ImGui.endDisabled();
if (this.resolved) { renderResolvedText();
ImGui.text("Bravo !"); renderUnsolvableText();
}
renderSolvePopup(); renderSolvePopup();
} }
@@ -129,9 +151,17 @@ public class SudokuView extends BaseView {
} }
} }
private void renderClearButton() {
if (centeredButton("Effacer")) {
this.doku.clearMutableCells();
}
}
@Override @Override
public void render() { public void render() {
sudokuRenderer.render(); sudokuRenderer.render();
renderHintButton();
renderClearButton();
renderSolveButton(); renderSolveButton();
renderSaveButton(); renderSaveButton();
renderCancelButton(); renderCancelButton();

View File

@@ -1,8 +1,7 @@
package org.polytech.ryuk.gui.widget; package gui.widget;
import org.polytech.ryuk.game.Game;
import org.polytech.ryuk.game.Player;
import game.Game;
import game.Player;
import imgui.ImGui; import imgui.ImGui;
import imgui.ImVec2; import imgui.ImVec2;
import imgui.ImVec4; import imgui.ImVec4;

View File

@@ -1,8 +1,7 @@
package org.polytech.ryuk.gui.widget; package gui.widget;
import org.polytech.ryuk.game.Game;
import org.polytech.ryuk.game.Player;
import game.Game;
import game.Player;
import imgui.ImGui; import imgui.ImGui;
import imgui.ImVec2; import imgui.ImVec2;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui.widget; package gui.widget;
import imgui.ImGui; import imgui.ImGui;
import imgui.ImVec2; import imgui.ImVec2;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui.widget; package gui.widget;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -6,25 +6,24 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.polytech.ryuk.common.ConsumerSignal; import common.ConsumerSignal;
import org.polytech.ryuk.common.Signal; import common.Signal;
import org.polytech.ryuk.gui.ColorGenerator; import gui.ColorGenerator;
import org.polytech.ryuk.gui.ColorGenerator.Color; import gui.Fonts;
import org.polytech.ryuk.gui.Fonts; import gui.Options;
import org.polytech.ryuk.gui.Options; import gui.RenderableMultidoku;
import org.polytech.ryuk.gui.RenderableMultidoku; import gui.Symbols;
import org.polytech.ryuk.gui.Symbols; import gui.ColorGenerator.Color;
import org.polytech.ryuk.sudoku.constraint.Constraint;
import org.polytech.ryuk.sudoku.structure.Block;
import org.polytech.ryuk.sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.MultiDoku;
import org.polytech.ryuk.sudoku.structure.Sudoku;
import imgui.ImGui; import imgui.ImGui;
import imgui.ImVec2; import imgui.ImVec2;
import imgui.ImVec4; import imgui.ImVec4;
import imgui.flag.ImGuiCol; import imgui.flag.ImGuiCol;
import imgui.flag.ImGuiStyleVar; import imgui.flag.ImGuiStyleVar;
import sudoku.constraint.Constraint;
import sudoku.structure.Block;
import sudoku.structure.Cell;
import sudoku.structure.MultiDoku;
import sudoku.structure.Sudoku;
public class SudokuRenderer { public class SudokuRenderer {
@@ -85,7 +84,7 @@ public class SudokuRenderer {
} }
} else { } else {
if (ImGui.button(Options.Symboles.getSymbols().get(i), cellSize)) { if (ImGui.button(Options.Symboles.getSymbols().get(i), cellSize)) {
if (currentCell.trySetValue(i)) currentCell.setSymbolIndex(i);
this.onCellChange.emit(currentCell); this.onCellChange.emit(currentCell);
if (this.doku.getDoku().isSolved()) if (this.doku.getDoku().isSolved())
this.onResolve.emit(); this.onResolve.emit();
@@ -118,6 +117,7 @@ public class SudokuRenderer {
ImGui.sameLine(); ImGui.sameLine();
int index = y * doku.getWidth() + x; int index = y * doku.getWidth() + x;
Cell cell = doku.getCell(x, y); Cell cell = doku.getCell(x, y);
ImGui.beginDisabled(cell == null);
if (cell == null) { if (cell == null) {
ImGui.pushStyleColor(ImGuiCol.Border, TRANSPARENT); ImGui.pushStyleColor(ImGuiCol.Border, TRANSPARENT);
ImGui.pushStyleColor(ImGuiCol.Button, TRANSPARENT); ImGui.pushStyleColor(ImGuiCol.Button, TRANSPARENT);
@@ -142,6 +142,7 @@ public class SudokuRenderer {
currentCell = cell; currentCell = cell;
} }
} }
ImGui.endDisabled();
ImGui.popStyleColor(2); ImGui.popStyleColor(2);
} }
} }

View File

@@ -1,20 +1,19 @@
package org.polytech.ryuk.gui.widget; package gui.widget;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.polytech.ryuk.common.ConsumerSignal; import common.ConsumerSignal;
import org.polytech.ryuk.gui.SudokuType; import gui.SudokuType;
import org.polytech.ryuk.sudoku.constraint.Constraint;
import org.polytech.ryuk.sudoku.structure.Difficulty;
import org.polytech.ryuk.sudoku.structure.MultiDoku;
import org.polytech.ryuk.sudoku.structure.SudokuFactory;
import imgui.ImGui; import imgui.ImGui;
import imgui.extension.imguifiledialog.ImGuiFileDialog; import imgui.extension.imguifiledialog.ImGuiFileDialog;
import imgui.extension.imguifiledialog.flag.ImGuiFileDialogFlags; import imgui.extension.imguifiledialog.flag.ImGuiFileDialogFlags;
import imgui.type.ImBoolean; import imgui.type.ImBoolean;
import imgui.type.ImInt; import imgui.type.ImInt;
import sudoku.constraint.Constraint;
import sudoku.structure.Difficulty;
import sudoku.structure.MultiDoku;
import sudoku.structure.SudokuFactory;
public class SudokuSelector { public class SudokuSelector {
@@ -25,7 +24,7 @@ public class SudokuSelector {
private final ImInt sudokuType = new ImInt(0); private final ImInt sudokuType = new ImInt(0);
private final ImInt difficulty = new ImInt(Difficulty.Medium.ordinal()); private final ImInt difficulty = new ImInt(Difficulty.Easy.ordinal());
private final List<ImBoolean> contraints = new ArrayList<>(); private final List<ImBoolean> contraints = new ArrayList<>();
private final ImInt sudokuSize = new ImInt(3); private final ImInt sudokuSize = new ImInt(3);
@@ -99,7 +98,8 @@ public class SudokuSelector {
SudokuType currentType = SudokuType.values()[sudokuType.get()]; SudokuType currentType = SudokuType.values()[sudokuType.get()];
switch (currentType.getMakerParamCount()) { switch (currentType.getMakerParamCount()) {
case 1: case 1:
ImGui.inputInt("Taille", sudokuSize); if (ImGui.inputInt("Taille", sudokuSize))
sudokuSize.set(Math.clamp(sudokuSize.get(), 1, 10));
if (ImGui.button(confirmMessage)) { if (ImGui.button(confirmMessage)) {
selectSudoku(currentType.createDoku(getConstraints(), sudokuSize.get()), false); selectSudoku(currentType.createDoku(getConstraints(), sudokuSize.get()), false);
} }
@@ -109,8 +109,10 @@ public class SudokuSelector {
break; break;
case 2: case 2:
ImGui.inputInt("Largeur", sudokuHeight); if (ImGui.inputInt("Longueur", sudokuWidth))
ImGui.inputInt("Longueur", sudokuWidth); sudokuWidth.set(Math.clamp(sudokuWidth.get(), 1, 10));
if (ImGui.inputInt("Hauteur", sudokuHeight))
sudokuHeight.set(Math.clamp(sudokuHeight.get(), 1, 10));
if (ImGui.button(confirmMessage)) { if (ImGui.button(confirmMessage)) {
selectSudoku(currentType.createDoku(getConstraints(), sudokuWidth.get(), sudokuHeight.get()), selectSudoku(currentType.createDoku(getConstraints(), sudokuWidth.get(), sudokuHeight.get()),
false); false);

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.gui.widget; package gui.widget;
import java.time.Instant; import java.time.Instant;

View File

@@ -1,11 +1,11 @@
package org.polytech.ryuk.network; package network;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.net.Socket; import java.net.Socket;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.PacketVisitor; import network.protocol.PacketVisitor;
public abstract class Connexion implements PacketVisitor { public abstract class Connexion implements PacketVisitor {

View File

@@ -1,9 +1,9 @@
package org.polytech.ryuk.network; package network;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
public class ConnexionThread extends Thread { public class ConnexionThread extends Thread {

View File

@@ -1,18 +1,18 @@
package org.polytech.ryuk.network.client; package network.client;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Random; import java.util.Random;
import org.polytech.ryuk.common.ConsumerSignal; import common.ConsumerSignal;
import org.polytech.ryuk.common.Signal; import common.Signal;
import org.polytech.ryuk.game.Game; import game.Game;
import org.polytech.ryuk.game.Player; import game.Player;
import org.polytech.ryuk.network.protocol.packets.ChangeCellPacket; import network.protocol.packets.ChangeCellPacket;
import org.polytech.ryuk.network.protocol.packets.LoginPacket; import network.protocol.packets.LoginPacket;
import org.polytech.ryuk.sudoku.structure.Cell; import sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.MultiDoku;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.Sudoku;
public class Client { public class Client {
private final ClientConnexion clientConnection; private final ClientConnexion clientConnection;

View File

@@ -1,22 +1,22 @@
package org.polytech.ryuk.network.client; package network.client;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import org.polytech.ryuk.game.Player; import game.Player;
import org.polytech.ryuk.network.Connexion; import network.Connexion;
import org.polytech.ryuk.network.protocol.packets.ChangeCellPacket; import network.protocol.packets.ChangeCellPacket;
import org.polytech.ryuk.network.protocol.packets.ConnexionInfoPacket; import network.protocol.packets.ConnexionInfoPacket;
import org.polytech.ryuk.network.protocol.packets.DisconnectPacket; import network.protocol.packets.DisconnectPacket;
import org.polytech.ryuk.network.protocol.packets.EndGamePacket; import network.protocol.packets.EndGamePacket;
import org.polytech.ryuk.network.protocol.packets.KeepAlivePacket; import network.protocol.packets.KeepAlivePacket;
import org.polytech.ryuk.network.protocol.packets.LoginPacket; import network.protocol.packets.LoginPacket;
import org.polytech.ryuk.network.protocol.packets.PlayerJoinPacket; import network.protocol.packets.PlayerJoinPacket;
import org.polytech.ryuk.network.protocol.packets.PlayerLeavePacket; import network.protocol.packets.PlayerLeavePacket;
import org.polytech.ryuk.network.protocol.packets.StartGamePacket; import network.protocol.packets.StartGamePacket;
import org.polytech.ryuk.network.protocol.packets.UpdatePlayerScorePacket; import network.protocol.packets.UpdatePlayerScorePacket;
import org.polytech.ryuk.sudoku.io.SudokuSerializer; import sudoku.io.SudokuSerializer;
public class ClientConnexion extends Connexion { public class ClientConnexion extends Connexion {

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.network.protocol; package network.protocol;
import java.io.Serializable; import java.io.Serializable;

View File

@@ -0,0 +1,31 @@
package network.protocol;
import network.protocol.packets.ChangeCellPacket;
import network.protocol.packets.ConnexionInfoPacket;
import network.protocol.packets.DisconnectPacket;
import network.protocol.packets.EndGamePacket;
import network.protocol.packets.KeepAlivePacket;
import network.protocol.packets.LoginPacket;
import network.protocol.packets.PlayerJoinPacket;
import network.protocol.packets.PlayerLeavePacket;
import network.protocol.packets.StartGamePacket;
import network.protocol.packets.UpdatePlayerScorePacket;
public interface PacketVisitor {
default void visit(Packet packet) {
packet.accept(this);
}
void visitPacket(ConnexionInfoPacket packet);
void visitPacket(DisconnectPacket packet);
void visitPacket(KeepAlivePacket packet);
void visitPacket(LoginPacket packet);
void visitPacket(PlayerJoinPacket packet);
void visitPacket(PlayerLeavePacket packet);
void visitPacket(StartGamePacket packet);
void visitPacket(EndGamePacket packet);
void visitPacket(UpdatePlayerScorePacket packet);
void visitPacket(ChangeCellPacket packet);
}

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.network.protocol; package network.protocol;
public enum Packets { public enum Packets {

View File

@@ -1,8 +1,8 @@
package org.polytech.ryuk.network.protocol.packets; package network.protocol.packets;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.PacketVisitor; import network.protocol.PacketVisitor;
import org.polytech.ryuk.network.protocol.Packets; import network.protocol.Packets;
public class ChangeCellPacket extends Packet { public class ChangeCellPacket extends Packet {

View File

@@ -1,8 +1,8 @@
package org.polytech.ryuk.network.protocol.packets; package network.protocol.packets;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.PacketVisitor; import network.protocol.PacketVisitor;
import org.polytech.ryuk.network.protocol.Packets; import network.protocol.Packets;
public class ConnexionInfoPacket extends Packet { public class ConnexionInfoPacket extends Packet {

View File

@@ -1,8 +1,8 @@
package org.polytech.ryuk.network.protocol.packets; package network.protocol.packets;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.PacketVisitor; import network.protocol.PacketVisitor;
import org.polytech.ryuk.network.protocol.Packets; import network.protocol.Packets;
public class DisconnectPacket extends Packet { public class DisconnectPacket extends Packet {

View File

@@ -1,8 +1,8 @@
package org.polytech.ryuk.network.protocol.packets; package network.protocol.packets;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.PacketVisitor; import network.protocol.PacketVisitor;
import org.polytech.ryuk.network.protocol.Packets; import network.protocol.Packets;
public class EndGamePacket extends Packet { public class EndGamePacket extends Packet {

View File

@@ -1,8 +1,8 @@
package org.polytech.ryuk.network.protocol.packets; package network.protocol.packets;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.PacketVisitor; import network.protocol.PacketVisitor;
import org.polytech.ryuk.network.protocol.Packets; import network.protocol.Packets;
public class KeepAlivePacket extends Packet { public class KeepAlivePacket extends Packet {

View File

@@ -1,8 +1,8 @@
package org.polytech.ryuk.network.protocol.packets; package network.protocol.packets;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.PacketVisitor; import network.protocol.PacketVisitor;
import org.polytech.ryuk.network.protocol.Packets; import network.protocol.Packets;
public class LoginPacket extends Packet { public class LoginPacket extends Packet {

View File

@@ -1,9 +1,9 @@
package org.polytech.ryuk.network.protocol.packets; package network.protocol.packets;
import org.polytech.ryuk.game.Player; import game.Player;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.PacketVisitor; import network.protocol.PacketVisitor;
import org.polytech.ryuk.network.protocol.Packets; import network.protocol.Packets;
public class PlayerJoinPacket extends Packet{ public class PlayerJoinPacket extends Packet{

View File

@@ -1,8 +1,8 @@
package org.polytech.ryuk.network.protocol.packets; package network.protocol.packets;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.PacketVisitor; import network.protocol.PacketVisitor;
import org.polytech.ryuk.network.protocol.Packets; import network.protocol.Packets;
public class PlayerLeavePacket extends Packet{ public class PlayerLeavePacket extends Packet{

View File

@@ -1,10 +1,10 @@
package org.polytech.ryuk.network.protocol.packets; package network.protocol.packets;
import java.time.Instant; import java.time.Instant;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.PacketVisitor; import network.protocol.PacketVisitor;
import org.polytech.ryuk.network.protocol.Packets; import network.protocol.Packets;
public class StartGamePacket extends Packet { public class StartGamePacket extends Packet {

View File

@@ -1,8 +1,8 @@
package org.polytech.ryuk.network.protocol.packets; package network.protocol.packets;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.PacketVisitor; import network.protocol.PacketVisitor;
import org.polytech.ryuk.network.protocol.Packets; import network.protocol.Packets;
public class UpdatePlayerScorePacket extends Packet { public class UpdatePlayerScorePacket extends Packet {

View File

@@ -1,8 +1,8 @@
package org.polytech.ryuk.network.server; package network.server;
import java.util.Random; import java.util.Random;
import org.polytech.ryuk.network.protocol.packets.KeepAlivePacket; import network.protocol.packets.KeepAlivePacket;
public class KeepAliveHandler { public class KeepAliveHandler {

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.network.server; package network.server;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
@@ -6,14 +6,14 @@ import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.polytech.ryuk.game.Game; import game.Game;
import org.polytech.ryuk.game.Game.GameState; import game.Player;
import org.polytech.ryuk.game.Player; import game.Game.GameState;
import org.polytech.ryuk.network.protocol.Packet; import network.protocol.Packet;
import org.polytech.ryuk.network.protocol.packets.EndGamePacket; import network.protocol.packets.EndGamePacket;
import org.polytech.ryuk.network.protocol.packets.StartGamePacket; import network.protocol.packets.StartGamePacket;
import org.polytech.ryuk.sudoku.io.SudokuSerializer; import sudoku.io.SudokuSerializer;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.MultiDoku;
public class Server { public class Server {

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.network.server; package network.server;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;

View File

@@ -1,25 +1,25 @@
package org.polytech.ryuk.network.server; package network.server;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import org.polytech.ryuk.game.Game; import game.Game;
import org.polytech.ryuk.game.Game.GameState; import game.Player;
import org.polytech.ryuk.game.Player; import game.Game.GameState;
import org.polytech.ryuk.network.Connexion; import network.Connexion;
import org.polytech.ryuk.network.protocol.packets.ChangeCellPacket; import network.protocol.packets.ChangeCellPacket;
import org.polytech.ryuk.network.protocol.packets.ConnexionInfoPacket; import network.protocol.packets.ConnexionInfoPacket;
import org.polytech.ryuk.network.protocol.packets.DisconnectPacket; import network.protocol.packets.DisconnectPacket;
import org.polytech.ryuk.network.protocol.packets.EndGamePacket; import network.protocol.packets.EndGamePacket;
import org.polytech.ryuk.network.protocol.packets.KeepAlivePacket; import network.protocol.packets.KeepAlivePacket;
import org.polytech.ryuk.network.protocol.packets.LoginPacket; import network.protocol.packets.LoginPacket;
import org.polytech.ryuk.network.protocol.packets.PlayerJoinPacket; import network.protocol.packets.PlayerJoinPacket;
import org.polytech.ryuk.network.protocol.packets.PlayerLeavePacket; import network.protocol.packets.PlayerLeavePacket;
import org.polytech.ryuk.network.protocol.packets.StartGamePacket; import network.protocol.packets.StartGamePacket;
import org.polytech.ryuk.network.protocol.packets.UpdatePlayerScorePacket; import network.protocol.packets.UpdatePlayerScorePacket;
import org.polytech.ryuk.sudoku.io.SudokuSerializer; import sudoku.io.SudokuSerializer;
import org.polytech.ryuk.sudoku.structure.Cell; import sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.MultiDoku;
public class ServerConnexion extends Connexion { public class ServerConnexion extends Connexion {

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.network.server; package network.server;
public class ServerLogicThread extends Thread { public class ServerLogicThread extends Thread {

View File

@@ -1,31 +0,0 @@
package org.polytech.ryuk.network.protocol;
import org.polytech.ryuk.network.protocol.packets.ChangeCellPacket;
import org.polytech.ryuk.network.protocol.packets.ConnexionInfoPacket;
import org.polytech.ryuk.network.protocol.packets.DisconnectPacket;
import org.polytech.ryuk.network.protocol.packets.EndGamePacket;
import org.polytech.ryuk.network.protocol.packets.KeepAlivePacket;
import org.polytech.ryuk.network.protocol.packets.LoginPacket;
import org.polytech.ryuk.network.protocol.packets.PlayerJoinPacket;
import org.polytech.ryuk.network.protocol.packets.PlayerLeavePacket;
import org.polytech.ryuk.network.protocol.packets.StartGamePacket;
import org.polytech.ryuk.network.protocol.packets.UpdatePlayerScorePacket;
public interface PacketVisitor {
default void visit(Packet packet) {
packet.accept(this);
}
void visitPacket(ConnexionInfoPacket packet);
void visitPacket(DisconnectPacket packet);
void visitPacket(KeepAlivePacket packet);
void visitPacket(LoginPacket packet);
void visitPacket(PlayerJoinPacket packet);
void visitPacket(PlayerLeavePacket packet);
void visitPacket(StartGamePacket packet);
void visitPacket(EndGamePacket packet);
void visitPacket(UpdatePlayerScorePacket packet);
void visitPacket(ChangeCellPacket packet);
}

View File

@@ -1,17 +0,0 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package org.polytech.ryuk.sudoku;
import org.polytech.ryuk.sudoku.io.ConsoleInterface;
public class Main {
public String getGreeting() {
return "Hello World!";
}
public static void main(String[] args) {
ConsoleInterface console = new ConsoleInterface();
console.start();
}
}

View File

@@ -1,138 +0,0 @@
package org.polytech.ryuk.sudoku.io;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import org.polytech.ryuk.sudoku.constraint.Constraint;
import org.polytech.ryuk.sudoku.solver.RandomSolver;
import org.polytech.ryuk.sudoku.structure.Difficulty;
import org.polytech.ryuk.sudoku.structure.MultiDoku;
import org.polytech.ryuk.sudoku.structure.Sudoku;
import org.polytech.ryuk.sudoku.structure.SudokuFactory;
public class ConsoleInterface {
public Scanner reader = new Scanner(System.in);
public void start(){
welcome();
System.out.println("First of all, you need to tell me the size of the sudoku you want to generate.");
int width = getBlockWidth();
int height = getBlockHeight();
System.out.println("Your sudoku will have blocks of a " + width + " x " + height + " format.");
int numberOfSymbols = width * height;
System.out.println("Would you like to pick the " + numberOfSymbols + " symbols from the sudoku? (y/n, default 'no' will use numbers)" );
List<String> listSymbols = new ArrayList<>();
if(reader.next().equalsIgnoreCase("y")){
pickSymbols(listSymbols, numberOfSymbols);
}
else {
// TODO
System.out.println("Simon doit finir sa partie.");
assert false;
}
List<Constraint> listConstraints = getListConstraints();
System.out.println("Now that we have the size of our sudoku, would you rather have a single grid ('one', default), " +
"or a a multidoku composed of 5 subgrids ('multi') ?");
List<Sudoku> subGrids = new ArrayList<>();
MultiDoku doku;
if (reader.next().equalsIgnoreCase("multi")) {
doku = SudokuFactory.createBasicEmptyRectangleDoku(width, height, listConstraints);
}
else {
doku = SudokuFactory.createBasicXShapedMultidoku(width, height, listConstraints);
}
System.out.println("Your sudoku will look like this:");
// TODO printMultiDoku method not yet implemented
SudokuPrinter.printMultiDoku(doku, width, height);
System.out.println("We now will fill this sudoku.");
System.out.println("What level of difficulty would you like? ('very easy', 'easy', 'medium' (default), 'hard', 'full' (sudoku fully completed))");
String difficulty = reader.next().toLowerCase();
if (difficulty.equals("full")) {
generateFullDoku(doku);
}
else {
generatePartialDoku(doku, difficulty);
}
System.out.println("Here's your sudoku !");
SudokuPrinter.printMultiDoku(doku, width, height);
}
public void welcome(){
System.out.println("Welcome to our Sudoku Solver!");
System.out.println("This is the project of Melvyn Bauvent, Lilas Grenier and Simon Priblyski.");
}
public int getBlockWidth() {
System.out.println("Width of a block: ");
int widthBlock = reader.nextInt();
checkValidSize(widthBlock);
while (!checkValidSize(widthBlock)) {
System.out.println("That is not a valid width for a block. Try again:");
widthBlock = reader.nextInt();
}
System.out.println("You have chose a width of " + widthBlock + ".");
return widthBlock;
}
public int getBlockHeight() {
System.out.println("Height of a block: ");
int heightBlock = reader.nextInt();
checkValidSize(heightBlock);
while (!checkValidSize(heightBlock)) {
System.out.println("That is not a valid height for a block. Try again:");
heightBlock = reader.nextInt();
}
System.out.println("You have chose a height of " + heightBlock + ".");
return heightBlock;
}
private Boolean checkValidSize(int size) {
return (size > 0);
}
private void pickSymbols(List<String> listSymbols, int numberOfSymbols) {
System.out.println("You have chosen to pick your own symbols.");
for (int i = 0; i < numberOfSymbols; i++) {
System.out.println("Choose for the symbol number " + i + ": ");
String newSymbol = reader.next();
while (listSymbols.contains(newSymbol)) {
System.out.println("This symbol has already been given. Try again:");
newSymbol = reader.next();
}
listSymbols.add(newSymbol);
}
System.out.println("You chose the symbols: " + listSymbols.toString());
}
private List<Constraint> getListConstraints() {
List<Constraint> listConstraints = SudokuFactory.DEFAULT_CONSTRAINTS;
System.out.println("The sudoku have constraints of blocks, lines and columns. Would you like to add the diagonal constraints ? (y/n, default 'no')");
if(reader.next().equalsIgnoreCase("y")){
listConstraints.add(Constraint.Diagonal);
}
return listConstraints;
}
private void generatePartialDoku(MultiDoku doku, String difficultyName) {
Difficulty difficulty;
switch (difficultyName){
case "very easy": difficulty = Difficulty.VeryEasy;
case "easy": difficulty = Difficulty.Easy;
case "hard": difficulty = Difficulty.Hard;
default: difficulty = Difficulty.Medium;
}
try {
SudokuFactory.fillDoku(doku, difficulty);
} catch (Exception e) {
System.out.println("There seems to be a problem with those settings. Let's start again.");
}
}
private void generateFullDoku(MultiDoku doku) {
new RandomSolver().solve(doku);
}
}

View File

@@ -1,7 +0,0 @@
package org.polytech.ryuk.sudoku.io;
public class SudokuFile {
}

View File

@@ -1,51 +0,0 @@
package org.polytech.ryuk.sudoku.io;
import org.polytech.ryuk.sudoku.structure.MultiDoku;
import org.polytech.ryuk.sudoku.structure.Sudoku;
public class SudokuPrinter {
public static void printRectangleSudoku(final Sudoku s, int blockWidth, int blockHeight) {
for (int y = 0; y < s.getSize(); y++) {
if (y % blockHeight == 0 && y > 0) {
System.out.println();
}
StringBuilder line = new StringBuilder("[ ");
for (int x = 0; x < s.getSize(); x++) {
line.append((s.getCell(x, y).getSymbolIndex() + 1)).append(" ");
if (x % blockWidth == blockWidth - 1 && x != blockWidth * blockHeight - 1) {
line.append("| ");
}
}
line.append("]");
System.out.println(line);
}
}
public static String toStringRectangleSudoku(final Sudoku s, int blockWidth, int blockHeight) {
StringBuilder result = new StringBuilder();
for (int y = 0; y < s.getSize(); y++) {
// Ajouter une ligne vide entre les blocs horizontaux
if (y % blockHeight == 0 && y > 0) {
result.append("\n");
}
StringBuilder line = new StringBuilder("[ ");
for (int x = 0; x < s.getSize(); x++) {
// Ajouter la valeur de la cellule
line.append((s.getCell(x, y).getSymbolIndex() + 1)).append(" ");
// Ajouter un séparateur vertical entre les blocs
if (x % blockWidth == blockWidth - 1 && x != s.getSize() - 1) {
line.append("| ");
}
}
line.append("]");
result.append(line).append("\n");
}
return result.toString();
}
public static void printMultiDoku(final MultiDoku doku, int blockWidth, int blockHeight){
// TODO
}
}

View File

@@ -1,41 +0,0 @@
package org.polytech.ryuk.sudoku.structure;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
//TODO: doc
public class StateManager {
private final Stack<Map<Cell, Integer>> states;
private final MultiDoku doku;
public StateManager(MultiDoku doku) {
this.states = new Stack<>();
this.doku = doku;
}
public void pushState() {
states.add(new HashMap<>());
saveState();
}
public void popState() {
assert (states.size() > 0);
restoreState();
states.pop();
}
private void restoreState() {
for (var entry : this.states.getLast().entrySet()) {
entry.getKey().setSymbolIndex(entry.getValue());
}
}
private void saveState() {
for (Cell cell : this.doku.getCells()) {
states.getLast().put(cell, cell.getSymbolIndex());
}
}
}

View File

@@ -0,0 +1,53 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package sudoku;
import gui.RenderableMultidoku;
import gui.Symbols;
import sudoku.io.ConsoleInterface;
import sudoku.io.SudokuPrinter;
import sudoku.io.SudokuSerializer;
import sudoku.solver.RandomSolver;
import sudoku.solver.Solver;
import sudoku.structure.MultiDoku;
import sudoku.structure.SudokuFactory;
import java.util.Random;
public class Main {
public String getGreeting() {
return "Hello World!";
}
public static void voidTest(){
MultiDoku md = SudokuFactory.createBasicXShapedMultidoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
SudokuPrinter.printMultiDoku(RenderableMultidoku.fromMultidoku(md), Symbols.Numbers, 3, 3);
SudokuSerializer.saveMultiDoku(md);
}
public static void filledTest(){
MultiDoku md = SudokuFactory.createBasicXShapedMultidoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
new RandomSolver().solve(md);
SudokuPrinter.printMultiDoku(RenderableMultidoku.fromMultidoku(md), Symbols.Numbers, 3, 3);
SudokuSerializer.saveMultiDoku(md);
}
public static void overwriteTest(int n){
MultiDoku md = SudokuFactory.createBasicXShapedMultidoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
new RandomSolver().solve(md);
SudokuPrinter.printMultiDoku(RenderableMultidoku.fromMultidoku(md), Symbols.Numbers, 3, 3);
SudokuSerializer.saveMultiDoku(md, n);
}
public static void main(String[] args) {
ConsoleInterface console = new ConsoleInterface();
/*
voidTest();
filledTest();
overwriteTest(0);
overwriteTest(17)
*/
console.welcome();
}
}

View File

@@ -1,7 +1,7 @@
package org.polytech.ryuk.sudoku.constraint; package sudoku.constraint;
import org.polytech.ryuk.sudoku.structure.Block; import sudoku.structure.Block;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.Sudoku;
public class BlockConstraint implements IConstraint{ public class BlockConstraint implements IConstraint{

View File

@@ -1,7 +1,7 @@
package org.polytech.ryuk.sudoku.constraint; package sudoku.constraint;
import org.polytech.ryuk.sudoku.structure.Cell; import sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.Sudoku;
public class ColumnConstraint implements IConstraint { public class ColumnConstraint implements IConstraint {

View File

@@ -1,8 +1,8 @@
package org.polytech.ryuk.sudoku.constraint; package sudoku.constraint;
import java.util.List; import java.util.List;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.Sudoku;
public enum Constraint { public enum Constraint {

View File

@@ -1,6 +1,6 @@
package org.polytech.ryuk.sudoku.constraint; package sudoku.constraint;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.Sudoku;
public class DiagonalConstraint implements IConstraint { public class DiagonalConstraint implements IConstraint {

View File

@@ -1,9 +1,9 @@
package org.polytech.ryuk.sudoku.constraint; package sudoku.constraint;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.Sudoku;
public interface IConstraint { public interface IConstraint {

View File

@@ -1,6 +1,6 @@
package org.polytech.ryuk.sudoku.constraint; package sudoku.constraint;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.Sudoku;
public class LineConstraint implements IConstraint { public class LineConstraint implements IConstraint {

View File

@@ -0,0 +1,305 @@
package sudoku.io;
import gui.RenderableMultidoku;
import gui.Symbols;
import sudoku.constraint.*;
import sudoku.solver.*;
import sudoku.structure.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class ConsoleInterface {
public Scanner reader = new Scanner(System.in);
public void welcome() {
System.out.println("Welcome to our Sudoku Solver!");
System.out.println("This is the project of Melvyn Bauvent, Lilas Grenier and Simon Priblyski.");
System.out.println("Do you have a save sudoku you would like to continue? (y/n, default n)");
if (reader.next().equalsIgnoreCase("y")) {
useSavedDoku();
} else {
createDoku();
}
}
private void useSavedDoku() {
System.out.println("What save should we use? Please enter the save number.");
MultiDoku md = saveChoice();
int blockWidth = md.getSubGrid(0).getBlockWidth();
int blockHeight = md.getSubGrid(0).getBlocks().getFirst().getCells().size() / blockWidth;
List<String> listSymbols = pickSymbols(blockWidth * blockHeight);
System.out.println("This is the saved sudoku:");
showMultidoku(md, listSymbols, blockWidth, blockHeight);
do {
turn(md, listSymbols, blockWidth, blockHeight);
} while (!md.isSolved());
congrats();
}
public void createDoku() {
System.out.println("First of all, you need to tell me the size of the sudoku you want to generate.");
int width = getBlockWidth();
int height = getBlockHeight();
System.out.println("Your sudoku will have blocks of a " + width + " x " + height + " format.");
int numberOfSymbols = width * height;
List<String> listSymbols = pickSymbols(numberOfSymbols);
List<Constraint> listConstraints = getListConstraints();
System.out.println("Now that we have the size of our sudoku, " +
"would you rather have a single grid ('one', default), " +
"or a a multidoku composed of 5 subgrids ('multi') ?");
MultiDoku doku;
if (reader.next().equalsIgnoreCase("multi")) {
doku = SudokuFactory.createBasicXShapedMultidoku(width, height, listConstraints);
} else {
doku = SudokuFactory.createBasicEmptyRectangleDoku(width, height, listConstraints);
}
System.out.println("Your sudoku will look like this:");
showMultidoku(doku, listSymbols, width, height);
System.out.println(
"You can now manually fill this sudoku ('fill'), or generate a playable one ('generate', default):");
if (reader.next().equalsIgnoreCase("fill")) {
findSolution(doku, listSymbols, width, height);
} else {
playableDoku(doku, listSymbols, width, height);
}
}
private void playableDoku(MultiDoku doku, List<String> listSymbols, int width, int height) {
System.out.println("We will now fill this sudoku.");
System.out.println("What level of difficulty would you like?" +
" ('very easy', 'easy', 'medium' (default), 'hard', 'full' (sudoku fully completed))");
String difficulty = reader.next().toLowerCase();
if (difficulty.equals("full")) {
generateFullDoku(doku);
System.out.println("Here's your sudoku !");
exit();
} else {
generatePartialDoku(doku, difficulty);
System.out.println("Here's your sudoku !");
showMultidoku(doku, listSymbols, width, height);
do {
turn(doku, listSymbols, width, height);
} while (!doku.isSolved());
congrats();
}
}
private void findSolution(MultiDoku doku, List<String> listSymbols, int width, int height){
do {
turn(doku, listSymbols, width, height);
} while (!doku.isSolved());
System.out.println("This doku can be solved like this :");
showMultidoku(doku, listSymbols, width, height);
exit();
}
private void congrats() {
System.out.println("Congrats! You've solved this sudoku! We hope this was fun! Let's play together again!");
System.exit(0);
}
private MultiDoku saveChoice() {
int nbSave;
MultiDoku md = null;
do {
nbSave = reader.nextInt();
try {
md = SudokuSerializer.getSavedMultiDoku(nbSave);
} catch (Exception e) {
System.out.println("There seems to be a problem with this save, please try again.");
}
} while (md == null);
return md;
}
public int getBlockWidth() {
System.out.println("Width of a block: ");
int widthBlock = reader.nextInt();
checkValidSize(widthBlock);
while (!checkValidSize(widthBlock)) {
System.out.println("That is not a valid width for a block. Try again:");
widthBlock = reader.nextInt();
}
System.out.println("You have chose a width of " + widthBlock + ".");
return widthBlock;
}
public int getBlockHeight() {
System.out.println("Height of a block: ");
int heightBlock = reader.nextInt();
checkValidSize(heightBlock);
while (!checkValidSize(heightBlock)) {
System.out.println("That is not a valid height for a block. Try again:");
heightBlock = reader.nextInt();
}
System.out.println("You have chose a height of " + heightBlock + ".");
return heightBlock;
}
private Boolean checkValidSize(int size) {
return (size > 0);
}
private List<String> pickSymbols(int numberOfSymbols) {
System.out.println("Would you like to pick the " + numberOfSymbols
+ " symbols from the sudoku? (y/n, default 'no')");
if (reader.next().equalsIgnoreCase("y")) {
List<String> listSymbols = new ArrayList<>();
System.out.println("You have chosen to pick your own symbols.");
for (int i = 0; i < numberOfSymbols; i++) {
System.out.println("Choose for the symbol number " + i + ": ");
String newSymbol = reader.next();
while (listSymbols.contains(newSymbol)) {
System.out.println("This symbol has already been given. Try again:");
newSymbol = reader.next();
}
listSymbols.add(newSymbol);
}
System.out.println("You chose the symbols: " + listSymbols.toString());
return listSymbols;
} else {
System.out.println(
"What existing sets of symbols do you want to use? Numbers ('n', default), letters ('l'), or emojis ('e', may not work on all consoles)?");
return switch (reader.next().toLowerCase()) {
case "l" -> Symbols.Letters.getSymbols();
case "e" -> Symbols.Emojis.getSymbols();
default -> Symbols.Numbers.getSymbols();
};
}
}
private List<Constraint> getListConstraints() {
List<Constraint> listConstraints = SudokuFactory.DEFAULT_CONSTRAINTS;
System.out.println(
"The sudoku have constraints of blocks, lines and columns. Would you like to add the diagonal constraints ? (y/n, default 'no')");
if (reader.next().equalsIgnoreCase("y")) {
listConstraints.add(Constraint.Diagonal);
}
return listConstraints;
}
private void generatePartialDoku(MultiDoku doku, String difficultyName) {
Difficulty difficulty;
switch (difficultyName) {
case "very easy":
difficulty = Difficulty.VeryEasy;
case "easy":
difficulty = Difficulty.Easy;
case "hard":
difficulty = Difficulty.Hard;
default:
difficulty = Difficulty.Medium;
}
try {
SudokuFactory.fillDoku(doku, difficulty);
} catch (Exception e) {
System.out.println("There seems to be a problem with those settings. Let's start again.");
}
}
private void generateFullDoku(MultiDoku doku) {
new RandomSolver().solve(doku);
}
private void showMultidoku(MultiDoku doku, List<String> listSymbols, int width, int height) {
showMultiDoku(RenderableMultidoku.fromMultidoku(doku), listSymbols, width, height);
}
private void showMultiDoku(RenderableMultidoku doku, List<String> listSymbols, int width, int height) {
SudokuPrinter.printMultiDokuWithIndex(doku, listSymbols, width, height);
}
private void saveMultiDoku(MultiDoku doku) {
System.out.println("Number of the file to overwrite ('-1' or unused save file number to create a new save) :");
int n = reader.nextInt();
String path = SudokuSerializer.saveMultiDoku(doku, n);
System.out.println("The path to your save is:" + path);
}
private void turn(MultiDoku doku, List<String> listSymbols, int width, int height) {
System.out.println(
"You can now put a number in a cell ('play', default), save the state of the doku ('save'), show a solution ('solution') or exit the program ('exit').");
switch (reader.next()) {
case "save":
saveMultiDoku(doku);
break;
case "solution":
solve(doku);
break;
case "exit":
exit();
break;
default:
play(doku, listSymbols, width, height);
break;
}
}
private void solve(MultiDoku doku){
System.out.println("Pick a solver to use : random ('random', default), human ('human') or mixed solver ('mixed').");
switch (reader.next()) {
case "human":
new HumanSolver().solve(doku);
break;
case "mixed":
new MixedSolver().solve(doku);
break;
default:
new RandomSolver().solve(doku);
break;
}
}
private void play(MultiDoku doku, List<String> listSymbols, int width, int height) {
int x, y;
RenderableMultidoku rdoku = RenderableMultidoku.fromMultidoku(doku);
do {
System.out.println("Line of the cell to fill:");
y = reader.nextInt();
System.out.println("Column of the cell to fill:");
x = reader.nextInt();
} while (!isValidCoordinates(rdoku, width, height, x-1, y-1));
Cell cell = rdoku.getCell(x-1, y-1);
System.out.println("Character to put in the (" + x + ", " + y + ") cell:");
String character = reader.next();
while (!isValidSymbol(character, listSymbols, width * height)) {
System.out.println("This is not a valid symbol; try again:");
character = reader.next();
}
cell.setSymbolIndex(indexOfSymbol(character, listSymbols, width * height));
showMultiDoku(rdoku, listSymbols, width, height);
}
private boolean isValidCoordinates(RenderableMultidoku doku, int width, int height, int x, int y) {
if (doku.getCell(x, y) != null) {
return true;
}
return false;
}
private int indexOfSymbol(String symbol, List<String> listSymbols, int nbSymbols) {
for (int i = 0; i < nbSymbols; i++) {
if (listSymbols.get(i).equals(symbol)) {
return i;
}
}
return -1;
}
private boolean isValidSymbol(String symbol, List<String> listSymbols, int size) {
for (int i = 0; i < size; i++) {
if (listSymbols.get(i).equals(symbol)) {
return true;
}
}
return false;
}
private void exit() {
System.out.println("Thank you for playing!");
System.exit(0);
}
}

View File

@@ -0,0 +1,7 @@
package sudoku.io;
public class SudokuFile {
}

View File

@@ -0,0 +1,202 @@
package sudoku.io;
import gui.RenderableMultidoku;
import gui.Symbols;
import sudoku.structure.Cell;
import sudoku.structure.MultiDoku;
import sudoku.structure.Sudoku;
import java.util.List;
public class SudokuPrinter {
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_RED = "\u001B[31m";
public static final String ANSI_GREEN = "\u001B[32m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_PURPLE = "\u001B[35m";
public static final String ANSI_CYAN = "\u001B[36m";
public static void printRectangleSudoku(final Sudoku s, int blockWidth, int blockHeight, Symbols symbols) {
printRectangleSudoku(s, blockWidth, blockHeight, symbols.getSymbols());
}
public static void printRectangleSudoku(final Sudoku s, int blockWidth, int blockHeight, List<String> listSymbols) {
for (int y = 0; y < s.getSize(); y++) {
if (y % blockHeight == 0 && y > 0) {
System.out.println();
}
StringBuilder line = new StringBuilder("[ ");
for (int x = 0; x < s.getSize(); x++) {
Cell c = s.getCell(x, y);
if (c.getSymbolIndex() == Cell.NOSYMBOL) {
line.append(" ");
} else {
line.append(listSymbols.get(c.getSymbolIndex())).append(" ");
}
if (x % blockWidth == blockWidth - 1 && x != blockWidth * blockHeight - 1) {
line.append("| ");
}
}
line.append("]");
System.out.println(line);
}
}
public static void printRectangleSudokuWithIndex(final Sudoku s, int blockWidth, int blockHeight,
List<String> listSymbols) {
StringBuilder header = new StringBuilder("");
header.append(" ");
for (int x = 0; x < blockWidth*blockHeight; x++) {
header.append(x + 1).append(" ");
if (x % blockWidth == blockWidth - 1 && x != blockWidth * blockHeight - 1) {
header.append(" ");
}
}
header.append("\n");
System.out.println(header);
for (int y = 0; y < s.getSize(); y++) {
if (y % blockHeight == 0 && y > 0) {
System.out.println();
}
StringBuilder line = new StringBuilder(y + 1);
line.append(" [ ");
for (int x = 0; x < s.getSize(); x++) {
Cell c = s.getCell(x, y);
if (c.getSymbolIndex() == Cell.NOSYMBOL) {
line.append(" ");
} else {
line.append(listSymbols.get(c.getSymbolIndex())).append(" ");
}
if (x % blockWidth == blockWidth - 1 && x != blockWidth * blockHeight - 1) {
line.append("| ");
}
}
line.append("]");
System.out.println(line);
}
}
public static void printMultiDoku(final RenderableMultidoku rm, Symbols symbols, int blockWidth, int blockHeight) {
printMultiDoku(rm, symbols.getSymbols(), blockWidth, blockHeight);
}
public static void printMultiDoku(final RenderableMultidoku rm, List<String> listSymbols, int blockWidth,
int blockHeight) {
StringBuilder line = new StringBuilder("\n");
int nBlockInWidth = rm.getWidth() / blockWidth;
for (int y = 0; y < rm.getHeight(); y++) {
if (y % blockHeight == 0) {
line.append("__".repeat(Math.max(0, rm.getWidth() + nBlockInWidth))).append("_\n");
}
line.append("[ ");
for (int x = 0; x < rm.getWidth(); x++) {
if (x % blockWidth == 0 && x > 0) {
line.append("| ");
}
Cell cell = rm.getCell(x, y);
if (cell != null) {
if (cell.getSymbolIndex() == Cell.NOSYMBOL) {
line.append("- ");
} else {
line.append(listSymbols.get(cell.getSymbolIndex())).append(" ");
}
} else {
line.append(" ");
}
}
line.append("]\n");
}
line.append("__".repeat(Math.max(0, rm.getWidth() + nBlockInWidth))).append("_\n");
System.out.println(line);
}
public static void printMultiDokuWithIndex(final RenderableMultidoku rm, List<String> listSymbols, int blockWidth,
int blockHeight) {
StringBuilder line = new StringBuilder("\n");
line.append(" ");
for (int x = 0; x < rm.getWidth(); x++) {
line.append(x + 1).append(" ");
if (x % blockWidth == blockWidth - 1 && x != blockWidth * blockHeight - 1) {
line.append(" ");
}
}
line.append("\n");
int nBlockInWidth = rm.getWidth() / blockWidth;
for (int y = 0; y < rm.getHeight(); y++) {
if (y % blockHeight == 0) {
line.append(" ").append("__".repeat(Math.max(0, rm.getWidth() + nBlockInWidth))).append("_\n");
}
line.append(y+1).append(" [ ");
for (int x = 0; x < rm.getWidth(); x++) {
if (x % blockWidth == 0 && x > 0) {
line.append("| ");
}
Cell cell = rm.getCell(x, y);
if (cell != null) {
if (cell.getSymbolIndex() == Cell.NOSYMBOL) {
line.append("- ");
} else {
line.append(listSymbols.get(cell.getSymbolIndex())).append(" ");
}
} else {
line.append(" ");
}
}
line.append("]\n");
}
line.append(" ").append("__".repeat(Math.max(0, rm.getWidth() + nBlockInWidth))).append("_\n");
System.out.println(line);
}
public static String toStringRectangleSudoku(final Sudoku s, int blockWidth, int blockHeight, Symbols symbols) {
return toStringRectangleSudoku(s, blockWidth, blockHeight, symbols.getSymbols());
}
public static String toStringRectangleSudoku(final Sudoku s, int blockWidth, int blockHeight,
List<String> listSymbols) {
StringBuilder result = new StringBuilder();
for (int y = 0; y < s.getSize(); y++) {
// Ajouter une ligne vide entre les blocs horizontaux
if (y % blockHeight == 0 && y > 0) {
result.append("\n");
}
StringBuilder line = new StringBuilder("[ ");
for (int x = 0; x < s.getSize(); x++) {
// Ajouter la valeur de la cellule
Cell cell = s.getCell(x, y);
if (cell.getSymbolIndex() == Cell.NOSYMBOL) {
line.append(" ");
} else {
line.append(listSymbols.get(cell.getSymbolIndex())).append(" ");
}
// Ajouter un séparateur vertical entre les blocs
if (x % blockWidth == blockWidth - 1 && x != s.getSize() - 1) {
line.append("| ");
}
}
line.append("]");
result.append(line).append("\n");
}
return result.toString();
}
public static void printMultiDoku(final MultiDoku doku, int blockWidth, int blockHeight, Symbols symbols) {
if (doku.getNbSubGrids() == 1) {
printRectangleSudoku(doku.getSubGrid(0), blockWidth, blockHeight, symbols);
} else {
printMultiDoku(RenderableMultidoku.fromMultidoku(doku), symbols, blockWidth, blockHeight);
}
}
public static void printMultiDokuWithIndex(final MultiDoku doku, int blockWidth, int blockHeight, Symbols symbols) {
if (doku.getNbSubGrids() == 1) {
printRectangleSudokuWithIndex(doku.getSubGrid(0), blockWidth, blockHeight, symbols.getSymbols());
} else {
printMultiDokuWithIndex(RenderableMultidoku.fromMultidoku(doku), symbols.getSymbols(), blockWidth,
blockHeight);
}
}
}

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.sudoku.io; package sudoku.io;
public class SudokuSave { public class SudokuSave {

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.sudoku.io; package sudoku.io;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@@ -10,11 +10,12 @@ import java.util.List;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.polytech.ryuk.sudoku.constraint.Constraint;
import org.polytech.ryuk.sudoku.structure.Block; import sudoku.constraint.Constraint;
import org.polytech.ryuk.sudoku.structure.Cell; import sudoku.structure.Block;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.MultiDoku;
import sudoku.structure.Sudoku;
public class SudokuSerializer { public class SudokuSerializer {
@@ -123,17 +124,13 @@ public class SudokuSerializer {
* @return String, the path of the save. * @return String, the path of the save.
*/ */
public static String saveMultiDoku(final MultiDoku doku) { public static String saveMultiDoku(final MultiDoku doku) {
JSONObject jsonRoot = serializeSudoku(doku); JSONObject jsonRoot = serializeSudoku(doku);
File f = new File("save", "save.json"); File f = new File("save", "save.json");
int i = 0; int i = 0;
while (f.exists()) { while (f.exists()) {
String newName = "save-" + ++i + ".json"; String newName = "save-" + ++i + ".json";
f = new File("save", newName); f = new File("save", newName);
} }
try (FileWriter file = new FileWriter(f)) { try (FileWriter file = new FileWriter(f)) {
file.write(jsonRoot.toString(3)); file.write(jsonRoot.toString(3));
} catch (IOException e) { } catch (IOException e) {
@@ -142,6 +139,27 @@ public class SudokuSerializer {
return f.getAbsolutePath(); return f.getAbsolutePath();
} }
public static String saveMultiDoku(final MultiDoku doku, final int saveToOverwrite) {
File f;
if (saveToOverwrite == 0) {
f = new File("save", "save.json");
}
else {
f = new File("save", "save-" + saveToOverwrite + ".json");
}
if (!f.exists()) {
return saveMultiDoku(doku);
}
else {
try (FileWriter file = new FileWriter(f)) {
file.write(serializeSudoku(doku).toString(3));
} catch (IOException e) {
e.printStackTrace();
}
return f.getAbsolutePath();
}
}
/** /**
* Get a MultiDoku from a pre-existing json save file. * Get a MultiDoku from a pre-existing json save file.
* *

View File

@@ -1,10 +1,10 @@
package org.polytech.ryuk.sudoku.solver; package sudoku.solver;
import java.util.List; import java.util.List;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import org.polytech.ryuk.sudoku.structure.Cell; import sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.MultiDoku;
public class BacktrackingSolver implements Solver { public class BacktrackingSolver implements Solver {

View File

@@ -0,0 +1,54 @@
package sudoku.solver;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import sudoku.structure.Cell;
import sudoku.structure.MultiDoku;
public class HintHelper {
public static record Hint(Cell cell, int newValue) {
}
public static Hint getHint(MultiDoku doku, Solver solver) {
doku.getStateManager().pushState();
doku.clearMutableCells();
if (!solver.solve(doku))
return null;
var stateSolved = doku.getStateManager().popAndGetState();
// find differences
Map<Cell, Integer> newValues = new HashMap<>();
for (var entry : stateSolved.entrySet()) {
Cell cell = entry.getKey();
// we only want the cells that can be filled
if (!cell.isMutable())
continue;
int oldValue = cell.getSymbolIndex();
int newValue = stateSolved.get(cell);
if (oldValue == newValue)
continue;
// we have to clear the cell
if (newValue == Cell.NOSYMBOL)
return new Hint(cell, newValue);
// we have to change the cell value
if (oldValue != Cell.NOSYMBOL && newValue != oldValue)
return new Hint(cell, newValue);
// there is a valid move
newValues.put(cell, newValue);
}
// this is too complex just for fetching a random entry, but whatever ...
Random r = new Random();
List<Cell> cells = new ArrayList<>(newValues.keySet());
Cell randomCell = cells.get(r.nextInt(cells.size()));
int randomCellValue = newValues.get(randomCell);
return new Hint(randomCell, randomCellValue);
}
}

View File

@@ -1,13 +1,14 @@
package org.polytech.ryuk.sudoku.solver; package sudoku.solver;
import java.util.List; import java.util.List;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.logging.Level; import java.util.logging.Level;
import org.polytech.ryuk.sudoku.io.SudokuPrinter; import gui.Symbols;
import org.polytech.ryuk.sudoku.structure.Cell; import sudoku.io.SudokuPrinter;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.MultiDoku;
import sudoku.structure.Sudoku;
public class HumanSolver implements Solver { public class HumanSolver implements Solver {
@@ -26,7 +27,8 @@ public class HumanSolver implements Solver {
logger.log(Level.FINE, logger.log(Level.FINE,
'\n' + SudokuPrinter.toStringRectangleSudoku(sudoku, '\n' + SudokuPrinter.toStringRectangleSudoku(sudoku,
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(), sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(),
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth())); sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth(),
Symbols.Numbers));
if (doku.isSolved()) { if (doku.isSolved()) {
return true; return true;

View File

@@ -1,14 +1,15 @@
package org.polytech.ryuk.sudoku.solver; package sudoku.solver;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.logging.Level; import java.util.logging.Level;
import org.polytech.ryuk.sudoku.io.SudokuPrinter; import gui.Symbols;
import org.polytech.ryuk.sudoku.structure.Cell; import sudoku.io.SudokuPrinter;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.MultiDoku;
import sudoku.structure.Sudoku;
public class MixedSolver implements Solver{ public class MixedSolver implements Solver{
@@ -32,7 +33,8 @@ public class MixedSolver implements Solver{
'\n' + SudokuPrinter.toStringRectangleSudoku( '\n' + SudokuPrinter.toStringRectangleSudoku(
sudoku, sudoku,
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(), sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(),
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth())); sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth(),
Symbols.Numbers));
if (doku.isSolved()) { if (doku.isSolved()) {
return true; return true;

View File

@@ -1,14 +1,15 @@
package org.polytech.ryuk.sudoku.solver; package sudoku.solver;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.logging.Level; import java.util.logging.Level;
import org.polytech.ryuk.sudoku.io.SudokuPrinter; import gui.Symbols;
import org.polytech.ryuk.sudoku.structure.Cell; import sudoku.io.SudokuPrinter;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.MultiDoku;
import sudoku.structure.Sudoku;
public class RandomSolver implements Solver { public class RandomSolver implements Solver {
@@ -18,7 +19,6 @@ public class RandomSolver implements Solver {
* de backtracking. * de backtracking.
* *
* @param doku Multidoku, à résoudre * @param doku Multidoku, à résoudre
* @param rand Random, pour tester aléatoirement les symboles
* @return boolean, true s'il est résolu ou false s'il ne l'est pas. * @return boolean, true s'il est résolu ou false s'il ne l'est pas.
*/ */
@Override @Override
@@ -32,7 +32,8 @@ public class RandomSolver implements Solver {
logger.log(Level.FINE, logger.log(Level.FINE,
'\n' + SudokuPrinter.toStringRectangleSudoku(sudoku, '\n' + SudokuPrinter.toStringRectangleSudoku(sudoku,
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(), sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(),
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth())); sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth(),
Symbols.Numbers));
if (doku.isSolved()) { if (doku.isSolved()) {
return true; return true;

View File

@@ -1,10 +1,10 @@
package org.polytech.ryuk.sudoku.solver; package sudoku.solver;
import java.util.List; import java.util.List;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.polytech.ryuk.sudoku.structure.Cell; import sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.MultiDoku;
public interface Solver { public interface Solver {

View File

@@ -1,9 +1,9 @@
package org.polytech.ryuk.sudoku.solver; package sudoku.solver;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.structure.MultiDoku;
import org.polytech.ryuk.sudoku.structure.Sudoku; import sudoku.structure.Sudoku;
/** /**
* Class de test non utilisé * Class de test non utilisé

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.sudoku.structure; package sudoku.structure;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.sudoku.structure; package sudoku.structure;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.sudoku.structure; package sudoku.structure;
/** /**
* Représente les coordonnées d'une Cell * Représente les coordonnées d'une Cell

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.sudoku.structure; package sudoku.structure;
//TODO: melvyn va passer par //TODO: melvyn va passer par
public enum Difficulty { public enum Difficulty {

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.sudoku.structure; package sudoku.structure;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@@ -6,7 +6,7 @@ import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.Set; import java.util.Set;
import org.polytech.ryuk.sudoku.io.SudokuSerializer; import sudoku.io.SudokuSerializer;
/** /**
* @class MultiDoku * @class MultiDoku
@@ -81,9 +81,9 @@ public class MultiDoku {
} }
/** /**
* Check si le MultiDoku est valide, en fonction de ses sous-Sudokus. * Check si le MultiDoku est résolu, c'est à dire complet et cohérent avec ses contraintes.
* *
* @return boolean, true s'il est valide et false sinon. * @return boolean, true s'il est résolu et false sinon.
*/ */
public boolean isSolved() { public boolean isSolved() {
for (Sudoku sudoku : this.subGrids) { for (Sudoku sudoku : this.subGrids) {

View File

@@ -0,0 +1,49 @@
package sudoku.structure;
import java.util.HashMap;
import java.util.Map;
import java.util.Stack;
//TODO: doc
public class StateManager {
private final Stack<Map<Cell, Integer>> states;
private final MultiDoku doku;
public StateManager(MultiDoku doku) {
this.states = new Stack<>();
this.doku = doku;
}
public Map<Cell, Integer> pushState() {
states.add(saveState());
return states.getLast();
}
public void popState() {
assert (states.size() > 0);
restoreState(states.pop());
}
public Map<Cell, Integer> popAndGetState() {
assert (states.size() > 0);
var currentState = saveState();
restoreState(states.pop());
return currentState;
}
private void restoreState(Map<Cell, Integer> state) {
for (var entry : state.entrySet()) {
entry.getKey().setSymbolIndex(entry.getValue());
}
}
private Map<Cell, Integer> saveState() {
Map<Cell, Integer> state = new HashMap<>();
for (Cell cell : this.doku.getCells()) {
state.put(cell, cell.getSymbolIndex());
}
return state;
}
}

View File

@@ -1,10 +1,13 @@
package org.polytech.ryuk.sudoku.structure; package sudoku.structure;
import sudoku.constraint.BlockConstraint;
import sudoku.constraint.Constraint;
import sudoku.constraint.IConstraint;
import sudoku.io.SudokuPrinter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.polytech.ryuk.sudoku.constraint.Constraint;
/** /**
* @class Sudoku * @class Sudoku
* @brief Représent un Sudoku * @brief Représent un Sudoku
@@ -242,7 +245,7 @@ public class Sudoku {
} }
/** /**
* Vérifie si le Sudoku est résolue, soit complet et cohérent avec ses contraintes. * Vérifie si le Sudoku est résolu, c'est à dire complet et cohérent avec ses contraintes.
* @return boolean, valant true si le Sudoku est résolu, false sinon. * @return boolean, valant true si le Sudoku est résolu, false sinon.
*/ */
public boolean isSolved() { public boolean isSolved() {

View File

@@ -1,4 +1,4 @@
package org.polytech.ryuk.sudoku.structure; package sudoku.structure;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
@@ -9,10 +9,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import org.polytech.ryuk.sudoku.constraint.Constraint; import sudoku.constraint.Constraint;
import org.polytech.ryuk.sudoku.io.SudokuSerializer; import sudoku.io.SudokuSerializer;
import org.polytech.ryuk.sudoku.solver.RandomSolver; import sudoku.solver.RandomSolver;
import org.polytech.ryuk.sudoku.solver.Solver; import sudoku.solver.Solver;
public class SudokuFactory { public class SudokuFactory {

View File

@@ -0,0 +1,14 @@
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package sudoku;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class AppTest {
@Test void appHasAGreeting() {
Main classUnderTest = new Main();
assertNotNull(classUnderTest.getGreeting(), "app should have a greeting");
}
}

View File

@@ -8,10 +8,11 @@ import java.util.Random;
import org.json.JSONObject; import org.json.JSONObject;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.polytech.ryuk.sudoku.io.SudokuSerializer;
import org.polytech.ryuk.sudoku.solver.RandomSolver; import sudoku.io.SudokuSerializer;
import org.polytech.ryuk.sudoku.structure.MultiDoku; import sudoku.solver.RandomSolver;
import org.polytech.ryuk.sudoku.structure.SudokuFactory; import sudoku.structure.MultiDoku;
import sudoku.structure.SudokuFactory;
public class SudokuSerializerTest { public class SudokuSerializerTest {

View File

@@ -1,19 +1,19 @@
package sudoku.solver; package sudoku.solver;
import gui.Symbols;
import org.junit.jupiter.api.Test;
import sudoku.io.SudokuPrinter;
import sudoku.io.SudokuSerializer;
import sudoku.structure.Cell;
import sudoku.structure.MultiDoku;
import sudoku.structure.Sudoku;
import sudoku.structure.SudokuFactory;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import org.junit.jupiter.api.Test;
import org.polytech.ryuk.sudoku.io.SudokuPrinter;
import org.polytech.ryuk.sudoku.io.SudokuSerializer;
import org.polytech.ryuk.sudoku.solver.RandomSolver;
import org.polytech.ryuk.sudoku.structure.Cell;
import org.polytech.ryuk.sudoku.structure.MultiDoku;
import org.polytech.ryuk.sudoku.structure.Sudoku;
import org.polytech.ryuk.sudoku.structure.SudokuFactory;
class SolverTest { class SolverTest {
@Test @Test
@@ -39,7 +39,8 @@ class SolverTest {
assert (sudokuToTest.setImmutableCellsSymbol(immutableCells)); assert (sudokuToTest.setImmutableCellsSymbol(immutableCells));
SudokuPrinter.printRectangleSudoku(dokuToTest.getSubGrid(0), 3, 3); //SudokuPrinter.printRectangleSudoku(dokuToTest.getSubGrid(0), 3, 3);
SudokuPrinter.printMultiDoku(dokuToTest, 3, 3, Symbols.Numbers);
List<Integer> correctCells = List.of(7, 6, 0, 3, 4, 2, 8, 5, 1, List<Integer> correctCells = List.of(7, 6, 0, 3, 4, 2, 8, 5, 1,
2, 3, 8, 1, 5, 6, 7, 0, 4, 2, 3, 8, 1, 5, 6, 7, 0, 4,
@@ -54,14 +55,15 @@ class SolverTest {
sudokuResult.setCellsSymbol(correctCells); sudokuResult.setCellsSymbol(correctCells);
System.out.println("\n****************************Doku Control\n"); System.out.println("\n****************************Doku Control\n");
SudokuPrinter.printRectangleSudoku(sudokuResult, 3, 3); SudokuPrinter.printRectangleSudoku(sudokuResult, 3, 3, Symbols.Russian);
assert (dokuResult.isSolved()); assert (dokuResult.isSolved());
new RandomSolver().solve(dokuToTest); new RandomSolver().solve(dokuToTest);
System.out.println("\n****************************\nDoku solved"); System.out.println("\n****************************\nDoku solved");
SudokuPrinter.printRectangleSudoku(dokuToTest.getSubGrid(0), 3, 3); //SudokuPrinter.printRectangleSudoku(dokuToTest.getSubGrid(0), 3, 3);
SudokuPrinter.printMultiDoku(dokuToTest, 3, 3, Symbols.Emojis);
assert (dokuToTest.isSolved()); assert (dokuToTest.isSolved());
@@ -98,6 +100,7 @@ class SolverTest {
new RandomSolver().solve(dokuToTest3); new RandomSolver().solve(dokuToTest3);
SudokuPrinter.printRectangleSudoku(dokuToTest3.getSubGrid(0), 3, 3); //SudokuPrinter.printRectangleSudoku(dokuToTest3.getSubGrid(0), 3, 3);
SudokuPrinter.printMultiDoku(dokuToTest3, 3, 3, Symbols.Letters);
} }
} }