-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
102 changed files
with
3,002 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...tegrationTest/kotlin/org/piepmeyer/gauguin/difficulty/human/HumanDifficultyBalanceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.piepmeyer.gauguin.difficulty.human | ||
|
||
import io.github.oshai.kotlinlogging.KotlinLogging | ||
import io.kotest.assertions.withClue | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
import org.piepmeyer.gauguin.game.save.SaveGame | ||
import java.io.File | ||
import java.nio.file.Files | ||
import java.util.stream.Collectors | ||
import kotlin.io.path.isDirectory | ||
import kotlin.io.path.name | ||
|
||
private val logger = KotlinLogging.logger {} | ||
|
||
class HumanDifficultyBalanceTest : | ||
FunSpec({ | ||
test("balancing") { | ||
val savedGames = | ||
Files | ||
.list(File("src/test/resources/difficulty-balancing").toPath()) | ||
.collect(Collectors.toList()) | ||
.filter { !it.isDirectory() } | ||
|
||
val namesToGrids = | ||
savedGames | ||
.associateWith { | ||
val grid = SaveGame.createWithFile(it.toFile()).restore()!! | ||
grid.clearUserValues() | ||
grid.addPossiblesAtNewGame() | ||
|
||
grid | ||
}.mapKeys { it.key.name } | ||
|
||
val namesToDifficulties = | ||
namesToGrids.mapValues { | ||
logger.info { it.key + "..." } | ||
|
||
val result = HumanSolver(it.value).solveAndCalculateDifficulty() | ||
|
||
withClue(it.key) { | ||
result.success shouldBe true | ||
} | ||
|
||
result.difficulty | ||
} | ||
|
||
namesToDifficulties.entries | ||
.sortedBy { it.value } | ||
.forEach { | ||
logger.info { "${it.value} -> ${it.key}" } | ||
} | ||
} | ||
}) |
88 changes: 88 additions & 0 deletions
88
...Test/kotlin/org/piepmeyer/gauguin/difficulty/human/HumanDifficultySolverHandpickedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.piepmeyer.gauguin.difficulty.human | ||
|
||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
import org.piepmeyer.gauguin.creation.MergingCageGridCalculator | ||
import org.piepmeyer.gauguin.creation.RandomPossibleDigitsShuffler | ||
import org.piepmeyer.gauguin.creation.SeedRandomizerMock | ||
import org.piepmeyer.gauguin.grid.GridSize | ||
import org.piepmeyer.gauguin.options.GameOptionsVariant | ||
import org.piepmeyer.gauguin.options.GameVariant | ||
|
||
class HumanDifficultySolverHandpickedTest : | ||
FunSpec({ | ||
test("seed random grid should be solved") { | ||
val randomizer = SeedRandomizerMock(16) | ||
|
||
val calculator = | ||
MergingCageGridCalculator( | ||
GameVariant( | ||
GridSize(3, 6), | ||
GameOptionsVariant.createClassic(), | ||
), | ||
randomizer, | ||
RandomPossibleDigitsShuffler(randomizer.random), | ||
) | ||
|
||
val grid = calculator.calculate() | ||
grid.cells.forEach { it.possibles = grid.variant.possibleDigits } | ||
|
||
val solver = HumanSolver(grid, true) | ||
|
||
solver.solveAndCalculateDifficulty() | ||
|
||
println(grid.toString()) | ||
|
||
grid.isSolved() shouldBe true | ||
} | ||
|
||
test("merging algo 4x4 wrong solution") { | ||
val randomizer = SeedRandomizerMock(6096) | ||
|
||
val calculator = | ||
MergingCageGridCalculator( | ||
GameVariant( | ||
GridSize(4, 4), | ||
GameOptionsVariant.createClassic(), | ||
), | ||
randomizer, | ||
RandomPossibleDigitsShuffler(randomizer.random), | ||
) | ||
|
||
val grid = calculator.calculate() | ||
grid.cells.forEach { it.possibles = grid.variant.possibleDigits } | ||
|
||
val solver = HumanSolver(grid) | ||
|
||
solver.solveAndCalculateDifficulty() | ||
|
||
println(grid.toString()) | ||
|
||
grid.isSolved() shouldBe true | ||
} | ||
|
||
test("merging algo 4x4 DetectPossiblesBreakingOtherCagesPossiblesDualLines bug") { | ||
val randomizer = SeedRandomizerMock(36) | ||
|
||
val calculator = | ||
MergingCageGridCalculator( | ||
GameVariant( | ||
GridSize(5, 5), | ||
GameOptionsVariant.createClassic(), | ||
), | ||
randomizer, | ||
RandomPossibleDigitsShuffler(randomizer.random), | ||
) | ||
|
||
val grid = calculator.calculate() | ||
grid.cells.forEach { it.possibles = grid.variant.possibleDigits } | ||
|
||
val solver = HumanSolver(grid) | ||
|
||
solver.solveAndCalculateDifficulty() | ||
|
||
println(grid.toString()) | ||
|
||
grid.isSolved() shouldBe true | ||
} | ||
}) |
53 changes: 53 additions & 0 deletions
53
...est/kotlin/org/piepmeyer/gauguin/difficulty/human/HumanDifficultySolverPerformanceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.piepmeyer.gauguin.difficulty.human | ||
|
||
import io.kotest.assertions.withClue | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.ints.shouldBeGreaterThan | ||
import io.kotest.matchers.shouldBe | ||
import org.piepmeyer.gauguin.creation.RandomCageGridCalculator | ||
import org.piepmeyer.gauguin.creation.RandomPossibleDigitsShuffler | ||
import org.piepmeyer.gauguin.creation.SeedRandomizerMock | ||
import org.piepmeyer.gauguin.grid.GridSize | ||
import org.piepmeyer.gauguin.options.GameOptionsVariant | ||
import org.piepmeyer.gauguin.options.GameVariant | ||
|
||
class HumanDifficultySolverPerformanceTest : | ||
FunSpec({ | ||
for (seed in 0..9) { | ||
withClue("seed $seed") { | ||
|
||
test("seed random grid should be solved") { | ||
val randomizer = SeedRandomizerMock(1) | ||
|
||
val calculator = | ||
RandomCageGridCalculator( | ||
GameVariant( | ||
GridSize(11, 11), | ||
GameOptionsVariant.createClassic(), | ||
), | ||
randomizer, | ||
RandomPossibleDigitsShuffler(randomizer.random), | ||
) | ||
|
||
val grid = calculator.calculate() | ||
grid.cells.forEach { it.possibles = grid.variant.possibleDigits } | ||
|
||
val solver = HumanSolver(grid) | ||
|
||
val solverResult = solver.solveAndCalculateDifficulty() | ||
|
||
println(grid.toString()) | ||
|
||
if (!grid.isSolved()) { | ||
if (grid.numberOfMistakes() != 0) { | ||
throw IllegalStateException("Found a grid with wrong values.") | ||
} | ||
} | ||
|
||
grid.isSolved() shouldBe true | ||
|
||
solverResult.difficulty shouldBeGreaterThan 0 | ||
} | ||
} | ||
} | ||
}) |
71 changes: 71 additions & 0 deletions
71
...ntegrationTest/kotlin/org/piepmeyer/gauguin/difficulty/human/HumanDifficultySolverTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package org.piepmeyer.gauguin.difficulty.human | ||
|
||
import io.kotest.assertions.withClue | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.ints.shouldBeGreaterThan | ||
import io.kotest.matchers.shouldBe | ||
import org.piepmeyer.gauguin.creation.MergingCageGridCalculator | ||
import org.piepmeyer.gauguin.creation.RandomPossibleDigitsShuffler | ||
import org.piepmeyer.gauguin.creation.SeedRandomizerMock | ||
import org.piepmeyer.gauguin.grid.GridSize | ||
import org.piepmeyer.gauguin.options.GameOptionsVariant | ||
import org.piepmeyer.gauguin.options.GameVariant | ||
|
||
class HumanDifficultySolverTest : | ||
FunSpec({ | ||
for (seed in 0..999) { | ||
// 10_000 of 4x4, random: 4 left unsolved | ||
// 10_000 of 4x4, merge: 19 left unsolved | ||
// 10_000 of 5x5, merge: 134 left unsolved | ||
// 10_000 of 2x4, merge: no (!) left unsolved | ||
// 1_000 of 3x6, merge: 119 left unsolved | ||
// 1_000 of 6x6, merge: 90 left unsolved | ||
// 100 of 9x9, merge: 50 left unsolved | ||
withClue("seed $seed") { | ||
test("seed random grid should be solved") { | ||
val randomizer = SeedRandomizerMock(seed) | ||
|
||
val calculator = | ||
MergingCageGridCalculator( | ||
GameVariant( | ||
GridSize(6, 6), | ||
GameOptionsVariant.createClassic(), | ||
), | ||
randomizer, | ||
RandomPossibleDigitsShuffler(randomizer.random), | ||
) | ||
|
||
val grid = calculator.calculate() | ||
grid.cells.forEach { it.possibles = grid.variant.possibleDigits } | ||
|
||
val solver = HumanSolver(grid, true) | ||
|
||
val solverResult = solver.solveAndCalculateDifficulty() | ||
|
||
println(grid.toString()) | ||
|
||
if (!grid.isSolved()) { | ||
if (grid.numberOfMistakes() != 0) { | ||
throw IllegalStateException("Found a grid with wrong values.") | ||
} | ||
grid.isActive = true | ||
grid.startedToBePlayed = true | ||
grid.description = "${grid.gridSize.width}x${grid.gridSize.height}-$seed" | ||
/*val saveGame = | ||
SaveGame.createWithFile( | ||
File( | ||
SaveGame.SAVEGAME_NAME_PREFIX + | ||
"${grid.numberOfMistakes()}-${grid.gridSize.width}x${grid.gridSize.height}-$seed.yml", | ||
), | ||
) | ||
saveGame.save(grid)*/ | ||
} | ||
|
||
grid.isSolved() shouldBe true | ||
|
||
solverResult.difficulty shouldBeGreaterThan 0 | ||
} | ||
} | ||
} | ||
}) |
Oops, something went wrong.