Add groups to solver (WIP)
This commit is contained in:
@@ -60,7 +60,20 @@ internal fun solve(
|
|||||||
} catch (e: UnsolvablePuzzleException) {
|
} catch (e: UnsolvablePuzzleException) {
|
||||||
return NO_SOLUTION
|
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) } }
|
grid.forEach { row -> row.forEach { cell -> row.cleanupOptions(cell) } }
|
||||||
} while (removedOptions)
|
} while (removedOptions)
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,47 @@ import kotlin.time.measureTime
|
|||||||
|
|
||||||
class GameTest {
|
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
|
@Test
|
||||||
fun `ensure generated game is valid`() {
|
fun `ensure generated game is valid`() {
|
||||||
val game: Game
|
val game: Game
|
||||||
|
|||||||
Reference in New Issue
Block a user