Compare commits
4 Commits
sooolve
...
createPlus
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e67e7a9d4 | |||
|
|
70eef1646d | ||
| 5dfe4382fe | |||
|
|
059886c2a4 |
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -19,7 +19,7 @@ jobs:
|
||||
uses: gradle/actions/setup-gradle@v4
|
||||
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew assemble
|
||||
run: ./gradlew build
|
||||
|
||||
- name: Test
|
||||
run: ./gradlew test
|
||||
|
||||
|
Before Width: | Height: | Size: 399 KiB After Width: | Height: | Size: 399 KiB |
@@ -11,6 +11,8 @@ plugins {
|
||||
id 'application'
|
||||
}
|
||||
|
||||
project.ext.os = System.properties['os.name'].toLowerCase().split(" ")[0]
|
||||
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
@@ -18,8 +20,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
// Use JUnit Jupiter for testing.
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.1'
|
||||
|
||||
implementation 'org.json:json:20250107'
|
||||
|
||||
@@ -27,9 +28,7 @@ dependencies {
|
||||
|
||||
implementation "org.lwjgl:lwjgl-stb:3.3.4"
|
||||
|
||||
implementation "org.lwjgl:lwjgl-stb::natives-linux"
|
||||
implementation "org.lwjgl:lwjgl-stb::natives-windows"
|
||||
implementation "org.lwjgl:lwjgl-stb::natives-macos"
|
||||
runtimeOnly "org.lwjgl:lwjgl-stb::natives-$os"
|
||||
}
|
||||
|
||||
application {
|
||||
@@ -49,10 +48,6 @@ jar {
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
run {
|
||||
enableAssertions = true
|
||||
}
|
||||
@@ -1,551 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"immutable": true,
|
||||
"symbolIndex": 2
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"immutable": true,
|
||||
"symbolIndex": 1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"immutable": true,
|
||||
"symbolIndex": 8
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"immutable": true,
|
||||
"symbolIndex": 2
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"immutable": true,
|
||||
"symbolIndex": 0
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"immutable": true,
|
||||
"symbolIndex": 5
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"immutable": true,
|
||||
"symbolIndex": 8
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"immutable": true,
|
||||
"symbolIndex": 1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"immutable": true,
|
||||
"symbolIndex": 5
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"immutable": true,
|
||||
"symbolIndex": 6
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"immutable": true,
|
||||
"symbolIndex": 0
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"immutable": true,
|
||||
"symbolIndex": 3
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"immutable": true,
|
||||
"symbolIndex": 7
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"immutable": true,
|
||||
"symbolIndex": 6
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"immutable": true,
|
||||
"symbolIndex": 8
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"immutable": true,
|
||||
"symbolIndex": 4
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"immutable": true,
|
||||
"symbolIndex": 6
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"immutable": true,
|
||||
"symbolIndex": 7
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"immutable": true,
|
||||
"symbolIndex": 0
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"immutable": true,
|
||||
"symbolIndex": 3
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"symbolIndex": -1
|
||||
}
|
||||
],
|
||||
"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,554 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"blockID": 0,
|
||||
"immutable": true,
|
||||
"symbolIndex": 5
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"immutable": true,
|
||||
"symbolIndex": 6
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"immutable": true,
|
||||
"symbolIndex": 7
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"immutable": true,
|
||||
"symbolIndex": 1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"immutable": true,
|
||||
"symbolIndex": 2
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"immutable": true,
|
||||
"symbolIndex": 4
|
||||
},
|
||||
{
|
||||
"blockID": 0,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 1,
|
||||
"immutable": true,
|
||||
"symbolIndex": 8
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"immutable": true,
|
||||
"symbolIndex": 7
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 2,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"immutable": true,
|
||||
"symbolIndex": 6
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"immutable": true,
|
||||
"symbolIndex": 8
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"immutable": true,
|
||||
"symbolIndex": 1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"immutable": true,
|
||||
"symbolIndex": 2
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"immutable": true,
|
||||
"symbolIndex": 6
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"immutable": true,
|
||||
"symbolIndex": 8
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 3,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"immutable": true,
|
||||
"symbolIndex": 0
|
||||
},
|
||||
{
|
||||
"blockID": 4,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 5,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"immutable": true,
|
||||
"symbolIndex": 5
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"immutable": true,
|
||||
"symbolIndex": 1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"immutable": true,
|
||||
"symbolIndex": 7
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"immutable": true,
|
||||
"symbolIndex": 8
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"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,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 6,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"immutable": true,
|
||||
"symbolIndex": 4
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"immutable": true,
|
||||
"symbolIndex": 5
|
||||
},
|
||||
{
|
||||
"blockID": 7,
|
||||
"immutable": true,
|
||||
"symbolIndex": 0
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"symbolIndex": -1
|
||||
},
|
||||
{
|
||||
"blockID": 8,
|
||||
"symbolIndex": -1
|
||||
}
|
||||
],
|
||||
"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,32 +0,0 @@
|
||||
package gui;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class AssetManager {
|
||||
|
||||
public static byte[] getResource(String name) {
|
||||
// we first search it in files
|
||||
File f = new File(name);
|
||||
if (f.exists()){
|
||||
FileInputStream fis;
|
||||
try {
|
||||
fis = new FileInputStream(f);
|
||||
return fis.readAllBytes();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// then in the jar
|
||||
InputStream is = ClassLoader.getSystemResourceAsStream(name);
|
||||
try {
|
||||
return is.readAllBytes();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,10 +2,15 @@ package gui;
|
||||
|
||||
import gui.constants.Fonts;
|
||||
import gui.constants.Images;
|
||||
import gui.constants.Symbols;
|
||||
import gui.menu.MainMenu;
|
||||
import gui.menu.StateMachine;
|
||||
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 {
|
||||
|
||||
@@ -31,7 +36,7 @@ public class Main extends Application {
|
||||
@Override
|
||||
protected void preRun() {
|
||||
super.preRun();
|
||||
Images.reloadImages();
|
||||
Images.loadImages();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,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 (distanceSquared > maxDistanceSquared) {
|
||||
maxDistanceSquared = distanceSquared;
|
||||
maxSudoku = entry.getKey();
|
||||
maxCoordinate = coordinate;
|
||||
}
|
||||
if (coordinate.getX() > maxX)
|
||||
maxX = coordinate.getX();
|
||||
if (coordinate.getY() > maxY)
|
||||
maxY = coordinate.getY();
|
||||
lastSudoku = entry.getKey();
|
||||
}
|
||||
|
||||
int blockWidth = maxSudoku.getBlockWidth();
|
||||
int blockHeight = maxSudoku.getSize() / blockWidth;
|
||||
Coordinate maxCoordinate = new Coordinate(maxX, maxY);
|
||||
// tous les sudokus sont censés faire la même taille
|
||||
int sudokuSize = lastSudoku.getSize();
|
||||
|
||||
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,6 +1,5 @@
|
||||
package gui.constants;
|
||||
|
||||
import gui.AssetManager;
|
||||
import imgui.ImFont;
|
||||
import imgui.ImFontConfig;
|
||||
import imgui.ImFontGlyphRangesBuilder;
|
||||
@@ -21,15 +20,15 @@ public class Fonts {
|
||||
ImFontGlyphRangesBuilder builder = new ImFontGlyphRangesBuilder();
|
||||
builder.addRanges(ImGui.getIO().getFonts().getGlyphRangesDefault());
|
||||
builder.addRanges(ImGui.getIO().getFonts().getGlyphRangesCyrillic());
|
||||
|
||||
// builder.addRanges(ImGui.getIO().getFonts().getGlyphRangesChineseFull());
|
||||
ImFontConfig cfg = new ImFontConfig();
|
||||
cfg.setGlyphRanges(builder.buildRanges());
|
||||
|
||||
COMIC = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("comic.ttf"), 50.0f);
|
||||
ARIAL_BOLD = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("arial_bold.ttf"), 50.0f);
|
||||
ARIAL = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("arial.ttf"), 50.0f, cfg);
|
||||
CHERI = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("cheri.ttf"), 50.0f);
|
||||
INFECTED = ImGui.getIO().getFonts().addFontFromMemoryTTF(AssetManager.getResource("INFECTED.ttf"), 50.0f);
|
||||
COMIC = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "comic.ttf", 50.0f);
|
||||
ARIAL_BOLD = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "arial_bold.ttf", 50.0f);
|
||||
ARIAL = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "arial.ttf", 50.0f, cfg);
|
||||
CHERI = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "cheri.ttf", 50.0f);
|
||||
INFECTED = ImGui.getIO().getFonts().addFontFromFileTTF(baseDir + "INFECTED.ttf", 50.0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,21 +5,16 @@ import java.nio.ByteBuffer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.stb.STBImage;
|
||||
|
||||
import gui.AssetManager;
|
||||
|
||||
public class Images {
|
||||
|
||||
public static int BACKGROUND;
|
||||
|
||||
private static int loadTexture(byte[] imageData) {
|
||||
private static int loadTexture(String fileName) {
|
||||
int[] width = new int[1];
|
||||
int[] height = new int[1];
|
||||
int[] channelCount = new int[1];
|
||||
|
||||
ByteBuffer img = ByteBuffer.allocateDirect(imageData.length);
|
||||
img.put(imageData);
|
||||
img.flip();
|
||||
ByteBuffer pixels = STBImage.stbi_load_from_memory(img, width, height, channelCount, 4);
|
||||
ByteBuffer pixels = STBImage.stbi_load(fileName, width, height, channelCount, 4);
|
||||
|
||||
int textureID = GL11.glGenTextures();
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
|
||||
@@ -37,8 +32,8 @@ public class Images {
|
||||
return textureID;
|
||||
}
|
||||
|
||||
public static void reloadImages() {
|
||||
BACKGROUND = loadTexture(AssetManager.getResource(Options.BackgroundPath));
|
||||
public static void loadImages() {
|
||||
BACKGROUND = loadTexture("background.png");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,5 @@ public class Options {
|
||||
|
||||
public static Symbols Symboles = Symbols.Numbers;
|
||||
public static float BackgroundSpeed = 1.0f;
|
||||
public static String BackgroundPath = "background.png";
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -14,12 +14,12 @@ public class ConnexionStatusView extends BaseView {
|
||||
|
||||
private String displayText = "Connecting ...";
|
||||
|
||||
public ConnexionStatusView(StateMachine stateMachine, String pseudo, String address, short port)
|
||||
public ConnexionStatusView(StateMachine stateMachine, String address, short port)
|
||||
throws UnknownHostException, IOException {
|
||||
super(stateMachine);
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
this.client = new Client(pseudo, address, port);
|
||||
this.client = new Client(address, port);
|
||||
bindListeners();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -29,13 +29,12 @@ public class ConnexionStatusView extends BaseView {
|
||||
t.start();
|
||||
}
|
||||
|
||||
public ConnexionStatusView(StateMachine stateMachine, String pseudo, short port)
|
||||
throws UnknownHostException, IOException {
|
||||
public ConnexionStatusView(StateMachine stateMachine, short port) throws UnknownHostException, IOException {
|
||||
super(stateMachine);
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
this.server = new Server(port);
|
||||
this.client = new Client(pseudo, "localhost", port);
|
||||
this.client = new Client("localhost", port);
|
||||
bindListeners();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package gui.menu;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import imgui.ImGui;
|
||||
import imgui.ImVec2;
|
||||
@@ -12,7 +11,6 @@ public class MultiMenu extends BaseView {
|
||||
|
||||
private final ImInt port = new ImInt(25565);
|
||||
private final ImString address = new ImString("localhost");
|
||||
private final ImString pseudo = new ImString("Joueur" + new Random().nextInt());
|
||||
|
||||
public MultiMenu(StateMachine stateMachine) {
|
||||
super(stateMachine);
|
||||
@@ -24,10 +22,9 @@ public class MultiMenu extends BaseView {
|
||||
ImGui.beginChild("##CreateGame", new ImVec2(displaySize.x / 2.0f, displaySize.y * 8.0f / 9.0f));
|
||||
if (ImGui.inputInt("Port", port))
|
||||
port.set(Math.clamp(port.get(), 1, 65535));
|
||||
ImGui.inputText("Pseudo", pseudo);
|
||||
if (ImGui.button("Créer")) {
|
||||
try {
|
||||
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, pseudo.get(), (short) port.get()));
|
||||
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, (short) port.get()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -41,7 +38,6 @@ public class MultiMenu extends BaseView {
|
||||
ImGui.inputText("Adresse", address);
|
||||
if (ImGui.inputInt("Port", port))
|
||||
port.set(Math.clamp(port.get(), 1, 65535));
|
||||
ImGui.inputText("Pseudo", pseudo);
|
||||
if (ImGui.button("Rejoindre")) {
|
||||
try {
|
||||
this.stateMachine.pushState(new ConnexionStatusView(stateMachine, address.get(), (short) port.get()));
|
||||
|
||||
@@ -78,9 +78,4 @@ public class MultiPlayerView extends BaseView {
|
||||
renderGameStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanResources() {
|
||||
this.selector.clean();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,56 +1,28 @@
|
||||
package gui.menu;
|
||||
|
||||
import gui.constants.Images;
|
||||
import gui.constants.Options;
|
||||
import gui.constants.Symbols;
|
||||
import imgui.ImGui;
|
||||
import imgui.extension.imguifiledialog.ImGuiFileDialog;
|
||||
import imgui.extension.imguifiledialog.flag.ImGuiFileDialogFlags;
|
||||
import imgui.type.ImInt;
|
||||
|
||||
public class OptionsMenu extends BaseView {
|
||||
|
||||
private ImInt currentValue = new ImInt();
|
||||
private float backgroundSpeed[] = new float[] { Options.BackgroundSpeed };
|
||||
private float backgroundSpeed[] = new float[]{Options.BackgroundSpeed};
|
||||
|
||||
public OptionsMenu(StateMachine stateMachine) {
|
||||
super(stateMachine);
|
||||
}
|
||||
|
||||
private void renderImageSelectDialog() {
|
||||
if (ImGuiFileDialog.display("browse-img", ImGuiFileDialogFlags.None)) {
|
||||
if (ImGuiFileDialog.isOk()) {
|
||||
var selection = ImGuiFileDialog.getSelection();
|
||||
for (var entry : selection.entrySet()) {
|
||||
try {
|
||||
String filePath = entry.getValue();
|
||||
Options.BackgroundPath = filePath;
|
||||
Images.reloadImages();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGuiFileDialog.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void renderImageSelectButton() {
|
||||
if (ImGui.button("Changer de fond d'écran"))
|
||||
ImGuiFileDialog.openDialog("browse-img", "Choisissez un fichier", ".png,.jpg,.jpeg", ".");
|
||||
renderImageSelectDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
ImGui.text("Options");
|
||||
if (ImGui.combo("Jeu de symboles", currentValue, Symbols.getSymbolsNames())) {
|
||||
if(ImGui.combo("Jeu de symboles", currentValue, Symbols.getSymbolsNames())){
|
||||
Options.Symboles = Symbols.values()[currentValue.get()];
|
||||
}
|
||||
if (ImGui.sliderFloat("Vitesse d'animation de l'arrière plan", backgroundSpeed, 0.0f, 10.0f)) {
|
||||
if(ImGui.sliderFloat("Vitesse d'animation de l'arrière plan", backgroundSpeed, 0.0f, 10.0f)){
|
||||
Options.BackgroundSpeed = backgroundSpeed[0];
|
||||
}
|
||||
renderImageSelectButton();
|
||||
renderReturnButton();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,4 @@ public class SoloMenu extends BaseView {
|
||||
renderReturnButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanResources() {
|
||||
this.sudokuSelector.clean();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -92,7 +92,6 @@ public class SudokuView extends BaseView {
|
||||
}
|
||||
|
||||
private void startSolve(Solver solver) {
|
||||
this.doku.clearMutableCells();
|
||||
resolveThread = new Thread(() -> {
|
||||
List<SolverStep> steps = new ArrayList<>();
|
||||
try {
|
||||
@@ -159,8 +158,6 @@ public class SudokuView extends BaseView {
|
||||
private void renderClearButton() {
|
||||
if (centeredButton("Effacer")) {
|
||||
this.doku.clearMutableCells();
|
||||
this.resolved = false;
|
||||
this.unresolved = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,22 +9,13 @@ public class SmoothProgressBar {
|
||||
private final float speed = 2.0f;
|
||||
private final float clipConstant = 0.001f;
|
||||
|
||||
private void updateProgress(float newProgress) {
|
||||
float delta = newProgress - lastProgress;
|
||||
public void render(String label, ImVec2 size, float progress) {
|
||||
float delta = progress - lastProgress;
|
||||
if (Math.abs(delta) < clipConstant)
|
||||
lastProgress = newProgress;
|
||||
lastProgress = progress;
|
||||
else
|
||||
lastProgress = lastProgress + delta * ImGui.getIO().getDeltaTime() * speed;
|
||||
}
|
||||
|
||||
public void render(String label, ImVec2 size, float progress) {
|
||||
updateProgress(progress);
|
||||
ImGui.progressBar(lastProgress, size, label);
|
||||
}
|
||||
|
||||
public void render(float progress) {
|
||||
updateProgress(progress);
|
||||
ImGui.progressBar(lastProgress);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import sudoku.constraint.IConstraint;
|
||||
import sudoku.structure.Difficulty;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.SudokuFactory;
|
||||
import sudoku.structure.SudokuFiller;
|
||||
|
||||
public class SudokuSelector {
|
||||
|
||||
@@ -36,15 +35,10 @@ public class SudokuSelector {
|
||||
|
||||
private final String confirmMessage;
|
||||
|
||||
private Thread genThread = null;
|
||||
|
||||
private final SmoothProgressBar genProgressBar;
|
||||
|
||||
public SudokuSelector(boolean canGenEmptyGrid, String confirmMessage) {
|
||||
this.canGenEmptyGrid = canGenEmptyGrid;
|
||||
this.confirmMessage = confirmMessage;
|
||||
initConstraints();
|
||||
this.genProgressBar = new SmoothProgressBar();
|
||||
}
|
||||
|
||||
private List<IConstraint> getConstraints() {
|
||||
@@ -62,40 +56,16 @@ public class SudokuSelector {
|
||||
}
|
||||
}
|
||||
|
||||
private void stopGenThread() {
|
||||
if (this.genThread != null) {
|
||||
this.genThread.interrupt();
|
||||
this.genThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void renderGenProgress() {
|
||||
if (ImGui.beginPopup("genProgress")) {
|
||||
ImGui.text("Chargement de la grille ...");
|
||||
int filled = this.doku.getFilledCells().size();
|
||||
int total = this.doku.getCells().size();
|
||||
this.genProgressBar.render(filled / (float) total);
|
||||
ImGui.endPopup();
|
||||
} else {
|
||||
stopGenThread();
|
||||
}
|
||||
}
|
||||
|
||||
private void selectSudoku(MultiDoku doku, boolean empty) {
|
||||
this.doku = doku;
|
||||
ImGui.openPopup("genProgress");
|
||||
this.genThread = new Thread(() -> {
|
||||
if (!empty) {
|
||||
try {
|
||||
if (!empty) {
|
||||
SudokuFiller.fillDoku(doku, Difficulty.values()[difficulty.get()]);
|
||||
// SudokuFactory.fillDoku(doku, Difficulty.values()[difficulty.get()]);
|
||||
}
|
||||
this.onSelect.emit(this.doku);
|
||||
SudokuFactory.fillDoku(doku, Difficulty.values()[difficulty.get()]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
this.genThread.start();
|
||||
}
|
||||
this.onSelect.emit(this.doku);
|
||||
}
|
||||
|
||||
public void renderFileDialog() {
|
||||
@@ -161,12 +131,7 @@ public class SudokuSelector {
|
||||
if (ImGui.button("À partir d'un fichier")) {
|
||||
ImGuiFileDialog.openDialog("browse-sudoku", "Choisissez un fichier", ".json", ".");
|
||||
}
|
||||
renderGenProgress();
|
||||
renderFileDialog();
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
stopGenThread();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,10 +28,12 @@ public class Client {
|
||||
|
||||
String disconnectReason = null;
|
||||
|
||||
public Client(String pseudo, String address, short port) throws UnknownHostException, IOException {
|
||||
public Client(String address, short port) throws UnknownHostException, IOException {
|
||||
this.clientConnection = new ClientConnexion(address, port, this);
|
||||
this.game = new Game();
|
||||
login(pseudo);
|
||||
// temp
|
||||
Random r = new Random();
|
||||
login("Player" + r.nextInt());
|
||||
}
|
||||
|
||||
public void login(String pseudo) {
|
||||
|
||||
@@ -227,7 +227,7 @@ public class ConsoleInterface {
|
||||
saveMultiDoku(doku);
|
||||
break;
|
||||
case "solution":
|
||||
solve(doku, listSymbols, width, height);
|
||||
solve(doku);
|
||||
break;
|
||||
case "exit":
|
||||
exit();
|
||||
@@ -238,50 +238,19 @@ public class ConsoleInterface {
|
||||
}
|
||||
}
|
||||
|
||||
private void applyStep(SolverStep step) {
|
||||
step.getCell().setSymbolIndex(step.getNewValue());
|
||||
}
|
||||
|
||||
private boolean showStep(MultiDoku doku, List<String> listSymbols, int width, int height, SolverStep step) {
|
||||
System.out.println("Here is the step : \n");
|
||||
showMultidoku(doku, listSymbols, width, height);
|
||||
applyStep(step);
|
||||
System.out.println("\nTurns into :\n");
|
||||
showMultidoku(doku, listSymbols, width, height);
|
||||
System.out.println("Do you want to see the next step ? (y/n, default n)");
|
||||
return reader.next().equals("y");
|
||||
}
|
||||
|
||||
private void showSolveSteps(MultiDoku doku, List<String> listSymbols, int width, int height, List<SolverStep> steps) {
|
||||
System.out.println("Would you like to see the steps of the solver ? (y/n, default n)");
|
||||
doku.getStateManager().popState();
|
||||
switch (reader.next()) {
|
||||
case "y":
|
||||
int stepCount = 0;
|
||||
while(stepCount < steps.size() && showStep(doku, listSymbols, width, height, steps.get(stepCount))){stepCount++;}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void solve(MultiDoku doku, List<String> listSymbols, int width, int height){
|
||||
private void solve(MultiDoku doku){
|
||||
System.out.println("Pick a solver to use : random ('random', default), human ('human') or mixed solver ('mixed').");
|
||||
List<SolverStep> steps = new ArrayList<>();
|
||||
doku.getStateManager().pushState();
|
||||
switch (reader.next()) {
|
||||
case "human":
|
||||
new HumanSolver().solve(doku, steps);
|
||||
new HumanSolver().solve(doku);
|
||||
break;
|
||||
case "mixed":
|
||||
new MixedSolver().solve(doku, steps);
|
||||
new MixedSolver().solve(doku);
|
||||
break;
|
||||
default:
|
||||
new RandomSolver().solve(doku, steps);
|
||||
new RandomSolver().solve(doku);
|
||||
break;
|
||||
}
|
||||
showSolveSteps(doku, listSymbols, width, height, steps);
|
||||
}
|
||||
|
||||
private void play(MultiDoku doku, List<String> listSymbols, int width, int height) {
|
||||
|
||||
@@ -9,10 +9,11 @@ import java.util.Random;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.MultiDoku;
|
||||
|
||||
//TODO
|
||||
public class HintHelper {
|
||||
|
||||
public static record Hint(Cell cell, int newValue) {}
|
||||
public static record Hint(Cell cell, int newValue) {
|
||||
|
||||
}
|
||||
|
||||
public static Hint getHint(MultiDoku doku, Solver solver) {
|
||||
doku.getStateManager().pushState();
|
||||
@@ -35,7 +36,7 @@ public class HintHelper {
|
||||
if (newValue == Cell.NOSYMBOL)
|
||||
return new Hint(cell, newValue);
|
||||
// we have to change the cell value
|
||||
if (oldValue != Cell.NOSYMBOL)
|
||||
if (oldValue != Cell.NOSYMBOL && newValue != oldValue)
|
||||
return new Hint(cell, newValue);
|
||||
|
||||
// there is a valid move
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package sudoku.solver;
|
||||
|
||||
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;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
public class HumanSolver implements Solver {
|
||||
|
||||
@@ -15,25 +20,39 @@ public class HumanSolver implements Solver {
|
||||
*/
|
||||
@Override
|
||||
public boolean solve(MultiDoku doku, List<SolverStep> steps) {
|
||||
while (!doku.isSolved()) {
|
||||
boolean filledCell = false;
|
||||
for (Cell cell : doku.getCells()) {
|
||||
if (!cell.isMutable() || !cell.isEmpty())
|
||||
continue;
|
||||
|
||||
List<Integer> possibleSymbols = cell.getPossibleSymbols();
|
||||
if (possibleSymbols.size() == 1) {
|
||||
cell.setSymbolIndex(possibleSymbols.getFirst());
|
||||
addStep(cell, steps);
|
||||
filledCell = true;
|
||||
}
|
||||
}
|
||||
// on ne peut plus remplir de cases, on abandonne
|
||||
if (!filledCell)
|
||||
return false;
|
||||
if (Thread.interrupted())
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
|
||||
Sudoku sudoku = doku.getSubGrid(0);
|
||||
logger.log(Level.FINE,
|
||||
'\n' + SudokuPrinter.toStringRectangleSudoku(sudoku,
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(),
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth(),
|
||||
Symbols.Numbers));
|
||||
|
||||
if (doku.isSolved()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
List<Cell> cellsToFill = doku.getEmptyCells();
|
||||
if (cellsToFill.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Cell cellToFill : cellsToFill) {
|
||||
|
||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
||||
if (possibleSymbols.size() != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
||||
addStep(cellToFill, steps);
|
||||
|
||||
return this.solve(doku, steps);
|
||||
}
|
||||
|
||||
return doku.isSolved();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,37 +1,18 @@
|
||||
package sudoku.solver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
public class MixedSolver implements Solver {
|
||||
|
||||
private List<Cell> findCellToBacktrack(MultiDoku doku, int maxPossibilities) {
|
||||
int symbolCount = doku.getSubGrid(0).getSize();
|
||||
if (maxPossibilities > symbolCount)
|
||||
return null;
|
||||
|
||||
List<Cell> backtrackCells = new ArrayList<>();
|
||||
|
||||
for (Cell cell : doku.getCells()) {
|
||||
if (!cell.isMutable() || !cell.isEmpty())
|
||||
continue;
|
||||
|
||||
List<Integer> possibleSymbols = cell.getPossibleSymbols();
|
||||
if (possibleSymbols.size() == maxPossibilities) {
|
||||
backtrackCells.add(cell);
|
||||
}
|
||||
|
||||
// grille non résolvable
|
||||
if (possibleSymbols.size() == 0)
|
||||
return null;
|
||||
}
|
||||
return backtrackCells;
|
||||
}
|
||||
|
||||
/**
|
||||
* Résout le MultiDoku passé en paramètre, avec règles de déduction et
|
||||
* backtracking.
|
||||
@@ -41,59 +22,55 @@ public class MixedSolver implements Solver {
|
||||
*/
|
||||
@Override
|
||||
public boolean solve(MultiDoku doku, List<SolverStep> steps) {
|
||||
Random rand = new Random();
|
||||
|
||||
if (Thread.interrupted()) {
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
}
|
||||
|
||||
if (doku.isSolved())
|
||||
Sudoku sudoku = doku.getSubGrid(0);
|
||||
logger.log(Level.FINE,
|
||||
'\n' + SudokuPrinter.toStringRectangleSudoku(
|
||||
sudoku,
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(),
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth(),
|
||||
Symbols.Numbers));
|
||||
|
||||
if (doku.isSolved()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int symbolCount = doku.getSubGrid(0).getSize();
|
||||
Cell cellToFill = doku.getFirstEmptyCell();
|
||||
if (cellToFill == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// on remplit les cases par déduction
|
||||
for (Cell cell : doku.getCells()) {
|
||||
if (!cell.isMutable() || !cell.isEmpty())
|
||||
continue;
|
||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
||||
|
||||
List<Integer> possibleSymbols = cell.getPossibleSymbols();
|
||||
if (possibleSymbols.size() == 1) {
|
||||
cell.setSymbolIndex(possibleSymbols.getFirst());
|
||||
addStep(cell, steps);
|
||||
if (solve(doku, steps))
|
||||
return true;
|
||||
cell.setSymbolIndex(Cell.NOSYMBOL);
|
||||
return false;
|
||||
if (possibleSymbols.size() == 1) {
|
||||
cellToFill.setSymbolIndex(possibleSymbols.getFirst());
|
||||
addStep(cellToFill, steps);
|
||||
if (this.solve(doku, steps)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// on ne peut plus remplir de cases, on tente de backtrack
|
||||
for (int maxPossibilities = 2; maxPossibilities <= symbolCount; maxPossibilities++) {
|
||||
List<Cell> backtrackCells = new ArrayList<>();
|
||||
while (backtrackCells.isEmpty()) {
|
||||
backtrackCells = findCellToBacktrack(doku, maxPossibilities);
|
||||
// grille non résolvable
|
||||
if (backtrackCells == null) {
|
||||
return false;
|
||||
}
|
||||
maxPossibilities++;
|
||||
}
|
||||
// on fait du backtracking
|
||||
for (Cell backtrackCell : backtrackCells) {
|
||||
List<Integer> possibilities = backtrackCell.getPossibleSymbols();
|
||||
while (!possibleSymbols.isEmpty()) {
|
||||
int nextPossibleSymbolIndex = rand.nextInt(possibleSymbols.size());
|
||||
int nextSymbol = possibleSymbols.get(nextPossibleSymbolIndex);
|
||||
|
||||
// System.out.println("Backtraing on " + backtrackCell);
|
||||
|
||||
// on tente de placer chacun des symboles
|
||||
for (int symbol : possibilities) {
|
||||
backtrackCell.setSymbolIndex(symbol);
|
||||
if (solve(doku, steps)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
backtrackCell.setSymbolIndex(Cell.NOSYMBOL);
|
||||
cellToFill.setSymbolIndex(nextSymbol);
|
||||
addStep(cellToFill, steps);
|
||||
if (this.solve(doku, steps)) {
|
||||
return true;
|
||||
}
|
||||
cellToFill.setSymbolIndex(Cell.NOSYMBOL);
|
||||
addStep(cellToFill, steps);
|
||||
possibleSymbols.remove(nextPossibleSymbolIndex);
|
||||
|
||||
}
|
||||
return doku.isSolved();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,13 @@ package sudoku.solver;
|
||||
import java.util.List;
|
||||
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;
|
||||
import sudoku.structure.Sudoku;
|
||||
|
||||
public class RandomSolver implements Solver {
|
||||
|
||||
@@ -24,6 +28,13 @@ public class RandomSolver implements Solver {
|
||||
if (Thread.interrupted())
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
|
||||
Sudoku sudoku = doku.getSubGrid(0);
|
||||
logger.log(Level.FINE,
|
||||
'\n' + SudokuPrinter.toStringRectangleSudoku(sudoku,
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getBlockWidth(),
|
||||
sudoku.getBlockWidth() == 0 ? sudoku.getSize() : sudoku.getSize() / sudoku.getBlockWidth(),
|
||||
Symbols.Numbers));
|
||||
|
||||
if (doku.isSolved()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package sudoku.solver;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CancellationException;
|
||||
|
||||
import sudoku.structure.MultiDoku;
|
||||
@@ -9,9 +8,9 @@ import sudoku.structure.Sudoku;
|
||||
/**
|
||||
* Class de test non utilisé
|
||||
*/
|
||||
public class StupidSolver implements Solver{
|
||||
public class StupidSolver {
|
||||
|
||||
private boolean solve(Sudoku sudoku, int index, List<SolverStep> steps) {
|
||||
private static boolean solve(Sudoku sudoku, int index) {
|
||||
// mécanisme d'abandon
|
||||
if (Thread.interrupted())
|
||||
throw new CancellationException("User wants to stop the solver");
|
||||
@@ -22,30 +21,27 @@ public class StupidSolver implements Solver{
|
||||
|
||||
// si la case n'est pas modifiable, on passe à la suivante
|
||||
if (!sudoku.getCell(index).isMutable())
|
||||
return solve(sudoku, index + 1, steps);
|
||||
return solve(sudoku, index + 1);
|
||||
|
||||
for (int symbol = 0; symbol < sudoku.getSize(); symbol++) {
|
||||
if (sudoku.getCell(index).trySetValue(symbol)) {
|
||||
addStep(sudoku.getCell(index), steps);
|
||||
// on tente de placer sur la case suivante
|
||||
if (solve(sudoku, index + 1, steps)) {
|
||||
if (solve(sudoku, index + 1)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// on a tout essayé et rien n'a fonctionné
|
||||
sudoku.getCell(index).empty();
|
||||
addStep(sudoku.getCell(index), steps);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean solve(MultiDoku doku, List<SolverStep> steps) {
|
||||
public static boolean solve(MultiDoku doku) {
|
||||
if (doku.isSolved())
|
||||
return true;
|
||||
|
||||
for (Sudoku sudoku : doku.getSubGrids()) {
|
||||
if (!solve(sudoku, 0, steps))
|
||||
if (!solve(sudoku, 0))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -4,41 +4,28 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class qui représente les Block de chaque Sudoku,
|
||||
* Un Block étant un ensemble de cellule avec une contrainte de block qui lui
|
||||
* ait associé.
|
||||
* Class qui représente les block de chaque sudoku,
|
||||
* Un block étant un ensemble de cellule avec une contrainte de block qui lui
|
||||
* ait associé
|
||||
*/
|
||||
public class Block {
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="ATTRIBUTS">
|
||||
|
||||
/**
|
||||
* L'ensemble des cellules du block.
|
||||
* L'ensemble des cellules du block
|
||||
*/
|
||||
private final List<Cell> cells;
|
||||
|
||||
/**
|
||||
* Liste de Sudoku qui contiennent le block
|
||||
* Pour un accès plus rapide aux sudokus.
|
||||
* List de sudoku qui contiennent le block
|
||||
* Pour un acces plus rapide aux sudokus
|
||||
*/
|
||||
private final List<Sudoku> sudokus;
|
||||
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="METHODES">
|
||||
|
||||
/**
|
||||
* Crée un Block avec une liste de Cell donnée.
|
||||
* @param cells List<Cell>
|
||||
*/
|
||||
public Block(List<Cell> cells) {
|
||||
this.cells = cells;
|
||||
this.sudokus = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée un Block avec une liste de Cell vide.
|
||||
*/
|
||||
public Block() {
|
||||
this(new ArrayList<>());
|
||||
}
|
||||
@@ -46,16 +33,13 @@ public class Block {
|
||||
public List<Cell> getCells() {
|
||||
return cells;
|
||||
}
|
||||
public List<Sudoku> getSudokus() {
|
||||
return sudokus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute une Cell au Block
|
||||
*
|
||||
* @param newCell Cell, à ajouter
|
||||
*/
|
||||
public void addCell(Cell newCell) {
|
||||
void addCell(Cell newCell) {
|
||||
this.cells.add(newCell);
|
||||
}
|
||||
|
||||
@@ -73,5 +57,16 @@ public class Block {
|
||||
return false;
|
||||
}
|
||||
|
||||
// </editor-fold>
|
||||
public boolean containsCell(Cell cell) {
|
||||
for (Cell cellTmp : this.cells) {
|
||||
if (cellTmp.equals(cell)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<Sudoku> getSudokus() {
|
||||
return sudokus;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@ import java.util.List;
|
||||
*/
|
||||
public class Cell {
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="ATTRIBUTS">
|
||||
|
||||
/**
|
||||
* Constante de valeur d'index de symbole quand il n'y en a pas,
|
||||
* soit que la Cell est vide.
|
||||
@@ -31,10 +29,6 @@ public class Cell {
|
||||
*/
|
||||
private boolean isMutable = true;
|
||||
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="METHODES">
|
||||
|
||||
public Cell() {
|
||||
this(Cell.NOSYMBOL);
|
||||
}
|
||||
@@ -52,22 +46,6 @@ public class Cell {
|
||||
return this.symbolIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie le Block qui la contient.
|
||||
* @return Block.
|
||||
*/
|
||||
public Block getBlock() {
|
||||
return this.blockContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie si la Cell est modifiable
|
||||
* @return boolean, true si elle est modifiable ou false sinon.
|
||||
*/
|
||||
public boolean isMutable() {
|
||||
return this.isMutable;
|
||||
}
|
||||
|
||||
public void setSymbolIndex(int symbolIndex) {
|
||||
this.symbolIndex = symbolIndex;
|
||||
}
|
||||
@@ -79,16 +57,22 @@ public class Cell {
|
||||
this.isMutable = false;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
return this.blockContainer;
|
||||
}
|
||||
|
||||
public void setBlock(Block block) {
|
||||
this.blockContainer = block;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vide la Cell.
|
||||
* Remove the current symbolIndex and returns it
|
||||
* @return integer symbolIndex cleared
|
||||
*/
|
||||
public void clearCurrentSymbol() {
|
||||
public int clearCurrentSymbol() {
|
||||
int i = this.symbolIndex;
|
||||
setSymbolIndex(NOSYMBOL);
|
||||
return i;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,6 +83,14 @@ public class Cell {
|
||||
return this.symbolIndex == Cell.NOSYMBOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie si la Cell est modifiable
|
||||
* @return boolean, true si elle est modifiable ou false sinon.
|
||||
*/
|
||||
public boolean isMutable() {
|
||||
return this.isMutable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vide la Cell, en renvoie l'ancien index du symbole qui était dedans.
|
||||
* @return int, index du symbole anciennement contenue dans la Cell.
|
||||
@@ -109,11 +101,6 @@ public class Cell {
|
||||
return oldSymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si la Cell peut prendre ce symbole par rapport aux contraintes de ses Sudokus.
|
||||
* @param value int, index du symbole
|
||||
* @return boolean, true si elle peut, false sinon.
|
||||
*/
|
||||
public boolean canHaveValue(int value) {
|
||||
for (Sudoku s :getBlock().getSudokus()) {
|
||||
int cellIndex = s.getCells().indexOf(this);
|
||||
@@ -129,10 +116,6 @@ public class Cell {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie les symboles que peut prendre cette Cell par rapport aux contraintes de ses Sudokus.
|
||||
* @return List<Integer>, la liste des symboles possibles.
|
||||
*/
|
||||
public List<Integer> getPossibleSymbols() {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (int i = 0; i < getBlock().getSudokus().get(0).getSize(); i++) {
|
||||
@@ -142,11 +125,6 @@ public class Cell {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Essaye de placer la valeur et renvoie false si ce n'est pas possible.
|
||||
* @param newValue int, valeur à placer.
|
||||
* @return boolean, true si la Cell à pris la valeur newValue, false sinon.
|
||||
*/
|
||||
public boolean trySetValue(int newValue) {
|
||||
if (!isMutable())
|
||||
return false;
|
||||
@@ -155,6 +133,4 @@ public class Cell {
|
||||
setSymbolIndex(newValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
// </editor-fold>
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package sudoku.structure;
|
||||
|
||||
/**
|
||||
* Représente les coordonnées d'une Cell.
|
||||
* Représente les coordonnées d'une Cell
|
||||
*/
|
||||
public class Coordinate {
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="ATTRIBUTS">
|
||||
|
||||
/**
|
||||
* L'abscisse de la Cell.
|
||||
*/
|
||||
@@ -16,10 +14,6 @@ public class Coordinate {
|
||||
*/
|
||||
private int y;
|
||||
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="METHODES">
|
||||
|
||||
public Coordinate(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -41,23 +35,16 @@ public class Coordinate {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajoute la Coordiante donnée à celle-ci.
|
||||
* @param other Coordiante, à ajouter.
|
||||
* @return Coordinate, le résultat de l'addition.
|
||||
*/
|
||||
public int calculateIndex(int size) {
|
||||
return this.y * size + this.x;
|
||||
}
|
||||
|
||||
public Coordinate add(Coordinate other) {
|
||||
return new Coordinate(this.x + other.x, this.y + other.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Soustrait la Coordiante donnée à celle-ci.
|
||||
* @param other Coordiante, à soustraire.
|
||||
* @return Coordinate, le résultat de la soustraction.
|
||||
*/
|
||||
public Coordinate sub(Coordinate other) {
|
||||
return new Coordinate(this.x - other.x, this.y - other.y);
|
||||
}
|
||||
|
||||
// </editor-fold>
|
||||
}
|
||||
|
||||
@@ -1,32 +1,26 @@
|
||||
package sudoku.structure;
|
||||
|
||||
/**
|
||||
* Les difficultés d'un Sudoku,
|
||||
* représente le nombre de cases à enlever, en proportion, à un Sudoku.
|
||||
* Par exemple, avec 0.1 de factor, on enlevera 10% des cases.
|
||||
*/
|
||||
//TODO: melvyn va passer par là
|
||||
public enum Difficulty {
|
||||
|
||||
VeryEasy("Très facile", 0.1),
|
||||
Easy("Facile", 0.25),
|
||||
Medium("Moyen", 0.5),
|
||||
Hard("Difficile", 0.75),
|
||||
VeryHard("Impossible", 0.78);
|
||||
VeryEasy("Très facile", 0.1), Easy("Facile", 0.25), Medium("Moyen", 0.5), Hard("Difficile", 0.75), VeryHard("Impossible", 0.78);
|
||||
|
||||
/**
|
||||
* Le pourcentage de Cell à enlever.
|
||||
*/
|
||||
final double factor;
|
||||
/**
|
||||
* Le nom de la difficulté.
|
||||
*/
|
||||
final String displayName;
|
||||
|
||||
Difficulty(String displayName, double factor) {
|
||||
private Difficulty(String displayName, double factor) {
|
||||
this.factor = factor;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public double getFactor() {
|
||||
return factor;
|
||||
}
|
||||
|
||||
private static final String[] difficultyNames;
|
||||
|
||||
static {
|
||||
@@ -37,14 +31,6 @@ public enum Difficulty {
|
||||
}
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public double getFactor() {
|
||||
return factor;
|
||||
}
|
||||
|
||||
public static String[] getDifficultyNames() {
|
||||
return difficultyNames;
|
||||
}
|
||||
|
||||
@@ -1,41 +1,85 @@
|
||||
package sudoku.structure;
|
||||
|
||||
import sudoku.io.SudokuSerializer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import sudoku.io.SudokuSerializer;
|
||||
|
||||
/**
|
||||
* @class MultiDoku
|
||||
* @brief Représente une grille de Multidoku.
|
||||
* Une grille de sudoku est un multidoku avec un seul sous-sudoku.
|
||||
* Une grille de sudoku est un multidoku avec un seul sous-sudoku
|
||||
*/
|
||||
public class MultiDoku {
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="ATTRIBUTS">
|
||||
|
||||
/**
|
||||
* Liste des sous-Sudoku contenue dans le multidoku.
|
||||
*/
|
||||
private final List<Sudoku> subGrids;
|
||||
|
||||
/**
|
||||
* Pile, qui contient des états du MultiDoku,
|
||||
* utile pour la résolution.
|
||||
*/
|
||||
private final StateManager stateManager;
|
||||
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="METHODES">
|
||||
|
||||
public MultiDoku(List<Sudoku> subGrids) {
|
||||
this.subGrids = subGrids;
|
||||
this.stateManager = new StateManager(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie le nombre de sudoku contenu dans ce MultiDoku.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public int getNbSubGrids() {
|
||||
return subGrids.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie la ie sudoku contenue dans ce MultiDoku.
|
||||
*
|
||||
* @param i int, indice du sudoku à renvoyer.
|
||||
* @return Sudoku, ie Sudoku
|
||||
*/
|
||||
public Sudoku getSubGrid(int i) {
|
||||
return subGrids.get(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie la liste des Cells contenue dans ce MultiDoku,
|
||||
* soit les Cells contenues de chaques sous-Sudoku.
|
||||
*
|
||||
* @return List<Cell>
|
||||
*/
|
||||
public List<Cell> getCells() {
|
||||
Set<Cell> cellsSet = new HashSet<>();
|
||||
for (Sudoku sudoku : subGrids) {
|
||||
cellsSet.addAll(sudoku.getCells());
|
||||
}
|
||||
return new ArrayList<>(cellsSet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Multidoku {");
|
||||
for (Sudoku sudoku : subGrids) {
|
||||
sb.append("\n\t").append(sudoku.toString());
|
||||
}
|
||||
sb.append("\n}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie les sous-Sudoku
|
||||
*
|
||||
* @return List<Sudoku>
|
||||
*/
|
||||
public List<Sudoku> getSubGrids() {
|
||||
return this.subGrids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check si le MultiDoku est résolu, c'est à dire complet et cohérent avec ses contraintes.
|
||||
*
|
||||
@@ -49,6 +93,21 @@ public class MultiDoku {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie la 1re Cell vide des sous-Sudoku.
|
||||
*
|
||||
* @return Cell, une Cell vide, ou null s'il n'y en a pas.
|
||||
*/
|
||||
public Cell getFirstEmptyCell() {
|
||||
for (Sudoku sudoku : this.subGrids) {
|
||||
Cell cellTmp = sudoku.getFirstEmptyCell();
|
||||
if (cellTmp != null) {
|
||||
return cellTmp;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie la liste des Cells préalablement remplies du MultiDoku.
|
||||
*
|
||||
@@ -80,51 +139,14 @@ public class MultiDoku {
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie la 1re Cell vide des sous-Sudoku.
|
||||
*
|
||||
* @return Cell, une Cell vide, ou null s'il n'y en a pas.
|
||||
* Vide une Cell donnée.
|
||||
*
|
||||
* @param cell Cell, à vider.
|
||||
*/
|
||||
public Cell getFirstEmptyCell() {
|
||||
for (Sudoku sudoku : this.subGrids) {
|
||||
Cell cellTmp = sudoku.getFirstEmptyCell();
|
||||
if (cellTmp != null) {
|
||||
return cellTmp;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie le nombre de sudoku contenu dans ce MultiDoku.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public int getNbSubGrids() {
|
||||
return subGrids.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie la ie sudoku contenue dans ce MultiDoku.
|
||||
*
|
||||
* @param i int, indice du sudoku à renvoyer.
|
||||
* @return Sudoku, ie Sudoku
|
||||
*/
|
||||
public Sudoku getSubGrid(int i) {
|
||||
return subGrids.get(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie la liste des Cells contenue dans ce MultiDoku,
|
||||
* soit les Cells contenues de chaques sous-Sudoku.
|
||||
*
|
||||
* @return List<Cell>
|
||||
*/
|
||||
public List<Cell> getCells() {
|
||||
Set<Cell> cellsSet = new HashSet<>();
|
||||
for (Sudoku sudoku : subGrids) {
|
||||
cellsSet.addAll(sudoku.getCells());
|
||||
}
|
||||
return new ArrayList<>(cellsSet);
|
||||
public void empty(Cell cell) {
|
||||
List<Cell> cells = getCells();
|
||||
Cell cellToEmpty = cells.get(cells.indexOf(cell));
|
||||
cellToEmpty.setSymbolIndex(Cell.NOSYMBOL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,9 +167,22 @@ public class MultiDoku {
|
||||
}
|
||||
}
|
||||
|
||||
public StateManager getStateManager() {
|
||||
return stateManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Vide les Cells modifiable.
|
||||
* Renvoie une Cell vide choisie aléatoirement.
|
||||
*
|
||||
* @param rand Random, pour le choix aléatoire.
|
||||
* @return Cell, une Cell vide.
|
||||
*/
|
||||
public Cell getRandomEmptyCell(Random rand) {
|
||||
List<Cell> emptyCells = getEmptyCells();
|
||||
int randomIndex = rand.nextInt(emptyCells.size());
|
||||
return emptyCells.get(randomIndex);
|
||||
}
|
||||
|
||||
public void clearMutableCells() {
|
||||
for (Sudoku s : getSubGrids()) {
|
||||
for (Cell cell : s.getCells()) {
|
||||
@@ -157,53 +192,8 @@ public class MultiDoku {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie les sous-Sudoku
|
||||
*
|
||||
* @return List<Sudoku>
|
||||
*/
|
||||
public List<Sudoku> getSubGrids() {
|
||||
return this.subGrids;
|
||||
}
|
||||
|
||||
public StateManager getStateManager() {
|
||||
return stateManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof MultiDoku otherDoku))
|
||||
return false;
|
||||
if (this.getNbSubGrids() != otherDoku.getNbSubGrids())
|
||||
return false;
|
||||
for (int i = 0; i < this.getNbSubGrids(); i++) {
|
||||
Sudoku sudoku = this.getSubGrid(i);
|
||||
Sudoku otherSudoku = otherDoku.getSubGrid(i);
|
||||
if (sudoku.getSize() != otherSudoku.getSize())
|
||||
return false;
|
||||
for (int j = 0; j < sudoku.getSize() * sudoku.getSize(); j++) {
|
||||
if (sudoku.getCell(i).getSymbolIndex() != otherSudoku.getCell(i).getSymbolIndex())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Multidoku {");
|
||||
for (Sudoku sudoku : subGrids) {
|
||||
sb.append("\n\t").append(sudoku.toString());
|
||||
}
|
||||
sb.append("\n}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public MultiDoku clone() {
|
||||
// TODO: C'est pas dingue de le faire comme ça...
|
||||
// TODO: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah
|
||||
return SudokuSerializer.deserializeSudoku(SudokuSerializer.serializeSudoku(this));
|
||||
}
|
||||
|
||||
// </editor-fold>
|
||||
}
|
||||
|
||||
@@ -4,49 +4,35 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* Une pile, qui réprésente les états d'un MultiDoku,
|
||||
* utile pour les Solvers.
|
||||
*/
|
||||
//TODO: doc
|
||||
public class StateManager {
|
||||
|
||||
/**
|
||||
* Le MultiDoku auquel il est associé.
|
||||
*/
|
||||
private final MultiDoku doku;
|
||||
|
||||
/**
|
||||
* La pile des états du MultiDoku associé.
|
||||
*/
|
||||
private final Stack<Map<Cell, Integer>> states;
|
||||
private final MultiDoku doku;
|
||||
|
||||
public StateManager(MultiDoku doku) {
|
||||
this.states = new Stack<>();
|
||||
this.doku = doku;
|
||||
}
|
||||
|
||||
public void forgetState() {
|
||||
states.pop();
|
||||
}
|
||||
|
||||
public Map<Cell, Integer> pushState() {
|
||||
states.add(saveState());
|
||||
return states.getLast();
|
||||
}
|
||||
|
||||
public void popState() {
|
||||
assert (!states.isEmpty());
|
||||
assert (states.size() > 0);
|
||||
restoreState(states.pop());
|
||||
}
|
||||
|
||||
public Map<Cell, Integer> popAndGetState() {
|
||||
assert (!states.isEmpty());
|
||||
assert (states.size() > 0);
|
||||
var currentState = saveState();
|
||||
restoreState(states.pop());
|
||||
return currentState;
|
||||
}
|
||||
|
||||
public void restoreState(Map<Cell, Integer> state) {
|
||||
private void restoreState(Map<Cell, Integer> state) {
|
||||
for (var entry : state.entrySet()) {
|
||||
entry.getKey().setSymbolIndex(entry.getValue());
|
||||
}
|
||||
|
||||
@@ -12,33 +12,24 @@ import sudoku.constraint.IConstraint;
|
||||
*/
|
||||
public class Sudoku {
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="ATTRIBUTS">
|
||||
|
||||
/**
|
||||
* Liste des Block contenus dans le Sudoku.
|
||||
*/
|
||||
private final List<Block> blocks;
|
||||
|
||||
/**
|
||||
* Liste des Cells contenus dans le Sudoku.
|
||||
*/
|
||||
private final List<Cell> cells;
|
||||
|
||||
private List<Cell> cells = new ArrayList<>();
|
||||
/**
|
||||
* Liste des contraintes (TODO) du Sudoku.
|
||||
*/
|
||||
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;
|
||||
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="METHODES">
|
||||
|
||||
public Sudoku(List<Cell> cells, List<Block> blocks, List<IConstraint> constraints) {
|
||||
this.cells = cells;
|
||||
this.blocks = blocks;
|
||||
@@ -106,79 +97,31 @@ public class Sudoku {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
public boolean isSolved() {
|
||||
boolean isComplete = isComplete();
|
||||
boolean isValid = isValid();
|
||||
return isComplete && isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return getFirstEmptyCell() == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
for (int i = 0; i < cells.size(); i++) {
|
||||
Cell cell = getCell(i);
|
||||
if (cell.isEmpty())
|
||||
continue;
|
||||
|
||||
Coordinate coordinate = toCoords(i);
|
||||
|
||||
int symbolPlaced = cell.empty();
|
||||
if (!canBePlaced(coordinate.getX(), coordinate.getY(), symbolPlaced)) {
|
||||
cell.setSymbolIndex(symbolPlaced);
|
||||
return false;
|
||||
}
|
||||
cell.setSymbolIndex(symbolPlaced);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie la Cell aux coordonées données.
|
||||
*
|
||||
* @param x int, abscisse.
|
||||
* @param y int, ordonnée.
|
||||
* @return Cell, si une Cell existe aux coordonnées données, null sinon.
|
||||
*/
|
||||
public Cell getCell(int x, int y) {
|
||||
int index = toIndex(x, y);
|
||||
public void clearCell(int x, int y) {
|
||||
assert (isValidCoords(x, y));
|
||||
try {
|
||||
return this.cells.get(index);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
return null;
|
||||
}
|
||||
Cell cell = getCell(x, y);
|
||||
cell.setSymbolIndex(Cell.NOSYMBOL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renvoie la 1re Cell vide du Sudoku.
|
||||
*
|
||||
* @return Cell, une Cell vide, ou null s'il n'y en a pas.
|
||||
* Vide toutes les Cell du Sudoku.
|
||||
*/
|
||||
public Cell getFirstEmptyCell() {
|
||||
for (Cell cell : this.cells) {
|
||||
if (cell.isEmpty()) {
|
||||
return cell;
|
||||
}
|
||||
public void clear() {
|
||||
for (int i = 0; i < getSize() * getSize(); i++) {
|
||||
Cell cell = getCell(i);
|
||||
if (cell.isMutable())
|
||||
cell.setSymbolIndex(Cell.NOSYMBOL);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getBlockWidth() {
|
||||
return blockWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -246,14 +189,24 @@ public class Sudoku {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasConstraint(Constraint constraint) {
|
||||
return this.constraints.contains(constraint.getConstraint());
|
||||
public Cell getCell(int x, int y) {
|
||||
int index = toIndex(x, y);
|
||||
assert (isValidCoords(x, y));
|
||||
try {
|
||||
return this.cells.get(index);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Cell getCell(int i) {
|
||||
return this.cells.get(i);
|
||||
}
|
||||
|
||||
public List<IConstraint> getConstraints() {
|
||||
return constraints;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.blocks.size();
|
||||
}
|
||||
@@ -266,19 +219,16 @@ public class Sudoku {
|
||||
return this.blocks;
|
||||
}
|
||||
|
||||
public List<IConstraint> getConstraints() {
|
||||
return constraints;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public boolean contains(Cell cell) {
|
||||
return this.cells.contains(cell);
|
||||
}
|
||||
|
||||
public int getBlockWidth() {
|
||||
return blockWidth;
|
||||
}
|
||||
|
||||
public void setBlockWidth(int blockWidth) {
|
||||
this.blockWidth = blockWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Sudoku {");
|
||||
@@ -293,6 +243,71 @@ public class Sudoku {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="METHODES">
|
||||
/**
|
||||
* Renvoie la 1re Cell vide du Sudoku.
|
||||
*
|
||||
* @return Cell, une Cell vide, ou null s'il n'y en a pas.
|
||||
*/
|
||||
public Cell getFirstEmptyCell() {
|
||||
for (Cell cell : this.cells) {
|
||||
if (cell.isEmpty()) {
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
boolean isComplete = isComplete();
|
||||
boolean isValid = isValid();
|
||||
return isComplete && isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return getFirstEmptyCell() == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
for (int i = 0; i < cells.size(); i++) {
|
||||
Cell cell = getCell(i);
|
||||
if (cell.isEmpty())
|
||||
continue;
|
||||
|
||||
Coordinate coordinate = toCoords(i);
|
||||
|
||||
int symbolPlaced = cell.empty();
|
||||
if (!canBePlaced(coordinate.getX(), coordinate.getY(), symbolPlaced)) {
|
||||
cell.setSymbolIndex(symbolPlaced);
|
||||
return false;
|
||||
}
|
||||
cell.setSymbolIndex(symbolPlaced);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setBlockWidth(int blockWidth) {
|
||||
this.blockWidth = blockWidth;
|
||||
}
|
||||
|
||||
public boolean hasConstraint(Constraint constraint) {
|
||||
return this.constraints.contains(constraint.getConstraint());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,11 +27,8 @@ public class SudokuFactory {
|
||||
* Comprend les contraintes de blocs, de lignes, et de colonnes.
|
||||
*/
|
||||
public static List<IConstraint> DEFAULT_CONSTRAINTS = SudokuFactory
|
||||
.fromConstraints(Arrays.asList(
|
||||
Constraint.Block,
|
||||
Constraint.Column,
|
||||
Constraint.Line)
|
||||
);
|
||||
.fromConstraints(Arrays.asList(Constraint.Block, Constraint.Column,
|
||||
Constraint.Line));
|
||||
|
||||
/**
|
||||
* Créée des Cells et les met dans une liste de taille size.
|
||||
@@ -68,6 +65,9 @@ public class SudokuFactory {
|
||||
int index = ((y + blockY * height) * size + (x + blockX * width));
|
||||
Cell blockCell = cells.get(index);
|
||||
blockCell.setBlock(newBlock);
|
||||
// List<Block> blockContainers = new ArrayList<>();
|
||||
// blockContainers.add(newBlock);
|
||||
// blockCell.setBlockContainers(blockContainers);
|
||||
newBlock.addCell(blockCell);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public class SudokuFactory {
|
||||
*/
|
||||
public static MultiDoku createBasicEmptyRectangleDoku(int widthBlock, int heightBlock,
|
||||
List<IConstraint> constraints) {
|
||||
return new MultiDoku(List.of(createRectangleSudoku(widthBlock, heightBlock, constraints)));
|
||||
return new MultiDoku(Arrays.asList(createRectangleSudoku(widthBlock, heightBlock, constraints)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,7 +96,63 @@ public class SudokuFactory {
|
||||
* @return MultiDoku, MultiDoku vide.
|
||||
*/
|
||||
public static MultiDoku createBasicEmptySquareDoku(int size, List<IConstraint> constraints) {
|
||||
return new MultiDoku(List.of(createSquareSudoku(size, constraints)));
|
||||
return new MultiDoku(Arrays.asList(createSquareSudoku(size, constraints)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public static void setImmutableCells(MultiDoku doku, Map<Coordinate, Integer> immutableCells) {
|
||||
immutableCells.forEach((coordinate, symbol) -> {
|
||||
for (Sudoku sudoku : doku.getSubGrids()) {
|
||||
Cell cell = sudoku.getCell(coordinate.getX(), coordinate.getY());
|
||||
if (cell != null) {
|
||||
cell.setSymbolIndex(symbol);
|
||||
cell.setImmutable();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée un MultiDoku de difficulté difficulty à partir d'un MultiDoku fourni.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public static boolean newDokuFromFilledOne(MultiDoku doku, int nbCellsToEmpty, Solver solver) throws Exception {
|
||||
|
||||
if (nbCellsToEmpty >= doku.getCells().size()) {
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
if (nbCellsToEmpty == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<Cell> cellsThatCanBeEmptied = doku.getFilledCells();
|
||||
|
||||
int index = random.nextInt(cellsThatCanBeEmptied.size());
|
||||
Cell cellToEmpty = cellsThatCanBeEmptied.get(index);
|
||||
|
||||
cellToEmpty.empty();
|
||||
|
||||
int nbDokuSultions = solver.countSolution(doku);
|
||||
if (nbDokuSultions == 1) {
|
||||
return newDokuFromFilledOne(doku, --nbCellsToEmpty, solver);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,10 +227,7 @@ 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.
|
||||
* 2 3
|
||||
* 1
|
||||
* 4 5
|
||||
*
|
||||
*
|
||||
* @param size int, largeur des Blocks unitraires des Sudokus à crééer.
|
||||
* @return MultiDoku, MultiDoku de forme X.
|
||||
*/
|
||||
@@ -185,21 +238,24 @@ public class SudokuFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée un MultiDoku de Blocks rectangulaires de forme X, de taille width par height composé
|
||||
* 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.
|
||||
* 2 3
|
||||
* 1
|
||||
* 4 5
|
||||
*
|
||||
* @param width int, largeur des Blocks unitaires des Sudokus à crééer.
|
||||
* @param height int, hauteur des Blocks unitaires des Sudokus à crééer.
|
||||
* @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 createBasicXShapedMultidoku(int width, int height, List<IConstraint> constraints) {
|
||||
assert (width > 1 && height > 1);
|
||||
|
||||
/*
|
||||
* 2 3
|
||||
* 1
|
||||
* 4 5
|
||||
*/
|
||||
|
||||
Sudoku sudoku1 = createRectangleSudoku(width, height, constraints);
|
||||
Sudoku sudoku2 = createRectangleSudoku(width, height, constraints);
|
||||
Sudoku sudoku3 = createRectangleSudoku(width, height, constraints);
|
||||
@@ -215,16 +271,13 @@ public class SudokuFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée un MultiDoku de Blocks carrés de forme +, de taille size composé
|
||||
* de cinq Sudokus,
|
||||
* dont un central qui partage chacun de ses Blocks de bord avec un autre
|
||||
* 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.
|
||||
* 3
|
||||
* 2 1 4
|
||||
* 5
|
||||
*
|
||||
* @param size int, largeur des Blocks unitaires des Sudokus à crééer.
|
||||
* @return MultiDoku, MultiDoku de forme +.
|
||||
* @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);
|
||||
@@ -233,21 +286,25 @@ public class SudokuFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée un MultiDoku de Blocks rectangulaires de forme +, de taille width par height composé
|
||||
* 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 de bord avec un autre
|
||||
* dont un central qui partage chacun de ses Blocks d'angle avec un autre
|
||||
* Sudoku.
|
||||
* 3
|
||||
* 2 1 4
|
||||
* 5
|
||||
*
|
||||
* @param width int, largeur des Blocks unitaires des Sudokus à crééer.
|
||||
* @param height int, hauteur des Blocks unitaires des Sudokus à crééer.
|
||||
* @return MultiDoku, MultiDoku de forme +.
|
||||
* @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);
|
||||
@@ -262,13 +319,25 @@ public class SudokuFactory {
|
||||
return new MultiDoku(Arrays.asList(sudoku1, sudoku2, sudoku3, sudoku4, sudoku5));
|
||||
}
|
||||
|
||||
/**
|
||||
* Crée un Sudoku vide avec les Blocks aléatoires.
|
||||
*
|
||||
* @param blockSize int, la taille des Block.
|
||||
* @param constraints List<IConstraint>, la liste des contraintes.
|
||||
* @return MultiDoku, avec un seul Sudoku.
|
||||
*/
|
||||
public static void fillDoku(MultiDoku doku, Difficulty difficulty) throws Exception {
|
||||
Solver solver = new RandomSolver();
|
||||
solver.solve(doku);
|
||||
int nbCellsToEmpty = (int) (difficulty.getFactor() * doku.getNbCells());
|
||||
boolean successfull = newDokuFromFilledOne(doku, nbCellsToEmpty, solver);
|
||||
doku.setFilledCellsImmutable();
|
||||
}
|
||||
|
||||
public static MultiDoku fromfile(String filePath) {
|
||||
try {
|
||||
String content = Files.readString(Paths.get(filePath));
|
||||
MultiDoku doku = SudokuSerializer.deserializeSudoku(content);
|
||||
return doku;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static MultiDoku createBasicEmptyRandomBlockDoku(int blockSize, List<IConstraint> constraints) {
|
||||
int blockCellCount = blockSize * blockSize;
|
||||
List<Cell> cells = initCells(blockCellCount);
|
||||
@@ -289,79 +358,9 @@ public class SudokuFactory {
|
||||
for (Block block : blocks) {
|
||||
block.getSudokus().add(sudoku);
|
||||
}
|
||||
return new MultiDoku(List.of(sudoku));
|
||||
return new MultiDoku(Arrays.asList(sudoku));
|
||||
}
|
||||
|
||||
/**
|
||||
* Créée un MultiDoku de difficulté difficulty à partir d'un MultiDoku fourni.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public static boolean newDokuFromFilledOne(MultiDoku doku, int nbCellsToEmpty, Solver solver) throws Exception {
|
||||
|
||||
if (nbCellsToEmpty >= doku.getCells().size()) {
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
if (nbCellsToEmpty == 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<Cell> cellsThatCanBeEmptied = doku.getFilledCells();
|
||||
|
||||
int index = random.nextInt(cellsThatCanBeEmptied.size());
|
||||
Cell cellToEmpty = cellsThatCanBeEmptied.get(index);
|
||||
|
||||
cellToEmpty.empty();
|
||||
|
||||
int nbDokuSultions = solver.countSolution(doku);
|
||||
if (nbDokuSultions == 1) {
|
||||
return newDokuFromFilledOne(doku, --nbCellsToEmpty, solver);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rempli un MultiDoku donné par rapport à un difficulté.
|
||||
*
|
||||
* @param doku MultiDoku, vide.
|
||||
* @param difficulty Difficulty, qui correspond au pourcentage de cases à enlever.
|
||||
*/
|
||||
public static void fillDoku(MultiDoku doku, Difficulty difficulty) throws Exception {
|
||||
Solver solver = new RandomSolver();
|
||||
solver.solve(doku);
|
||||
int nbCellsToEmpty = (int) (difficulty.getFactor() * doku.getNbCells());
|
||||
newDokuFromFilledOne(doku, nbCellsToEmpty, solver);
|
||||
doku.setFilledCellsImmutable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Génère un MultiDoku à partir d'un fichier de sauvegarde.
|
||||
*
|
||||
* @param filePath String, chemin du fichier.
|
||||
* @return MultiDoku.
|
||||
*/
|
||||
public static MultiDoku fromfile(String filePath) {
|
||||
try {
|
||||
String content = Files.readString(Paths.get(filePath));
|
||||
return SudokuSerializer.deserializeSudoku(content);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforme des Constraint en IConstraint correspondants
|
||||
* @param constraints List<Constraints>
|
||||
* @return List<IConstraints>
|
||||
*/
|
||||
public static List<IConstraint> fromConstraints(List<Constraint> constraints) {
|
||||
List<IConstraint> iconstraints = new ArrayList<>();
|
||||
for (Constraint cons : constraints) {
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
package sudoku.structure;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import sudoku.solver.BacktrackingSolver;
|
||||
import sudoku.solver.HumanSolver;
|
||||
import sudoku.solver.MixedSolver;
|
||||
import sudoku.solver.RandomSolver;
|
||||
import sudoku.solver.Solver;
|
||||
|
||||
public class SudokuFiller {
|
||||
|
||||
private static boolean isPossiblySolvable(MultiDoku doku) {
|
||||
for (Cell cell : doku.getEmptyCells()) {
|
||||
if (cell.getPossibleSymbols().size() == 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void tryFillRandomCells(MultiDoku doku) {
|
||||
Random r = new Random();
|
||||
while (isPossiblySolvable(doku)) {
|
||||
int cellCount = doku.getEmptyCells().size();
|
||||
if (cellCount == 0)
|
||||
return;
|
||||
Cell cellToFill = doku.getEmptyCells().get(r.nextInt(cellCount));
|
||||
if (!cellToFill.isEmpty() || !cellToFill.isMutable())
|
||||
continue;
|
||||
|
||||
List<Integer> possibleSymbols = cellToFill.getPossibleSymbols();
|
||||
int symbolCount = possibleSymbols.size();
|
||||
// la cellule n'a pas de valeur possible
|
||||
if (symbolCount == 0)
|
||||
return;
|
||||
|
||||
cellToFill.setSymbolIndex(possibleSymbols.get(r.nextInt(symbolCount)));
|
||||
}
|
||||
}
|
||||
|
||||
private static void removeRandomCell(MultiDoku doku) {
|
||||
Random r = new Random();
|
||||
int cellCount = doku.getFilledCells().size();
|
||||
doku.getFilledCells().get(r.nextInt(cellCount)).clearCurrentSymbol();
|
||||
}
|
||||
|
||||
private static void makeSolvable(MultiDoku doku) {
|
||||
while (!isPossiblySolvable(doku)) {
|
||||
removeRandomCell(doku);
|
||||
}
|
||||
Solver solver = new BacktrackingSolver();
|
||||
boolean solvable = false;
|
||||
while (!solvable) {
|
||||
removeRandomCell(doku);
|
||||
doku.getStateManager().pushState();
|
||||
solvable = solver.solve(doku);
|
||||
doku.getStateManager().popState();
|
||||
System.out.println("eeeeeeeeeeeee");
|
||||
}
|
||||
}
|
||||
|
||||
private static void fillDoku(MultiDoku doku) {
|
||||
tryFillRandomCells(doku);
|
||||
makeSolvable(doku);
|
||||
}
|
||||
|
||||
private static void setCellsImmutable(MultiDoku doku) {
|
||||
for (Cell cell : doku.getFilledCells())
|
||||
cell.setImmutable();
|
||||
}
|
||||
|
||||
public static void fillDoku(MultiDoku doku, Difficulty difficulty) {
|
||||
fillDoku(doku);
|
||||
setCellsImmutable(doku);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package sudoku;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Random;
|
||||
@@ -21,7 +22,7 @@ public class SudokuSerializerTest {
|
||||
new RandomSolver().solve(sudoku);
|
||||
JSONObject data = SudokuSerializer.serializeSudoku(sudoku);
|
||||
MultiDoku multiDoku = SudokuSerializer.deserializeSudoku(data);
|
||||
assertEquals(data.toString(), SudokuSerializer.serializeSudoku(multiDoku).toString());
|
||||
assertTrue(data.toString().equals(SudokuSerializer.serializeSudoku(multiDoku).toString()));
|
||||
}
|
||||
|
||||
void testSaveWithSize(int blockWidth, int blockHeight) {
|
||||
@@ -40,7 +41,7 @@ public class SudokuSerializerTest {
|
||||
File fileToDelete = new File(savePath);
|
||||
fileToDelete.delete();
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
e.printStackTrace();
|
||||
assert false;
|
||||
}
|
||||
}
|
||||
@@ -51,27 +52,25 @@ public class SudokuSerializerTest {
|
||||
JSONObject data = SudokuSerializer.serializeSudoku(sudoku);
|
||||
MultiDoku multiDoku = SudokuSerializer.deserializeSudoku(data);
|
||||
|
||||
assertEquals(data.toString(), SudokuSerializer.serializeSudoku(multiDoku).toString());
|
||||
assertTrue(data.toString().equals(SudokuSerializer.serializeSudoku(multiDoku).toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerialize() {
|
||||
Random r = new Random();
|
||||
int testCount = 20;
|
||||
int minSize = 2;
|
||||
int maxSize = 3;
|
||||
for (int i = 0; i < testCount; i++) {
|
||||
int blockWidth = r.nextInt(maxSize - minSize + 1) + minSize;
|
||||
int blockHeight = r.nextInt(maxSize - minSize + 1) + minSize;
|
||||
int blockWidth = r.nextInt(4) + 1;
|
||||
int blockHeight = r.nextInt(4) + 1;
|
||||
testSerializeWithSize(blockWidth, blockHeight);
|
||||
}
|
||||
for (int i = 0; i < testCount; i++) {
|
||||
int blockWidth = r.nextInt(maxSize - minSize + 1) + minSize;
|
||||
int blockHeight = r.nextInt(maxSize - minSize + 1) + minSize;
|
||||
int blockWidth = r.nextInt(4) + 1;
|
||||
int blockHeight = r.nextInt(4) + 1;
|
||||
testSaveWithSize(blockWidth, blockHeight);
|
||||
}
|
||||
for (int i = 0; i < testCount; i++) {
|
||||
int size = r.nextInt(maxSize - minSize + 1) + minSize;
|
||||
int size = r.nextInt(2) + 2;
|
||||
testSerializeX(size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +1,31 @@
|
||||
package sudoku.solver;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import gui.constants.Symbols;
|
||||
import sudoku.io.SudokuPrinter;
|
||||
import sudoku.io.SudokuSerializer;
|
||||
import sudoku.structure.Cell;
|
||||
import sudoku.structure.Difficulty;
|
||||
import sudoku.structure.MultiDoku;
|
||||
import sudoku.structure.Sudoku;
|
||||
import sudoku.structure.SudokuFactory;
|
||||
|
||||
class SolverTest {
|
||||
private int ns = Cell.NOSYMBOL;
|
||||
protected static HumanSolver h;
|
||||
private static RandomSolver r;
|
||||
private static MixedSolver m;
|
||||
|
||||
@BeforeAll
|
||||
public static void initializeSolvers() {
|
||||
h = new HumanSolver();
|
||||
r = new RandomSolver();
|
||||
m = new MixedSolver();
|
||||
}
|
||||
@Test
|
||||
void solveTest() {
|
||||
MultiDoku dokuToTest = SudokuFactory.createBasicEmptySquareDoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
MultiDoku dokuResult = SudokuFactory.createBasicEmptySquareDoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
|
||||
private void testSize2(Solver solver) {
|
||||
MultiDoku mdTest = SudokuFactory.createBasicEmptySquareDoku(2, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
MultiDoku mdResult = SudokuFactory.createBasicEmptySquareDoku(2, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
Sudoku test = mdTest.getSubGrid(0);
|
||||
Sudoku result = mdResult.getSubGrid(0);
|
||||
List<Integer> immutableCells = List.of(
|
||||
ns, 2, 3, ns,
|
||||
0, ns, ns, ns,
|
||||
ns, ns, ns, 3,
|
||||
ns, 0, 1, ns);
|
||||
assertTrue(test.setImmutableCellsSymbol(immutableCells));
|
||||
List<Integer> correctCells = List.of(
|
||||
1, 2, 3, 0,
|
||||
0, 3, 2, 1,
|
||||
2, 1, 0, 3,
|
||||
3, 0, 1, 2);
|
||||
assertTrue(result.setCellsSymbol(correctCells));
|
||||
assertTrue(result.isSolved());
|
||||
|
||||
assertNotEquals(mdResult, mdTest);
|
||||
solver.solve(mdTest);
|
||||
assertTrue(mdTest.isSolved());
|
||||
Sudoku sudokuToTest = dokuToTest.getSubGrid(0);
|
||||
Sudoku sudokuResult = dokuResult.getSubGrid(0);
|
||||
|
||||
assertEquals(mdTest, mdResult);
|
||||
}
|
||||
|
||||
private void testSize3(Solver solver) {
|
||||
MultiDoku mdTest = SudokuFactory.createBasicEmptySquareDoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
MultiDoku mdResult = SudokuFactory.createBasicEmptySquareDoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
Sudoku test = mdTest.getSubGrid(0);
|
||||
Sudoku result = mdResult.getSubGrid(0);
|
||||
List<Integer> immutableCells = List.of(
|
||||
ns, ns, 0, ns, ns, 2, 8, ns, 1,
|
||||
int ns = Cell.NOSYMBOL;
|
||||
List<Integer> immutableCells = List.of(ns, ns, 0, ns, ns, 2, 8, ns, 1,
|
||||
ns, 3, ns, ns, 5, 6, 7, ns, ns,
|
||||
ns, ns, ns, 8, ns, 7, ns, ns, 6,
|
||||
0, ns, 1, ns, ns, ns, ns, ns, ns,
|
||||
@@ -71,9 +34,13 @@ class SolverTest {
|
||||
ns, ns, 6, ns, ns, 8, ns, 7, 5,
|
||||
8, 0, ns, 7, ns, 5, 2, ns, 3,
|
||||
5, ns, ns, ns, 3, 1, 0, ns, ns);
|
||||
assert (test.setImmutableCellsSymbol(immutableCells));
|
||||
List<Integer> correctCells = List.of(
|
||||
7, 6, 0, 3, 4, 2, 8, 5, 1,
|
||||
|
||||
assert (sudokuToTest.setImmutableCellsSymbol(immutableCells));
|
||||
|
||||
//SudokuPrinter.printRectangleSudoku(dokuToTest.getSubGrid(0), 3, 3);
|
||||
SudokuPrinter.printMultiDoku(dokuToTest, 3, 3, Symbols.Numbers);
|
||||
|
||||
List<Integer> correctCells = List.of(7, 6, 0, 3, 4, 2, 8, 5, 1,
|
||||
2, 3, 8, 1, 5, 6, 7, 0, 4,
|
||||
1, 4, 5, 8, 0, 7, 3, 2, 6,
|
||||
0, 2, 1, 6, 8, 3, 5, 4, 7,
|
||||
@@ -82,43 +49,56 @@ class SolverTest {
|
||||
3, 1, 6, 0, 2, 8, 4, 7, 5,
|
||||
8, 0, 4, 7, 6, 5, 2, 1, 3,
|
||||
5, 7, 2, 4, 3, 1, 0, 6, 8);
|
||||
assert (result.setCellsSymbol(correctCells));
|
||||
assert (result.isSolved());
|
||||
|
||||
assertNotEquals(mdResult, mdTest);
|
||||
solver.solve(mdTest);
|
||||
assert (mdTest.isSolved());
|
||||
assertEquals(mdTest, mdResult);
|
||||
}
|
||||
sudokuResult.setCellsSymbol(correctCells);
|
||||
|
||||
private void testMDSize3(Solver solver) {
|
||||
MultiDoku mdTest = SudokuFactory.createBasicXShapedMultidoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
try {
|
||||
SudokuFactory.fillDoku(mdTest, Difficulty.Easy);
|
||||
} catch (Exception e) {
|
||||
assert (false);
|
||||
System.out.println("\n****************************Doku Control\n");
|
||||
SudokuPrinter.printRectangleSudoku(sudokuResult, 3, 3, Symbols.Russian);
|
||||
|
||||
assert (dokuResult.isSolved());
|
||||
|
||||
new RandomSolver().solve(dokuToTest);
|
||||
|
||||
System.out.println("\n****************************\nDoku solved");
|
||||
//SudokuPrinter.printRectangleSudoku(dokuToTest.getSubGrid(0), 3, 3);
|
||||
SudokuPrinter.printMultiDoku(dokuToTest, 3, 3, Symbols.Emojis);
|
||||
|
||||
assert (dokuToTest.isSolved());
|
||||
|
||||
for (Cell cell : sudokuToTest.getCells()) {
|
||||
cell.setImmutable();
|
||||
}
|
||||
MultiDoku mdResult = SudokuSerializer.deserializeSudoku(SudokuSerializer.serializeSudoku(mdTest));
|
||||
assertFalse(mdTest.isSolved());
|
||||
assertFalse(mdResult.isSolved());
|
||||
assertTrue(solver.solve(mdTest));
|
||||
assertTrue(mdTest.isSolved());
|
||||
assertFalse(mdResult.isSolved());
|
||||
assertNotEquals(mdTest, mdResult);
|
||||
solver.solve(mdResult);
|
||||
assertEquals(mdTest, mdResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
void solveTest() {
|
||||
initializeSolvers();
|
||||
testSize2(h);
|
||||
testSize3(h);
|
||||
testSize2(m);
|
||||
testSize3(m);
|
||||
testMDSize3(m);
|
||||
testSize2(r);
|
||||
testSize3(r);
|
||||
testMDSize3(r);
|
||||
for (Cell cell : sudokuResult.getCells()) {
|
||||
cell.setImmutable();
|
||||
}
|
||||
|
||||
assertEquals(SudokuSerializer.serializeSudoku(dokuResult).toString(),
|
||||
SudokuSerializer.serializeSudoku(dokuToTest).toString());
|
||||
|
||||
MultiDoku dokuToTest2 = SudokuFactory.createBasicEmptySquareDoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
Sudoku sudokuToTest2 = dokuToTest2.getSubGrid(0);
|
||||
|
||||
List<Integer> immutableCells2 = List.of(ns, ns, 0, ns, ns, 2, 8, ns, 1,
|
||||
1, 3, ns, ns, 5, 6, 7, ns, ns,
|
||||
ns, ns, ns, 8, ns, 7, ns, ns, 6,
|
||||
0, ns, 1, ns, ns, ns, ns, ns, ns,
|
||||
4, 8, 7, 5, 1, ns, 6, ns, ns,
|
||||
6, ns, 3, 2, ns, ns, ns, 8, 0,
|
||||
ns, ns, 6, ns, ns, 8, ns, 7, 5,
|
||||
8, 0, ns, 7, ns, 5, 2, ns, 3,
|
||||
5, ns, ns, ns, 3, 1, 0, ns, ns);
|
||||
sudokuToTest2.setImmutableCellsSymbol(immutableCells2);
|
||||
|
||||
boolean isSolved = new RandomSolver().solve(dokuToTest2);
|
||||
|
||||
assert (!isSolved);
|
||||
|
||||
MultiDoku dokuToTest3 = SudokuFactory.createBasicEmptySquareDoku(3, SudokuFactory.DEFAULT_CONSTRAINTS);
|
||||
|
||||
new RandomSolver().solve(dokuToTest3);
|
||||
|
||||
//SudokuPrinter.printRectangleSudoku(dokuToTest3.getSubGrid(0), 3, 3);
|
||||
SudokuPrinter.printMultiDoku(dokuToTest3, 3, 3, Symbols.Letters);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user