diff --git a/domain/src/main/kotlin/ch/dissem/yaep/domain/generator.kt b/domain/src/main/kotlin/ch/dissem/yaep/domain/generator.kt index 6660440..d4c0822 100644 --- a/domain/src/main/kotlin/ch/dissem/yaep/domain/generator.kt +++ b/domain/src/main/kotlin/ch/dissem/yaep/domain/generator.kt @@ -60,7 +60,20 @@ internal fun solve( } catch (e: UnsolvablePuzzleException) { return NO_SOLUTION } - // TODO clean up groups in rows (?) + // TODO: this breaks stuff and is probably unnecessary, but further tests might be needed +// grid.forEach { row -> row.forEach { cell -> row.cleanupOptions(cell) } } +// grid.forEach { row -> +// row.filter { it.selection == null && it.options.size in 2..row.size / 2 } +// .groupBy { cell -> cell.options } +// .filter { it.value.size == it.key.size } +// .forEach { entry -> +// val groupOptions = entry.key +// val group = entry.value +// println("removing options for group ${groupOptions.map { it.symbol }}") +// row.filter { !group.contains(it) } +// .forEach { it.options.removeAll(groupOptions) } +// } +// } grid.forEach { row -> row.forEach { cell -> row.cleanupOptions(cell) } } } while (removedOptions) diff --git a/domain/src/test/kotlin/ch/dissem/yaep/domain/GameTest.kt b/domain/src/test/kotlin/ch/dissem/yaep/domain/GameTest.kt index fd2f23c..7baa59c 100644 --- a/domain/src/test/kotlin/ch/dissem/yaep/domain/GameTest.kt +++ b/domain/src/test/kotlin/ch/dissem/yaep/domain/GameTest.kt @@ -15,6 +15,47 @@ import kotlin.time.measureTime class GameTest { + @Test + fun `ensure generated games are solvable`() { + val tries = 2000 + var fastest = 500.milliseconds + var slowest = 0.milliseconds + var total = 0.milliseconds + var most = 0 + var least = 1000 + var totalClues = 0 + for (i in 1..tries) { + val game: Game + val time = measureTime { + game = generateGame() + } + expect(solve(game.grid, game.clues)).toEqual(SOLVABLE) + expect(time).toBeLessThan(500.milliseconds) + if (time < fastest) { + fastest = time + } + if (time > slowest) { + slowest = time + } + total += time + if (game.clues.size > most){ + most = game.clues.size + } + if (game.clues.size < least){ + least = game.clues.size + } + totalClues += game.clues.size + } + + println("Slowest: $slowest") + println("Fastest: $fastest") + println("Average: ${total / tries}") + println("Clues:") + println("Most: $most") + println("Least: $least") + println("Average: ${totalClues / tries}") + } + @Test fun `ensure generated game is valid`() { val game: Game