Skip to content

Commit

Permalink
fix: generate cages for killer
Browse files Browse the repository at this point in the history
  • Loading branch information
kaajjo committed Jul 15, 2024
1 parent b49cbef commit 9b6c6b0
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions app/src/main/java/com/kaajjo/libresudoku/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.kaajjo.libresudoku.core.Cell
import com.kaajjo.libresudoku.core.PreferencesConstants
import com.kaajjo.libresudoku.core.qqwing.Cage
import com.kaajjo.libresudoku.core.qqwing.CageGenerator
import com.kaajjo.libresudoku.core.qqwing.GameDifficulty
import com.kaajjo.libresudoku.core.qqwing.GameType
Expand Down Expand Up @@ -124,8 +125,16 @@ class HomeViewModel
}
}

val generator = CageGenerator(solvedPuzzle, gameTypeToGenerate)
val cages = generator.generate(2, 5)
var cages: List<Cage>? = null
if (gameTypeToGenerate in setOf(
GameType.Killer9x9,
GameType.Killer12x12,
GameType.Killer6x6
)
) {
val generator = CageGenerator(solvedPuzzle, gameTypeToGenerate)
cages = generator.generate(2, 5)
}
withContext(Dispatchers.IO) {
val sudokuParser = SudokuParser()
insertedBoardUid = boardRepository.insert(
Expand All @@ -135,7 +144,9 @@ class HomeViewModel
solvedBoard = sudokuParser.boardToString(solvedPuzzle),
difficulty = selectedDifficulty,
type = selectedType,
killerCages = SudokuParser().killerSudokuCagesToString(cages)
killerCages = if (cages != null) sudokuParser.killerSudokuCagesToString(
cages
) else null
)
)
}
Expand Down

0 comments on commit 9b6c6b0

Please sign in to comment.