From a648d5e9291c9551aac0312c181a87d25d44a2a4 Mon Sep 17 00:00:00 2001 From: Teodor Grigor Date: Sat, 2 Mar 2024 13:20:58 +0200 Subject: [PATCH] Address Misuse of Deprecated Functions in createPuzzle() for Compatibility --- .../core/generation/SudokuGenerator.kt | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/sudoklify-core/src/main/kotlin/dev/teogor/sudoklify/core/generation/SudokuGenerator.kt b/sudoklify-core/src/main/kotlin/dev/teogor/sudoklify/core/generation/SudokuGenerator.kt index d46872a..9b7f17a 100644 --- a/sudoklify-core/src/main/kotlin/dev/teogor/sudoklify/core/generation/SudokuGenerator.kt +++ b/sudoklify-core/src/main/kotlin/dev/teogor/sudoklify/core/generation/SudokuGenerator.kt @@ -30,8 +30,6 @@ import dev.teogor.sudoklify.core.util.sortRandom import dev.teogor.sudoklify.core.util.toBoard import dev.teogor.sudoklify.core.util.toSequenceString import dev.teogor.sudoklify.ktx.createSeed -import dev.teogor.sudoklify.ktx.mapIndexedToSudokuBoard -import dev.teogor.sudoklify.ktx.mapToSudokuBoard import dev.teogor.sudoklify.ktx.toJEncodedCell import kotlin.math.sqrt import kotlin.random.Random @@ -102,17 +100,27 @@ class SudokuGenerator internal constructor( sudokuType = seed.sudokuType, seed = this.seed, givens = - puzzle.toSequenceString() - .mapIndexedToSudokuBoard(seed.sudokuType) { value, row, col -> - SudokuPuzzle.Givens( - value = value, - row = row, - col = col, - ) - }.flatten().filter { it.value != 0 }, + puzzle + .map { it.toList() } + .mapIndexed { row, cols -> + cols.mapIndexed { col, value -> + SudokuPuzzle.Givens( + value = value.toIntOrNull() ?: 0, + row = row, + col = col, + ) + } + } + .flatten() + .filter { it.value != 0 }, solution = - solution.toSequenceString() - .mapToSudokuBoard(seed.sudokuType), + solution + .map { it.toList() } + .map { cols -> + cols.map { value -> + value.toIntOrNull() ?: 0 + } + }, ) }