Simple project for solving nonogram puzzles using Kotlin
nonograms-core
- multi-platform library for creating puzzle definitions and running the solver algorithmnonograms-web
- example Kotlin/JS library usage to create a simple webpage for a user to enter puzzles to solve
- Install the
nonograms-core
library to your local Maven repository:
./gradlew publishToMavenLocal
- Add the
nonograms-core
library as a dependency in your project:
repositories {
mavenCentral()
mavenLocal() // add your local maven repository
}
dependencies {
implementation "com.askrepps:nonograms-core:1.1.1"
}
- Generate the library's API documentation:
./gradlew dokkaHtml
- Open
nonograms-core/build/dokka/html/index.html
in a web browser.
Here is an example showing how to create a puzzle definition and run the solver:
// create puzzle
val puzzle = PuzzleDefinition(
rowHints = listOf(
listOf(0),
listOf(1, 1),
listOf(1, 1),
listOf(1, 1),
listOf(0),
listOf(1, 1),
listOf(4),
listOf(0)
),
columnHints = listOf(
listOf(0),
listOf(1),
listOf(3, 1),
listOf(1),
listOf(1),
listOf(3, 1),
listOf(1),
listOf(0)
)
)
// run solver
val solution = puzzle.solve()
// access solved puzzle state
for (row in solution.state.getCellGrid()) {
println(
row.joinToString(separator = " ") { cell ->
when (cell) {
CellContents.FILLED -> "█"
CellContents.X -> "X"
CellContents.OPEN -> " "
}
}
)
}
The above example generates the following output:
X X X X X X X X
X X █ X X █ X X
X X █ X X █ X X
X X █ X X █ X X
X X X X X X X X
X █ X X X X █ X
X X █ █ █ █ X X
X X X X X X X X
Copyright © 2020-2024 Andrew Krepps