Compare commits
28 Commits
8c672e24ad
...
createPlus
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e67e7a9d4 | |||
|
|
70eef1646d | ||
| 5dfe4382fe | |||
|
|
059886c2a4 | ||
|
|
129c3ef0b2 | ||
| 14d0521215 | |||
| 7568208045 | |||
| 86aa6e9bb5 | |||
| 91c645e34f | |||
| 78bdefebe5 | |||
| 3e30332245 | |||
| 275878932b | |||
| 68d577a99a | |||
| fa3124220d | |||
| 3a009256c5 | |||
| d09bf6e9ce | |||
| 5da915932d | |||
| da422e78b8 | |||
| f0a0a8e328 | |||
| 436b641269 | |||
| 34a59546e6 | |||
| 9e2421accf | |||
| 52ca8b208c | |||
|
|
140d37fbd9 | ||
|
|
2b3581a400 | ||
| a6b1fae230 | |||
| a20a5387a7 | |||
| a1032335a5 |
@@ -16,25 +16,14 @@ project.ext.os = System.properties['os.name'].toLowerCase().split(" ")[0]
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
flatDir {
|
||||
dirs("$rootProject.projectDir/libs")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Use JUnit Jupiter for testing.
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1'
|
||||
|
||||
// This dependency is used by the application.
|
||||
implementation 'com.google.guava:guava:31.1-jre'
|
||||
|
||||
// uml
|
||||
implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.26.2'
|
||||
|
||||
implementation 'org.json:json:20250107'
|
||||
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.2'
|
||||
|
||||
implementation "io.github.spair:imgui-java-app:1.88.0"
|
||||
|
||||
implementation "org.lwjgl:lwjgl-stb:3.3.4"
|
||||
@@ -47,9 +36,16 @@ application {
|
||||
mainClass = 'gui.Main'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
// Use JUnit Platform for unit tests.
|
||||
useJUnitPlatform()
|
||||
// Add libraries into the final jar
|
||||
jar {
|
||||
archiveBaseName = rootProject.getName()
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
manifest {
|
||||
attributes "Main-Class": application.mainClass
|
||||
}
|
||||
from {
|
||||
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
}
|
||||
|
||||
run {
|
||||
|
||||
@@ -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
|
||||
]
|
||||
}]
|
||||
}
|
||||
@@ -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
|
||||
]
|
||||
}]
|
||||
}
|
||||
@@ -1,10 +1,16 @@
|
||||
package gui;
|
||||
|
||||
import gui.constants.Fonts;
|
||||
import gui.constants.Images;
|
||||
import gui.constants.Symbols;
|
||||
import gui.menu.MainMenu;
|
||||
import gui.menu.StateMachine;
|
||||
import imgui.ImGui;
|
||||
import imgui.app.Application;
|
||||
import imgui.app.Configuration;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.structure.Difficulty;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.SudokuFactory;
|
||||
|
||||
public class Main extends Application {
|
||||
|
||||
@@ -40,6 +46,13 @@ public class Main extends Application {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(new Main());
|
||||
MultiDoku doku = SudokuFactory.createBasicPlusShapedMultidoku(3, 3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
try {
|
||||
SudokuFactory.fillDoku(doku, Difficulty.Easy);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
SudokuPrinter.printMultiDoku(doku, 3, 3, Symbols.Numbers);
|
||||
//launch(new Main());
|
||||
}
|
||||
}
|
||||
@@ -90,29 +90,23 @@ public class RenderableMultidoku {
|
||||
}
|
||||
|
||||
private static Coordinate getMaxSudokuCoordinate(Map<Sudoku, Coordinate> sudokusOffset) {
|
||||
Coordinate maxCoordinate = null;
|
||||
Sudoku maxSudoku = null;
|
||||
float maxDistanceSquared = 0;
|
||||
int maxX = 0;
|
||||
int maxY = 0;
|
||||
Sudoku lastSudoku = null;
|
||||
for (var entry : sudokusOffset.entrySet()) {
|
||||
Coordinate coordinate = entry.getValue();
|
||||
float distanceSquared = coordinate.getX() * coordinate.getX() + coordinate.getY() * coordinate.getY();
|
||||
if (maxCoordinate == null) {
|
||||
maxCoordinate = coordinate;
|
||||
maxDistanceSquared = distanceSquared;
|
||||
maxSudoku = entry.getKey();
|
||||
if (coordinate.getX() > maxX)
|
||||
maxX = coordinate.getX();
|
||||
if (coordinate.getY() > maxY)
|
||||
maxY = coordinate.getY();
|
||||
lastSudoku = entry.getKey();
|
||||
}
|
||||
|
||||
if (distanceSquared > maxDistanceSquared) {
|
||||
maxDistanceSquared = distanceSquared;
|
||||
maxSudoku = entry.getKey();
|
||||
maxCoordinate = coordinate;
|
||||
}
|
||||
}
|
||||
Coordinate maxCoordinate = new Coordinate(maxX, maxY);
|
||||
// tous les sudokus sont censés faire la même taille
|
||||
int sudokuSize = lastSudoku.getSize();
|
||||
|
||||
int blockWidth = maxSudoku.getBlockWidth();
|
||||
int blockHeight = maxSudoku.getSize() / blockWidth;
|
||||
|
||||
return new Coordinate(maxCoordinate.getX() + maxSudoku.getSize(), maxCoordinate.getY() + maxSudoku.getSize());
|
||||
return new Coordinate(maxCoordinate.getX() + sudokuSize, maxCoordinate.getY() + sudokuSize);
|
||||
}
|
||||
|
||||
public static RenderableMultidoku fromMultidoku(MultiDoku doku) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package gui;
|
||||
package gui.constants;
|
||||
|
||||
import imgui.ImFont;
|
||||
import imgui.ImFontConfig;
|
||||
@@ -1,4 +1,4 @@
|
||||
package gui;
|
||||
package gui.constants;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package gui;
|
||||
package gui.constants;
|
||||
|
||||
public class Options {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package gui;
|
||||
package gui.constants;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import sudoku.constraint.Constraint;
|
||||
import sudoku.constraint.IConstraint;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.SudokuFactory;;
|
||||
|
||||
@@ -14,10 +14,14 @@ public enum SudokuType {
|
||||
(constraints, params) -> SudokuFactory.createBasicEmptyRectangleDoku(params[0], params[1], constraints)),
|
||||
RandomBloc("Blocs aléatoires", 1,
|
||||
(constraints, params) -> SudokuFactory.createBasicEmptyRandomBlockDoku(params[0], constraints)),
|
||||
MultiDokuSquare("Multidoku carré (X)", 1,
|
||||
MultiDokuXSquare("Multidoku carré (X)", 1,
|
||||
(constraints, params) -> SudokuFactory.createBasicXShapedMultidoku(params[0], constraints)),
|
||||
MultidokuRectangle("Multidoku rectangle (X)", 2,
|
||||
(constraints, params) -> SudokuFactory.createBasicXShapedMultidoku(params[0], params[1], constraints));
|
||||
MultidokuXRectangle("Multidoku rectangle (X)", 2,
|
||||
(constraints, params) -> SudokuFactory.createBasicXShapedMultidoku(params[0], params[1], constraints)),
|
||||
MultiDokuPSquare("Multidoku carré (+)", 1,
|
||||
(constraints, params) -> SudokuFactory.createBasicPlusShapedMultidoku(params[0], constraints)),
|
||||
MultiDokuPRectangle("Multidoku rectangle (+)", 2,
|
||||
(constraints, params) -> SudokuFactory.createBasicPlusShapedMultidoku(params[0], params[1], constraints));
|
||||
|
||||
String displayName;
|
||||
SudokuMaker maker;
|
||||
@@ -33,7 +37,7 @@ public enum SudokuType {
|
||||
return this.displayName;
|
||||
}
|
||||
|
||||
public MultiDoku createDoku(List<Constraint> constraints, int... params) {
|
||||
public MultiDoku createDoku(List<IConstraint> constraints, int... params) {
|
||||
return maker.makeSudoku(constraints, params);
|
||||
}
|
||||
|
||||
@@ -43,7 +47,7 @@ public enum SudokuType {
|
||||
|
||||
@FunctionalInterface
|
||||
private static interface SudokuMaker {
|
||||
MultiDoku makeSudoku(List<Constraint> constraints, int... params);
|
||||
MultiDoku makeSudoku(List<IConstraint> constraints, int... params);
|
||||
}
|
||||
|
||||
private static final String[] dokuNames;
|
||||
@@ -1,4 +1,4 @@
|
||||
package gui;
|
||||
package gui.constants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -20,7 +20,8 @@ public class MultiMenu extends BaseView {
|
||||
private void renderCreate() {
|
||||
ImVec2 displaySize = ImGui.getIO().getDisplaySize();
|
||||
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")) {
|
||||
try {
|
||||
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, (short) port.get()));
|
||||
@@ -35,12 +36,12 @@ public class MultiMenu extends BaseView {
|
||||
ImVec2 displaySize = ImGui.getIO().getDisplaySize();
|
||||
ImGui.beginChild("##JoinGame", new ImVec2(displaySize.x / 2.0f, displaySize.y * 8.0f / 9.0f));
|
||||
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")) {
|
||||
try {
|
||||
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, address.get(), (short) port.get()));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,8 @@ public class MultiPlayerView extends BaseView {
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package gui.menu;
|
||||
|
||||
import gui.Options;
|
||||
import gui.Symbols;
|
||||
import gui.constants.Options;
|
||||
import gui.constants.Symbols;
|
||||
import imgui.ImGui;
|
||||
import imgui.type.ImInt;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package gui.menu;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import gui.AnimatedBackground;
|
||||
import gui.widget.AnimatedBackground;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImVec2;
|
||||
import imgui.flag.ImGuiKey;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package gui.menu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
import gui.widget.SudokuRenderer;
|
||||
@@ -7,9 +9,12 @@ import imgui.ImGui;
|
||||
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.SolverStep;
|
||||
import sudoku.solver.HintHelper.Hint;
|
||||
import sudoku.structure.MultiDoku;
|
||||
|
||||
public class SudokuView extends BaseView {
|
||||
@@ -20,6 +25,8 @@ public class SudokuView extends BaseView {
|
||||
private String lastSavePath = null;
|
||||
|
||||
private boolean resolved = false;
|
||||
// if the solver can't solve
|
||||
private volatile boolean unresolved = false;
|
||||
|
||||
public SudokuView(StateMachine stateMachine, MultiDoku doku) {
|
||||
super(stateMachine);
|
||||
@@ -68,10 +75,27 @@ public class SudokuView extends BaseView {
|
||||
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) {
|
||||
resolveThread = new Thread(() -> {
|
||||
List<SolverStep> steps = new ArrayList<>();
|
||||
try {
|
||||
solver.solve(this.doku);
|
||||
unresolved = !solver.solve(this.doku, steps);
|
||||
} catch (CancellationException e) {
|
||||
System.out.println("The user is bored !");
|
||||
}
|
||||
@@ -79,6 +103,11 @@ public class SudokuView extends BaseView {
|
||||
});
|
||||
}
|
||||
|
||||
private void renderResolvedText() {
|
||||
if (this.resolved)
|
||||
ImGui.text("Bravo !");
|
||||
}
|
||||
|
||||
private void renderSolvePopup() {
|
||||
if (ImGui.beginPopup("solve")) {
|
||||
if (ImGui.button("Résoudre avec backtrace")) {
|
||||
@@ -102,16 +131,14 @@ public class SudokuView extends BaseView {
|
||||
ImGui.beginDisabled();
|
||||
|
||||
if (!this.resolved && centeredButton("Résoudre")) {
|
||||
// beginSolve = true;
|
||||
ImGui.openPopup("solve");
|
||||
}
|
||||
|
||||
if (resolveThread != null)
|
||||
ImGui.endDisabled();
|
||||
|
||||
if (this.resolved) {
|
||||
ImGui.text("Bravo !");
|
||||
}
|
||||
renderResolvedText();
|
||||
renderUnsolvableText();
|
||||
|
||||
renderSolvePopup();
|
||||
}
|
||||
@@ -128,9 +155,17 @@ public class SudokuView extends BaseView {
|
||||
}
|
||||
}
|
||||
|
||||
private void renderClearButton() {
|
||||
if (centeredButton("Effacer")) {
|
||||
this.doku.clearMutableCells();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
sudokuRenderer.render();
|
||||
renderHintButton();
|
||||
renderClearButton();
|
||||
renderSolveButton();
|
||||
renderSaveButton();
|
||||
renderCancelButton();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package gui;
|
||||
package gui.widget;
|
||||
|
||||
import gui.constants.Images;
|
||||
import gui.constants.Options;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImVec2;
|
||||
import imgui.flag.ImGuiWindowFlags;
|
||||
@@ -9,11 +9,11 @@ import java.util.Set;
|
||||
import common.ConsumerSignal;
|
||||
import common.Signal;
|
||||
import gui.ColorGenerator;
|
||||
import gui.Fonts;
|
||||
import gui.Options;
|
||||
import gui.RenderableMultidoku;
|
||||
import gui.Symbols;
|
||||
import gui.ColorGenerator.Color;
|
||||
import gui.RenderableMultidoku;
|
||||
import gui.constants.Fonts;
|
||||
import gui.constants.Options;
|
||||
import gui.constants.Symbols;
|
||||
import imgui.ImGui;
|
||||
import imgui.ImVec2;
|
||||
import imgui.ImVec4;
|
||||
@@ -84,7 +84,7 @@ public class SudokuRenderer {
|
||||
}
|
||||
} else {
|
||||
if (ImGui.button(Options.Symboles.getSymbols().get(i), cellSize)) {
|
||||
if (currentCell.trySetValue(i))
|
||||
currentCell.setSymbolIndex(i);
|
||||
this.onCellChange.emit(currentCell);
|
||||
if (this.doku.getDoku().isSolved())
|
||||
this.onResolve.emit();
|
||||
@@ -117,6 +117,7 @@ public class SudokuRenderer {
|
||||
ImGui.sameLine();
|
||||
int index = y * doku.getWidth() + x;
|
||||
Cell cell = doku.getCell(x, y);
|
||||
ImGui.beginDisabled(cell == null);
|
||||
if (cell == null) {
|
||||
ImGui.pushStyleColor(ImGuiCol.Border, TRANSPARENT);
|
||||
ImGui.pushStyleColor(ImGuiCol.Button, TRANSPARENT);
|
||||
@@ -141,6 +142,7 @@ public class SudokuRenderer {
|
||||
currentCell = cell;
|
||||
}
|
||||
}
|
||||
ImGui.endDisabled();
|
||||
ImGui.popStyleColor(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import common.ConsumerSignal;
|
||||
import gui.SudokuType;
|
||||
import gui.constants.SudokuType;
|
||||
import imgui.ImGui;
|
||||
import imgui.extension.imguifiledialog.ImGuiFileDialog;
|
||||
import imgui.extension.imguifiledialog.flag.ImGuiFileDialogFlags;
|
||||
import imgui.type.ImBoolean;
|
||||
import imgui.type.ImInt;
|
||||
import sudoku.constraint.Constraint;
|
||||
import sudoku.constraint.IConstraint;
|
||||
import sudoku.structure.Difficulty;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.SudokuFactory;
|
||||
@@ -24,7 +25,7 @@ public class SudokuSelector {
|
||||
|
||||
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 ImInt sudokuSize = new ImInt(3);
|
||||
@@ -40,18 +41,18 @@ public class SudokuSelector {
|
||||
initConstraints();
|
||||
}
|
||||
|
||||
private List<Constraint> getConstraints() {
|
||||
List<Constraint> constraints = new ArrayList<>();
|
||||
private List<IConstraint> getConstraints() {
|
||||
List<IConstraint> constraints = new ArrayList<>();
|
||||
for (int i = 0; i < this.contraints.size(); i++) {
|
||||
if (this.contraints.get(i).get())
|
||||
constraints.add(Constraint.values()[i]);
|
||||
constraints.add(Constraint.values()[i].getConstraint());
|
||||
}
|
||||
return constraints;
|
||||
}
|
||||
|
||||
private void initConstraints() {
|
||||
for (Constraint cons : Constraint.values()) {
|
||||
contraints.add(new ImBoolean(SudokuFactory.DEFAULT_CONSTRAINTS.contains(cons)));
|
||||
contraints.add(new ImBoolean(SudokuFactory.DEFAULT_CONSTRAINTS.contains(cons.getConstraint())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +99,8 @@ public class SudokuSelector {
|
||||
SudokuType currentType = SudokuType.values()[sudokuType.get()];
|
||||
switch (currentType.getMakerParamCount()) {
|
||||
case 1:
|
||||
ImGui.inputInt("Taille", sudokuSize);
|
||||
if (ImGui.inputInt("Taille", sudokuSize))
|
||||
sudokuSize.set(Math.clamp(sudokuSize.get(), 1, 10));
|
||||
if (ImGui.button(confirmMessage)) {
|
||||
selectSudoku(currentType.createDoku(getConstraints(), sudokuSize.get()), false);
|
||||
}
|
||||
@@ -108,8 +110,10 @@ public class SudokuSelector {
|
||||
break;
|
||||
|
||||
case 2:
|
||||
ImGui.inputInt("Largeur", sudokuHeight);
|
||||
ImGui.inputInt("Longueur", sudokuWidth);
|
||||
if (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)) {
|
||||
selectSudoku(currentType.createDoku(getConstraints(), sudokuWidth.get(), sudokuHeight.get()),
|
||||
false);
|
||||
|
||||
@@ -4,16 +4,14 @@
|
||||
package sudoku;
|
||||
|
||||
import gui.RenderableMultidoku;
|
||||
import gui.Symbols;
|
||||
import gui.constants.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!";
|
||||
@@ -22,12 +20,21 @@ public class Main {
|
||||
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) {
|
||||
@@ -35,7 +42,8 @@ public class Main {
|
||||
/*
|
||||
voidTest();
|
||||
filledTest();
|
||||
filledTest();
|
||||
overwriteTest(0);
|
||||
overwriteTest(17)
|
||||
*/
|
||||
console.welcome();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package sudoku.constraint;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
public interface IConstraint {
|
||||
|
||||
public interface IConstraint extends Serializable {
|
||||
boolean canBePlaced(final Sudoku s, int x, int y, int newSymbolIndex);
|
||||
|
||||
default List<Integer> getPossibleSymbols(final Sudoku s, int x, int y) {
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
package sudoku.io;
|
||||
|
||||
import gui.RenderableMultidoku;
|
||||
import gui.Symbols;
|
||||
import gui.constants.Symbols;
|
||||
import sudoku.constraint.*;
|
||||
import sudoku.solver.RandomSolver;
|
||||
import sudoku.solver.Solver;
|
||||
import sudoku.structure.Difficulty;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.SudokuFactory;
|
||||
import sudoku.solver.*;
|
||||
import sudoku.structure.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ConsoleInterface {
|
||||
@@ -19,48 +15,104 @@ public class ConsoleInterface {
|
||||
|
||||
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.");
|
||||
start();
|
||||
System.out.println("This is the project of Melvyn Bauvent, Lilas Grenier and Simon Pribylski.");
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
public void start(){
|
||||
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;
|
||||
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 {
|
||||
listSymbols = Symbols.Numbers.getSymbols();
|
||||
}
|
||||
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), " +
|
||||
List<String> listSymbols = pickSymbols(numberOfSymbols);
|
||||
List<IConstraint> 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 {
|
||||
} else {
|
||||
doku = SudokuFactory.createBasicEmptyRectangleDoku(width, height, listConstraints);
|
||||
}
|
||||
RenderableMultidoku rm = RenderableMultidoku.fromMultidoku(doku);
|
||||
System.out.println("Your sudoku will look like this:");
|
||||
SudokuPrinter.printMultiDoku(rm, listSymbols, 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))");
|
||||
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);
|
||||
}
|
||||
else {
|
||||
generatePartialDoku(doku, difficulty);
|
||||
}
|
||||
System.out.println("Here's your sudoku !");
|
||||
SudokuPrinter.printMultiDoku(rm, listSymbols, width, height);
|
||||
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() {
|
||||
@@ -91,7 +143,11 @@ public class ConsoleInterface {
|
||||
return (size > 0);
|
||||
}
|
||||
|
||||
private void pickSymbols(List<String> listSymbols, int numberOfSymbols) {
|
||||
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 + ": ");
|
||||
@@ -103,13 +159,24 @@ public class ConsoleInterface {
|
||||
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')");
|
||||
private List<IConstraint> getListConstraints() {
|
||||
List<IConstraint> 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);
|
||||
listConstraints.add(Constraint.Diagonal.getConstraint());
|
||||
}
|
||||
return listConstraints;
|
||||
}
|
||||
@@ -117,10 +184,14 @@ public class ConsoleInterface {
|
||||
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;
|
||||
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);
|
||||
@@ -133,4 +204,102 @@ public class ConsoleInterface {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package sudoku.io;
|
||||
|
||||
import gui.RenderableMultidoku;
|
||||
import gui.Symbols;
|
||||
import gui.constants.Symbols;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.Sudoku;
|
||||
@@ -31,8 +31,41 @@ public class SudokuPrinter {
|
||||
Cell c = s.getCell(x, y);
|
||||
if (c.getSymbolIndex() == Cell.NOSYMBOL) {
|
||||
line.append(" ");
|
||||
} else {
|
||||
line.append(listSymbols.get(c.getSymbolIndex())).append(" ");
|
||||
}
|
||||
else {
|
||||
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) {
|
||||
@@ -48,7 +81,8 @@ public class SudokuPrinter {
|
||||
printMultiDoku(rm, symbols.getSymbols(), blockWidth, blockHeight);
|
||||
}
|
||||
|
||||
public static void printMultiDoku(final RenderableMultidoku rm, List<String> listSymbols, int blockWidth, int 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++) {
|
||||
@@ -64,12 +98,10 @@ public class SudokuPrinter {
|
||||
if (cell != null) {
|
||||
if (cell.getSymbolIndex() == Cell.NOSYMBOL) {
|
||||
line.append("- ");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
line.append(listSymbols.get(cell.getSymbolIndex())).append(" ");
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
line.append(" ");
|
||||
}
|
||||
}
|
||||
@@ -79,11 +111,50 @@ public class SudokuPrinter {
|
||||
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) {
|
||||
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
|
||||
@@ -96,8 +167,7 @@ public class SudokuPrinter {
|
||||
Cell cell = s.getCell(x, y);
|
||||
if (cell.getSymbolIndex() == Cell.NOSYMBOL) {
|
||||
line.append(" ");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
line.append(listSymbols.get(cell.getSymbolIndex())).append(" ");
|
||||
}
|
||||
|
||||
@@ -115,9 +185,18 @@ public class SudokuPrinter {
|
||||
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 {
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import sudoku.constraint.Constraint;
|
||||
import sudoku.constraint.IConstraint;
|
||||
import sudoku.structure.Block;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
@@ -99,8 +100,17 @@ public class SudokuSerializer {
|
||||
|
||||
// serialize constraints
|
||||
|
||||
for (Constraint cons : sudoku.getConstraints()) {
|
||||
constraintsJsonArray.put(cons.ordinal());
|
||||
for (IConstraint cons : sudoku.getConstraints()) {
|
||||
boolean constraintSerialized = false;
|
||||
for (Constraint enumCons : Constraint.values()) {
|
||||
if (cons.getClass().isAssignableFrom(enumCons.getConstraint().getClass())) {
|
||||
constraintSerialized = true;
|
||||
constraintsJsonArray.put(enumCons.ordinal());
|
||||
}
|
||||
}
|
||||
if (!constraintSerialized) {
|
||||
System.out.println("La contrainte " + cons.getClass() + " n'a pas pu être sérialisé !");
|
||||
}
|
||||
}
|
||||
|
||||
jsonSudoku.put("constraints", constraintsJsonArray);
|
||||
@@ -124,17 +134,14 @@ public class SudokuSerializer {
|
||||
* @return String, the path of the save.
|
||||
*/
|
||||
public static String saveMultiDoku(final MultiDoku doku) {
|
||||
|
||||
JSONObject jsonRoot = serializeSudoku(doku);
|
||||
|
||||
File f = new File("save", "save.json");
|
||||
int i = 0;
|
||||
|
||||
while (f.exists()) {
|
||||
String newName = "save-" + ++i + ".json";
|
||||
f = new File("save", newName);
|
||||
}
|
||||
|
||||
try (FileWriter file = new FileWriter(f)) {
|
||||
file.write(jsonRoot.toString(3));
|
||||
} catch (IOException e) {
|
||||
@@ -143,6 +150,25 @@ public class SudokuSerializer {
|
||||
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.
|
||||
*
|
||||
@@ -217,7 +243,7 @@ public class SudokuSerializer {
|
||||
|
||||
List<Cell> sudokuCells = new ArrayList<>();
|
||||
List<Block> sudokuBlocks = new ArrayList<>();
|
||||
List<Constraint> sudokuConstraints = new ArrayList<>();
|
||||
List<IConstraint> sudokuConstraints = new ArrayList<>();
|
||||
|
||||
for (int j = 0; j < sudokuCellsJsonArray.length(); j++) {
|
||||
int cellID = sudokuCellsJsonArray.getInt(j);
|
||||
@@ -231,7 +257,7 @@ public class SudokuSerializer {
|
||||
|
||||
for (int j = 0; j < sudokuConstraintsJsonArray.length(); j++) {
|
||||
int constraintID = sudokuConstraintsJsonArray.getInt(j);
|
||||
sudokuConstraints.add(Constraint.values()[constraintID]);
|
||||
sudokuConstraints.add(Constraint.values()[constraintID].getConstraint());
|
||||
}
|
||||
|
||||
Sudoku s = new Sudoku(sudokuCells, sudokuBlocks, sudokuConstraints);
|
||||
|
||||
@@ -15,7 +15,7 @@ public class BacktrackingSolver implements Solver {
|
||||
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
|
||||
*/
|
||||
@Override
|
||||
public boolean solve(MultiDoku doku) {
|
||||
public boolean solve(MultiDoku doku, List<SolverStep> steps) {
|
||||
if (Thread.interrupted())
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
|
||||
@@ -34,14 +34,14 @@ public class BacktrackingSolver implements Solver {
|
||||
}
|
||||
|
||||
for (int symbol : possibleSymbols) {
|
||||
|
||||
cellToFill.setSymbolIndex(symbol);
|
||||
if (this.solve(doku)) {
|
||||
addStep(cellToFill, steps);
|
||||
if (this.solve(doku, steps)) {
|
||||
return true;
|
||||
} else {
|
||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||
addStep(cellToFill, steps);
|
||||
}
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
54
app/src/main/java/sudoku/solver/HintHelper.java
Normal file
54
app/src/main/java/sudoku/solver/HintHelper.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import gui.constants.Symbols;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
@@ -18,7 +19,7 @@ public class HumanSolver implements Solver {
|
||||
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
|
||||
*/
|
||||
@Override
|
||||
public boolean solve(MultiDoku doku) {
|
||||
public boolean solve(MultiDoku doku, List<SolverStep> steps) {
|
||||
if (Thread.interrupted())
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
|
||||
@@ -26,7 +27,8 @@ public class HumanSolver implements Solver {
|
||||
logger.log(Level.FINE,
|
||||
'\n' + SudokuPrinter.toStringRectangleSudoku(sudoku,
|
||||
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()) {
|
||||
return true;
|
||||
@@ -45,8 +47,9 @@ public class HumanSolver implements Solver {
|
||||
}
|
||||
|
||||
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
||||
addStep(cellToFill, steps);
|
||||
|
||||
return this.solve(doku);
|
||||
return this.solve(doku, steps);
|
||||
}
|
||||
|
||||
return doku.isSolved();
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Random;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import gui.constants.Symbols;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
@@ -20,7 +21,7 @@ public class MixedSolver implements Solver{
|
||||
* @return boolean, valant true si le MultiDoku est résolu, false sinon.
|
||||
*/
|
||||
@Override
|
||||
public boolean solve(MultiDoku doku) {
|
||||
public boolean solve(MultiDoku doku, List<SolverStep> steps) {
|
||||
Random rand = new Random();
|
||||
|
||||
if (Thread.interrupted()) {
|
||||
@@ -32,7 +33,8 @@ public class MixedSolver implements Solver{
|
||||
'\n' + SudokuPrinter.toStringRectangleSudoku(
|
||||
sudoku,
|
||||
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()) {
|
||||
return true;
|
||||
@@ -47,7 +49,8 @@ public class MixedSolver implements Solver{
|
||||
|
||||
if (possibleSymbols.size() == 1) {
|
||||
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
||||
if (this.solve(doku)) {
|
||||
addStep(cellToFill, steps);
|
||||
if (this.solve(doku, steps)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -57,10 +60,12 @@ public class MixedSolver implements Solver{
|
||||
int nextSymbol = possibleSymbols.get(nextPossibleSymbolIndex);
|
||||
|
||||
cellToFill.setSymbolIndex(nextSymbol);
|
||||
if (this.solve(doku)) {
|
||||
addStep(cellToFill, steps);
|
||||
if (this.solve(doku, steps)) {
|
||||
return true;
|
||||
}
|
||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||
addStep(cellToFill, steps);
|
||||
possibleSymbols.remove(nextPossibleSymbolIndex);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Random;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import gui.constants.Symbols;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
@@ -18,11 +19,10 @@ public class RandomSolver implements Solver {
|
||||
* de backtracking.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
@Override
|
||||
public boolean solve(MultiDoku doku) {
|
||||
public boolean solve(MultiDoku doku, List<SolverStep> steps) {
|
||||
Random rand = new Random();
|
||||
|
||||
if (Thread.interrupted())
|
||||
@@ -32,7 +32,8 @@ public class RandomSolver implements Solver {
|
||||
logger.log(Level.FINE,
|
||||
'\n' + SudokuPrinter.toStringRectangleSudoku(sudoku,
|
||||
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()) {
|
||||
return true;
|
||||
@@ -50,10 +51,12 @@ public class RandomSolver implements Solver {
|
||||
int nextSymbol = possibleSymbols.get(nextPossibleSymbolIndex);
|
||||
|
||||
cellToFill.setSymbolIndex(nextSymbol);
|
||||
if (this.solve(doku)) {
|
||||
addStep(cellToFill, steps);
|
||||
if (this.solve(doku, steps)) {
|
||||
return true;
|
||||
}
|
||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||
addStep(cellToFill, steps);
|
||||
possibleSymbols.remove(nextPossibleSymbolIndex);
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,11 @@ public interface Solver {
|
||||
*/
|
||||
public static final Logger logger = Logger.getLogger("SolverLogger");
|
||||
|
||||
boolean solve(MultiDoku doku);
|
||||
boolean solve(MultiDoku doku, List<SolverStep> solverSteps);
|
||||
|
||||
default boolean solve(MultiDoku doku) {
|
||||
return solve(doku, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compte le nombre de solutions possibles au MultiDoku passé en paramètres.
|
||||
@@ -38,10 +42,20 @@ public interface Solver {
|
||||
cellToFill.setSymbolIndex(symbol);
|
||||
if (solve(doku)) {
|
||||
result++;
|
||||
if (result > 1) {
|
||||
doku.getStateManager().popState();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
doku.getStateManager().popState();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
default void addStep(Cell cell, List<SolverStep> steps) {
|
||||
if (steps == null)
|
||||
return;
|
||||
steps.add(new SolverStep(cell));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
23
app/src/main/java/sudoku/solver/SolverStep.java
Normal file
23
app/src/main/java/sudoku/solver/SolverStep.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package sudoku.solver;
|
||||
|
||||
import sudoku.structure.Cell;
|
||||
|
||||
public class SolverStep {
|
||||
|
||||
private final Cell cell;
|
||||
private final int newValue;
|
||||
|
||||
public SolverStep(Cell cell) {
|
||||
this.cell = cell;
|
||||
this.newValue = cell.getSymbolIndex();
|
||||
}
|
||||
|
||||
public int getNewValue() {
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public Cell getCell() {
|
||||
return cell;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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() {
|
||||
for (Sudoku sudoku : this.subGrids) {
|
||||
|
||||
@@ -15,27 +15,35 @@ public class StateManager {
|
||||
this.doku = doku;
|
||||
}
|
||||
|
||||
public void pushState() {
|
||||
states.add(new HashMap<>());
|
||||
saveState();
|
||||
public Map<Cell, Integer> pushState() {
|
||||
states.add(saveState());
|
||||
return states.getLast();
|
||||
}
|
||||
|
||||
public void popState() {
|
||||
assert (states.size() > 0);
|
||||
restoreState();
|
||||
states.pop();
|
||||
restoreState(states.pop());
|
||||
}
|
||||
|
||||
private void restoreState() {
|
||||
for (var entry : this.states.getLast().entrySet()) {
|
||||
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 void saveState() {
|
||||
private Map<Cell, Integer> saveState() {
|
||||
Map<Cell, Integer> state = new HashMap<>();
|
||||
for (Cell cell : this.doku.getCells()) {
|
||||
states.getLast().put(cell, cell.getSymbolIndex());
|
||||
state.put(cell, cell.getSymbolIndex());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
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.List;
|
||||
|
||||
import sudoku.constraint.Constraint;
|
||||
import sudoku.constraint.IConstraint;
|
||||
|
||||
/**
|
||||
* @class Sudoku
|
||||
* @brief Représent un Sudoku
|
||||
@@ -25,13 +23,14 @@ public class Sudoku {
|
||||
/**
|
||||
* Liste des contraintes (TODO) du Sudoku.
|
||||
*/
|
||||
private final List<Constraint> constraints;
|
||||
private final List<IConstraint> constraints;
|
||||
/**
|
||||
* Largeur des Blocks s'ils sont rectangulaires, valant 0 si ce n'est pas le cas.
|
||||
* Largeur des Blocks s'ils sont rectangulaires, valant 0 si ce n'est pas le
|
||||
* cas.
|
||||
*/
|
||||
private int blockWidth;
|
||||
|
||||
public Sudoku(List<Cell> cells, List<Block> blocks, List<Constraint> constraints) {
|
||||
public Sudoku(List<Cell> cells, List<Block> blocks, List<IConstraint> constraints) {
|
||||
this.cells = cells;
|
||||
this.blocks = blocks;
|
||||
this.constraints = constraints;
|
||||
@@ -49,6 +48,7 @@ public class Sudoku {
|
||||
|
||||
/**
|
||||
* Transforme des coordonées d'une Cell en index.
|
||||
*
|
||||
* @param x int, abscisse.
|
||||
* @param y int, ordonnée.
|
||||
* @return int, index correspondant.
|
||||
@@ -59,7 +59,9 @@ public class Sudoku {
|
||||
|
||||
/**
|
||||
* Vérifie que des coordonnées correspondent bien à une Cell dans le Sudoku.
|
||||
* @return boolean, valant true si les coordonnées sont dans les bornes du Sudoku, false sinon.
|
||||
*
|
||||
* @return boolean, valant true si les coordonnées sont dans les bornes du
|
||||
* Sudoku, false sinon.
|
||||
*/
|
||||
public boolean isValidCoords(int x, int y) {
|
||||
int index = toIndex(x, y);
|
||||
@@ -68,21 +70,25 @@ public class Sudoku {
|
||||
|
||||
/**
|
||||
* Vérifie que l'index correspond bien à une Cell dans le Sudoku.
|
||||
* @return boolean, valant true si l'index est dans les bornes du Sudoku, false sinon.
|
||||
*
|
||||
* @return boolean, valant true si l'index est dans les bornes du Sudoku, false
|
||||
* sinon.
|
||||
*/
|
||||
public boolean isValidCoords(int index) {
|
||||
return index < getSize() * getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Teste si on peut placer la value dans la Cell aux coordonnées x, y d'après les contraintes du Sudoku.
|
||||
* Teste si on peut placer la value dans la Cell aux coordonnées x, y d'après
|
||||
* les contraintes du Sudoku.
|
||||
*
|
||||
* @param x int, abscisse de la Cell voulue.
|
||||
* @param y int, ordonnée de la Cell voulue.
|
||||
* @param value int, index du symbole qu'on veut placer.
|
||||
* @return boolean, true si on peut la placer et false sinon.
|
||||
*/
|
||||
public boolean canBePlaced(int x, int y, int value) {
|
||||
for (Constraint constraint : this.constraints) {
|
||||
for (IConstraint constraint : this.constraints) {
|
||||
if (!constraint.canBePlaced(this, x, y, value)) {
|
||||
return false;
|
||||
}
|
||||
@@ -92,6 +98,7 @@ public class Sudoku {
|
||||
|
||||
/**
|
||||
* Vide la Cell dotn les coordonnées sont renseignées de son symbole.
|
||||
*
|
||||
* @param x int, abscisse de la Cell voulue.
|
||||
* @param y int, coordonnée de la Cell voulue.
|
||||
*/
|
||||
@@ -119,6 +126,7 @@ public class Sudoku {
|
||||
|
||||
/**
|
||||
* Place le symbole d'index value dans la Cell de coordonnées précisées.
|
||||
*
|
||||
* @param x int, abscisse de la Cell voulue.
|
||||
* @param y int, coordonnée de la Cell voulue.
|
||||
* @param value int, index du symbole à placer.
|
||||
@@ -126,7 +134,7 @@ public class Sudoku {
|
||||
*/
|
||||
public Cell setCellSymbol(int x, int y, int value) {
|
||||
assert (isValidCoords(x, y));
|
||||
for (Constraint constraint : this.constraints) {
|
||||
for (IConstraint constraint : this.constraints) {
|
||||
if (!constraint.canBePlaced(this, x, y, value)) {
|
||||
return null;
|
||||
}
|
||||
@@ -138,6 +146,7 @@ public class Sudoku {
|
||||
|
||||
/**
|
||||
* Place les symboles d'index contenus dans values dans les cases du Sudoku.
|
||||
*
|
||||
* @param values List<Integer>, liste des index des symboles à placer.
|
||||
* @return boolean, vaut true si les symboles ont été placés, false sinon.
|
||||
*/
|
||||
@@ -155,7 +164,9 @@ public class Sudoku {
|
||||
}
|
||||
|
||||
/**
|
||||
* Place les symboles d'index contenus dans values dans les cases du Sudoku et rend ces cases immuables.
|
||||
* Place les symboles d'index contenus dans values dans les cases du Sudoku et
|
||||
* rend ces cases immuables.
|
||||
*
|
||||
* @param values List<Integer>, liste des index des symboles à placer.
|
||||
* @return boolean, vaut true si les symboles ont été placés, false sinon.
|
||||
*/
|
||||
@@ -192,7 +203,7 @@ public class Sudoku {
|
||||
return this.cells.get(i);
|
||||
}
|
||||
|
||||
public List<Constraint> getConstraints() {
|
||||
public List<IConstraint> getConstraints() {
|
||||
return constraints;
|
||||
}
|
||||
|
||||
@@ -210,6 +221,7 @@ public class Sudoku {
|
||||
|
||||
/**
|
||||
* Vérifie si une Cell appartient au Sudoku.
|
||||
*
|
||||
* @param cell Cell, cellule dont on veut vérifier l'appartenance au Sudoku.
|
||||
* @return boolean, vaut true si la Cell appartient au Sudoku.
|
||||
*/
|
||||
@@ -233,6 +245,7 @@ public class Sudoku {
|
||||
|
||||
/**
|
||||
* Renvoie la 1re Cell vide du Sudoku.
|
||||
*
|
||||
* @return Cell, une Cell vide, ou null s'il n'y en a pas.
|
||||
*/
|
||||
public Cell getFirstEmptyCell() {
|
||||
@@ -245,7 +258,9 @@ 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ésolue, soit complet et cohérent avec ses
|
||||
* contraintes.
|
||||
*
|
||||
* @return boolean, valant true si le Sudoku est résolu, false sinon.
|
||||
*/
|
||||
public boolean isSolved() {
|
||||
@@ -256,6 +271,7 @@ public class Sudoku {
|
||||
|
||||
/**
|
||||
* Vérifie que le Sudoku est complet, soit qu'il n'y ait aucune case vide.
|
||||
*
|
||||
* @return boolean, true si le Sudoku est complet, false sinon.
|
||||
*/
|
||||
private boolean isComplete() {
|
||||
@@ -263,7 +279,9 @@ public class Sudoku {
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si le Sudoku est valide, soit qu'il est cohérent avec ses contraintes.
|
||||
* Vérifie si le Sudoku est valide, soit qu'il est cohérent avec ses
|
||||
* contraintes.
|
||||
*
|
||||
* @return bollean, true si le Sudoku est valide, false sinon
|
||||
*/
|
||||
private boolean isValid() {
|
||||
@@ -289,7 +307,7 @@ public class Sudoku {
|
||||
}
|
||||
|
||||
public boolean hasConstraint(Constraint constraint) {
|
||||
return this.constraints.contains(constraint);
|
||||
return this.constraints.contains(constraint.getConstraint());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import sudoku.constraint.Constraint;
|
||||
import sudoku.constraint.IConstraint;
|
||||
import sudoku.io.SudokuSerializer;
|
||||
import sudoku.solver.RandomSolver;
|
||||
import sudoku.solver.Solver;
|
||||
@@ -25,11 +26,13 @@ public class SudokuFactory {
|
||||
* Liste des contraintes par défaut d'un Multi- ou Sudoku.
|
||||
* Comprend les contraintes de blocs, de lignes, et de colonnes.
|
||||
*/
|
||||
public static List<Constraint> DEFAULT_CONSTRAINTS = Arrays.asList(Constraint.Block, Constraint.Column,
|
||||
Constraint.Line);
|
||||
public static List<IConstraint> DEFAULT_CONSTRAINTS = SudokuFactory
|
||||
.fromConstraints(Arrays.asList(Constraint.Block, Constraint.Column,
|
||||
Constraint.Line));
|
||||
|
||||
/**
|
||||
* Créée des Cells et les met dans une liste de taille size.
|
||||
*
|
||||
* @param size int, nombre de Cells à initialiser.
|
||||
* @return List<Cell>, liste des Cells initialisées.
|
||||
*/
|
||||
@@ -42,7 +45,9 @@ public class SudokuFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée des Blocks de taille width par height à partir des cellules données, et les met dans une liste.
|
||||
* Créée des Blocks de taille width par height à partir des cellules données, et
|
||||
* les met dans une liste.
|
||||
*
|
||||
* @param cells List<Cell>, liste des Cells à découper en Blocks.
|
||||
* @param width int, largeur des Blocks à créer.
|
||||
* @param height int, hauteur des Blocks à créer.
|
||||
@@ -72,29 +77,36 @@ public class SudokuFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée un MultiDoku vide dont les Blocks sont de taille widthBlock par heightBlock.
|
||||
* Créée un MultiDoku vide dont les Blocks sont de taille widthBlock par
|
||||
* heightBlock.
|
||||
*
|
||||
* @param widthBlock int, largeur des Blocks.
|
||||
* @param heightBlock int, hauteur des Blocks.
|
||||
* @return MultiDoku, MultiDoku vide.
|
||||
*/
|
||||
public static MultiDoku createBasicEmptyRectangleDoku(int widthBlock, int heightBlock,
|
||||
List<Constraint> constraints) {
|
||||
List<IConstraint> constraints) {
|
||||
return new MultiDoku(Arrays.asList(createRectangleSudoku(widthBlock, heightBlock, constraints)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée un MultiDoku vide dont les Blocks sont carrés de longueur size.
|
||||
*
|
||||
* @param size int, taille des Blocks.
|
||||
* @return MultiDoku, MultiDoku vide.
|
||||
*/
|
||||
public static MultiDoku createBasicEmptySquareDoku(int size, List<Constraint> constraints) {
|
||||
public static MultiDoku createBasicEmptySquareDoku(int size, List<IConstraint> constraints) {
|
||||
return new MultiDoku(Arrays.asList(createSquareSudoku(size, constraints)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Place des Cells immutables de valeurs fournies, aux Coordinate fournies dans le MultiDoku doku fourni.
|
||||
* Place des Cells immutables de valeurs fournies, aux Coordinate fournies dans
|
||||
* le MultiDoku doku fourni.
|
||||
*
|
||||
* @param doku MultiDoku, MultiDoku à remplir.
|
||||
* @param immutableCells Map<Coordinate, Integer>, association de Coordinate coordonnées et Integer valeurs, correspondant aux cases à remplir.
|
||||
* @param immutableCells Map<Coordinate, Integer>, association de Coordinate
|
||||
* coordonnées et Integer valeurs, correspondant aux cases
|
||||
* à remplir.
|
||||
*/
|
||||
public static void setImmutableCells(MultiDoku doku, Map<Coordinate, Integer> immutableCells) {
|
||||
immutableCells.forEach((coordinate, symbol) -> {
|
||||
@@ -113,8 +125,10 @@ public class SudokuFactory {
|
||||
*
|
||||
* @param doku MultiDoku, MultiDoku dont on doit vider des Cells.
|
||||
* @param nbCellsToEmpty int, nombre de cases à retirer.
|
||||
* @return boolean, valant true si un MultiDoku de difficulté donnée peut être créée, false sinon.
|
||||
* @throws Exception si la difficulté n'est pas compatible avec la taille du MultiDoku.
|
||||
* @return boolean, valant true si un MultiDoku de difficulté donnée peut être
|
||||
* créée, false sinon.
|
||||
* @throws Exception si la difficulté n'est pas compatible avec la taille du
|
||||
* MultiDoku.
|
||||
*/
|
||||
public static boolean newDokuFromFilledOne(MultiDoku doku, int nbCellsToEmpty, Solver solver) throws Exception {
|
||||
|
||||
@@ -128,33 +142,28 @@ public class SudokuFactory {
|
||||
|
||||
List<Cell> cellsThatCanBeEmptied = doku.getFilledCells();
|
||||
|
||||
while (!cellsThatCanBeEmptied.isEmpty()) {
|
||||
int index = random.nextInt(cellsThatCanBeEmptied.size());
|
||||
Cell cellToEmpty = cellsThatCanBeEmptied.get(index);
|
||||
|
||||
int oldSymbol = cellToEmpty.empty();
|
||||
cellToEmpty.empty();
|
||||
|
||||
int nbDokuSultions = solver.countSolution(doku);
|
||||
if (nbDokuSultions == 1) {
|
||||
if (newDokuFromFilledOne(doku, --nbCellsToEmpty, solver)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
cellToEmpty.setSymbolIndex(oldSymbol);
|
||||
cellsThatCanBeEmptied.remove(cellToEmpty);
|
||||
return newDokuFromFilledOne(doku, --nbCellsToEmpty, solver);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée un Sudoku vide dont les Blocks sont de taille widthBlock par heightBlock.
|
||||
* Créée un Sudoku vide dont les Blocks sont de taille widthBlock par
|
||||
* heightBlock.
|
||||
*
|
||||
* @param widthBlock int, largeur des Blocks.
|
||||
* @param heightBlock int, hauteur des Blocks.
|
||||
* @return Sudoku, Sudoku vide.
|
||||
*/
|
||||
private static Sudoku createRectangleSudoku(int widthBlock, int heightBlock, List<Constraint> constraints) {
|
||||
private static Sudoku createRectangleSudoku(int widthBlock, int heightBlock, List<IConstraint> constraints) {
|
||||
int symbolCount = widthBlock * heightBlock;
|
||||
List<Cell> cases = initCells(symbolCount);
|
||||
List<Block> blocs = initRectangleBlocs(cases, widthBlock, heightBlock);
|
||||
@@ -168,15 +177,17 @@ public class SudokuFactory {
|
||||
|
||||
/**
|
||||
* Créée un Sudoku vide dont les Blocks sont carrés de longueur size.
|
||||
*
|
||||
* @param size int, taille des Blocks.
|
||||
* @return Sudoku, Sudoku vide.
|
||||
*/
|
||||
private static Sudoku createSquareSudoku(int size, List<Constraint> constraints) {
|
||||
private static Sudoku createSquareSudoku(int size, List<IConstraint> constraints) {
|
||||
return createRectangleSudoku(size, size, constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connecte deux Sudokus selon la décalage offset fourni.
|
||||
*
|
||||
* @param sudoku1 Sudoku, premier sudoku à connecter.
|
||||
* @param sudoku2 Sudoku, second sudoku à connecter.
|
||||
* @param offset Coordinate, décalage entre les deux Sudokus.
|
||||
@@ -213,35 +224,22 @@ public class SudokuFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée un MultiDoku de Blocks carrés de taille size composé de cinq Sudokus, dont un central qui partage chacun de ses Blockss d'angle avec un autre Sudoku.
|
||||
* Créée un MultiDoku de Blocks carrés de taille size composé de cinq Sudokus,
|
||||
* dont un central qui partage chacun de ses Blockss d'angle avec un autre
|
||||
* Sudoku.
|
||||
*
|
||||
* @param size int, largeur des Blocks unitraires des Sudokus à crééer.
|
||||
* @return MultiDoku, MultiDoku de forme X.
|
||||
*/
|
||||
public static MultiDoku createBasicXShapedMultidoku(int size, List<Constraint> constraints) {
|
||||
public static MultiDoku createBasicXShapedMultidoku(int size, List<IConstraint> constraints) {
|
||||
assert (size > 1);
|
||||
|
||||
/*
|
||||
* 2 3
|
||||
* 1
|
||||
* 4 5
|
||||
*/
|
||||
|
||||
Sudoku sudoku1 = createSquareSudoku(size, constraints);
|
||||
Sudoku sudoku2 = createSquareSudoku(size, constraints);
|
||||
Sudoku sudoku3 = createSquareSudoku(size, constraints);
|
||||
Sudoku sudoku4 = createSquareSudoku(size, constraints);
|
||||
Sudoku sudoku5 = createSquareSudoku(size, constraints);
|
||||
|
||||
linkRectangleSudokus(sudoku1, sudoku2, new Coordinate(1 - size, 1 - size));
|
||||
linkRectangleSudokus(sudoku1, sudoku3, new Coordinate(size - 1, 1 - size));
|
||||
linkRectangleSudokus(sudoku1, sudoku4, new Coordinate(1 - size, size - 1));
|
||||
linkRectangleSudokus(sudoku1, sudoku5, new Coordinate(size - 1, size - 1));
|
||||
|
||||
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
||||
return createBasicXShapedMultidoku(size, size, constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée un MultiDoku de Blocks rectangulaires de forme width par height composé de cinq Sudokus,
|
||||
* Créée un MultiDoku de Blocks rectangulaires de forme width par height composé
|
||||
* de cinq Sudokus,
|
||||
* dont un central qui partage chacun de ses Blocks d'angle avec un autre
|
||||
* Sudoku.
|
||||
*
|
||||
@@ -249,7 +247,7 @@ public class SudokuFactory {
|
||||
* @param height int, hauteur des Blocks unitraires des Sudokus à crééer.
|
||||
* @return MultiDoku, MultiDoku de forme X.
|
||||
*/
|
||||
public static MultiDoku createBasicXShapedMultidoku(int width, int height, List<Constraint> constraints) {
|
||||
public static MultiDoku createBasicXShapedMultidoku(int width, int height, List<IConstraint> constraints) {
|
||||
assert (width > 1 && height > 1);
|
||||
|
||||
/*
|
||||
@@ -272,6 +270,55 @@ public class SudokuFactory {
|
||||
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Créée un MultiDoku de Blocks carrés de taille size composé de cinq Sudokus,
|
||||
* dont un central qui partage chacun de ses Blockss d'angle avec un autre
|
||||
* Sudoku.
|
||||
*
|
||||
* @param size int, largeur des Blocks unitraires des Sudokus à crééer.
|
||||
* @return MultiDoku, MultiDoku de forme X.
|
||||
*/
|
||||
public static MultiDoku createBasicPlusShapedMultidoku(int size, List<IConstraint> constraints) {
|
||||
assert (size > 1);
|
||||
|
||||
return createBasicPlusShapedMultidoku(size, size, constraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Créée un MultiDoku de Blocks rectangulaires de forme width par height composé
|
||||
* de cinq Sudokus,
|
||||
* dont un central qui partage chacun de ses Blocks d'angle avec un autre
|
||||
* Sudoku.
|
||||
*
|
||||
* @param width int, largeur des Blocks unitraires des Sudokus à crééer.
|
||||
* @param height int, hauteur des Blocks unitraires des Sudokus à crééer.
|
||||
* @return MultiDoku, MultiDoku de forme X.
|
||||
*/
|
||||
public static MultiDoku createBasicPlusShapedMultidoku(int width, int height, List<IConstraint> constraints) {
|
||||
assert (width > 1 && height > 1);
|
||||
|
||||
/*
|
||||
* 3
|
||||
* 2 1 4
|
||||
* 5
|
||||
*/
|
||||
|
||||
Sudoku sudoku1 = createRectangleSudoku(width, height, constraints);
|
||||
Sudoku sudoku2 = createRectangleSudoku(width, height, constraints);
|
||||
Sudoku sudoku3 = createRectangleSudoku(width, height, constraints);
|
||||
Sudoku sudoku4 = createRectangleSudoku(width, height, constraints);
|
||||
Sudoku sudoku5 = createRectangleSudoku(width, height, constraints);
|
||||
|
||||
linkRectangleSudokus(sudoku1, sudoku2, new Coordinate(1 - height, 0));
|
||||
linkRectangleSudokus(sudoku1, sudoku3, new Coordinate(0, 1 - width));
|
||||
linkRectangleSudokus(sudoku1, sudoku4, new Coordinate(height - 1, 0));
|
||||
linkRectangleSudokus(sudoku1, sudoku5, new Coordinate(0, width - 1));
|
||||
|
||||
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
||||
}
|
||||
|
||||
public static void fillDoku(MultiDoku doku, Difficulty difficulty) throws Exception {
|
||||
Solver solver = new RandomSolver();
|
||||
solver.solve(doku);
|
||||
@@ -291,11 +338,10 @@ public class SudokuFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public static MultiDoku createBasicEmptyRandomBlockDoku(int blockSize, List<Constraint> constraints) {
|
||||
public static MultiDoku createBasicEmptyRandomBlockDoku(int blockSize, List<IConstraint> constraints) {
|
||||
int blockCellCount = blockSize * blockSize;
|
||||
List<Cell> cells = initCells(blockCellCount);
|
||||
List<Cell> homeLessCells = new ArrayList<>();
|
||||
homeLessCells.addAll(cells);
|
||||
List<Cell> homeLessCells = new ArrayList<>(cells);
|
||||
List<Block> blocks = new ArrayList<>();
|
||||
Random r = new Random();
|
||||
for (int i = 0; i < blockCellCount; i++) {
|
||||
@@ -314,4 +360,12 @@ public class SudokuFactory {
|
||||
}
|
||||
return new MultiDoku(Arrays.asList(sudoku));
|
||||
}
|
||||
|
||||
public static List<IConstraint> fromConstraints(List<Constraint> constraints) {
|
||||
List<IConstraint> iconstraints = new ArrayList<>();
|
||||
for (Constraint cons : constraints) {
|
||||
iconstraints.add(cons.getConstraint());
|
||||
}
|
||||
return iconstraints;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
package sudoku.solver;
|
||||
|
||||
import gui.Symbols;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import gui.constants.Symbols;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.io.SudokuSerializer;
|
||||
import sudoku.structure.Cell;
|
||||
@@ -9,17 +14,10 @@ import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.Sudoku;
|
||||
import sudoku.structure.SudokuFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
class SolverTest {
|
||||
|
||||
@Test
|
||||
void solveTest() {
|
||||
Random rand = new Random();
|
||||
|
||||
MultiDoku dokuToTest = SudokuFactory.createBasicEmptySquareDoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
MultiDoku dokuResult = SudokuFactory.createBasicEmptySquareDoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user