Skip to content

Commit

Permalink
Merge pull request #71 from teogor/feature/add-sudoklify-modules-beta
Browse files Browse the repository at this point in the history
Release Sudoklify Beta Modules: Common, Core, IO, Presets, Solver, and Tokenizer
  • Loading branch information
teogor authored Aug 17, 2024
2 parents affaacf + 93d2297 commit a8ab223
Show file tree
Hide file tree
Showing 112 changed files with 7,454 additions and 3,604 deletions.
59 changes: 28 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,51 +59,48 @@ challenge. 🧠🧩🚀

## Usage

### Generating Sudoku Puzzles

To generate Sudoku puzzles using Sudoklify, follow these steps:

1. Add Sudoklify as a dependency in your project.

2. Create a `ParamsBuilder` to configure the puzzle generation parameters.
1. **Initialize the Architect**: Start by creating a `SudoklifyArchitect` instance. This allows you
to load preset schemas and optionally add your own custom schemas.

```kotlin
import dev.teogor.sudoklify.sudokuParamsBuilder
import dev.teogor.sudoklify.model.Difficulty
import dev.teogor.sudoklify.model.GameType

// Configure puzzle generation parameters
val sudokuParams = sudokuParamsBuilder {
difficulty { Difficulty.MEDIUM }
seed { createSeed(2024) }
type { GameType.ThreeByThree }
val architect = SudoklifyArchitect {
SudokuSchemas(loadPresetSchemas()) {
// TODO Optional: Add own schemas using add(*), addAll(*)
}
}
```

3. Generate the Sudoku puzzle using the `generateSudoku` extension function.
2. **Define the Sudoku Specification**: Create a `SudokuSpec` to specify the puzzle's seed, grid
dimension, and difficulty level.

```kotlin
import dev.teogor.sudoklify.extensions.generateSudoku

val sudoku = sudokuParams.generateSudoku()
val sudokuSpec = SudokuSpec {
seed = 2024L.toSeed()
type = Dimension.NineByNine
difficulty = Difficulty.EASY
}
```

### Accessing Generated Sudoku
3. **Generate Sudoku Puzzles**: Use the `SudoklifyArchitect` to construct Sudoku puzzles based on
the defined specifications.

The `generatedSudoku` instance contains the puzzle and solution strings, difficulty level, and grid
type. You can access these properties as follows:
```kotlin
val sudokuPuzzle1 = architect.constructSudoku(sudokuSpec)
val sudokuPuzzle2 = architect.constructSudoku {
seed = 2025L.toSeed()
}
```

4. **Process and Print the Puzzles**: Iterate through the generated puzzles and print their grids.

```kotlin
val puzzleBoard = sudoku.puzzle
val solutionBoard = sudoku.solution
val difficulty = sudoku.difficulty
val gameType = sudoku.gameType

// Print the properties
println("Puzzle Board: $puzzleBoard")
println("Solution Board: $solutionBoard")
println("Difficulty: $difficulty")
println("Grid Type: $gameType")
val puzzles = listOf(sudokuPuzzle1, sudokuPuzzle2)
puzzles.forEach { puzzle ->
println(puzzle.generateGridWithGivens().mapToSudokuString())
println(puzzle.generateGridWithGivens().mapToSudokuString().mapToSudokuBoard(puzzle.type))
}
```

## Kotlin Multiplatform Support
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ subprojects {
target("**/*.kt")
targetExclude(
"**/build/**/*.kt",
"**/test/**",
"**/seeds/**",
"**/dev/teogor/sudoklify/presets/**",
)

ktlint()
Expand Down
6 changes: 2 additions & 4 deletions demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ winds {
}

dependencies {
implementation(projects.sudoklifyCommon)
implementation(projects.sudoklifyCore)
implementation(projects.sudoklifyKtx)
implementation(projects.sudoklifySeeds)
implementation(projects.sudoklifyCommon)
implementation(projects.sudoklifyPresets)

implementation(libs.jetbrains.kotlin.stdlib)
implementation(libs.jetbrains.kotlinx.coroutines.core)
implementation(libs.google.gson)
}
44 changes: 41 additions & 3 deletions demo/src/main/kotlin/dev/teogor/sudoklify/demo/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,48 @@
* limitations under the License.
*/

@file:OptIn(ExperimentalSudoklifyApi::class)

package dev.teogor.sudoklify.demo

import kotlinx.coroutines.runBlocking
import dev.teogor.sudoklify.ExperimentalSudoklifyApi
import dev.teogor.sudoklify.SudoklifyArchitect
import dev.teogor.sudoklify.components.Difficulty
import dev.teogor.sudoklify.components.Dimension
import dev.teogor.sudoklify.components.toSeed
import dev.teogor.sudoklify.mapToSudokuBoard
import dev.teogor.sudoklify.mapToSudokuString
import dev.teogor.sudoklify.presets.loadPresetSchemas
import dev.teogor.sudoklify.puzzle.SudokuSpec
import dev.teogor.sudoklify.puzzle.generateGridWithGivens
import dev.teogor.sudoklify.schema.SudokuSchemas

fun main() {
val architect =
SudoklifyArchitect {
SudokuSchemas(loadPresetSchemas()) {
// TODO Optional: Add own schemas.
// addAll(*), add(*)
}
}

val sudokuSpec =
SudokuSpec {
seed = 2024L.toSeed()
type = Dimension.NineByNine
difficulty = Difficulty.EASY
}
val sudokuPuzzle1 = architect.constructSudoku(sudokuSpec)
val sudokuPuzzle2 =
architect.constructSudoku {
seed = 2025L.toSeed()
}

fun main() =
runBlocking {
val puzzles = listOf(sudokuPuzzle1, sudokuPuzzle2)
puzzles.forEach { puzzle ->
println(puzzle.generateGridWithGivens().mapToSudokuString())
println(
puzzle.generateGridWithGivens().mapToSudokuString().mapToSudokuBoard(puzzle.type),
)
}
}

This file was deleted.

Loading

0 comments on commit a8ab223

Please sign in to comment.