From 3b13c8e2486896218de8367a73587d25d0f7d28f Mon Sep 17 00:00:00 2001 From: meikpiep Date: Fri, 1 Nov 2024 10:55:21 +0100 Subject: [PATCH] wip debug solve --- .../ui/main/BottomAppBarItemClickListener.kt | 11 ++++++++++- .../piepmeyer/gauguin/ui/main/GameTopFragment.kt | 13 +++---------- gauguin-app/src/main/res/menu/bottom_app_bar.xml | 9 ++++++++- .../gauguin/difficulty/human/HumanSolver.kt | 11 +++++++++++ 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/gauguin-app/src/main/kotlin/org/piepmeyer/gauguin/ui/main/BottomAppBarItemClickListener.kt b/gauguin-app/src/main/kotlin/org/piepmeyer/gauguin/ui/main/BottomAppBarItemClickListener.kt index 33a9e9b5..db24e550 100644 --- a/gauguin-app/src/main/kotlin/org/piepmeyer/gauguin/ui/main/BottomAppBarItemClickListener.kt +++ b/gauguin-app/src/main/kotlin/org/piepmeyer/gauguin/ui/main/BottomAppBarItemClickListener.kt @@ -5,12 +5,14 @@ import androidx.appcompat.widget.Toolbar import org.koin.core.component.KoinComponent import org.koin.core.component.inject import org.piepmeyer.gauguin.R +import org.piepmeyer.gauguin.difficulty.human.HumanSolver import org.piepmeyer.gauguin.game.Game import org.piepmeyer.gauguin.game.GameSolveService class BottomAppBarItemClickListener( private val mainActivity: MainActivity, -) : Toolbar.OnMenuItemClickListener, KoinComponent { +) : Toolbar.OnMenuItemClickListener, + KoinComponent { private val game: Game by inject() private val gameSolveService: GameSolveService by inject() @@ -23,6 +25,13 @@ class BottomAppBarItemClickListener( R.id.menu_reveal_cell -> gameSolveService.revealSelectedCell() R.id.menu_reveal_cage -> gameSolveService.revealSelectedCage() R.id.menu_show_solution -> gameSolveService.solveGrid() + R.id.menu_debug_solve_by_human_solver -> { + val solver = HumanSolver(game.grid) + solver.prepareGrid() + solver.solveAndCalculateDifficulty() + + game.gridUI.invalidate() + } } return true diff --git a/gauguin-app/src/main/kotlin/org/piepmeyer/gauguin/ui/main/GameTopFragment.kt b/gauguin-app/src/main/kotlin/org/piepmeyer/gauguin/ui/main/GameTopFragment.kt index 76163169..e1310343 100644 --- a/gauguin-app/src/main/kotlin/org/piepmeyer/gauguin/ui/main/GameTopFragment.kt +++ b/gauguin-app/src/main/kotlin/org/piepmeyer/gauguin/ui/main/GameTopFragment.kt @@ -26,7 +26,6 @@ import org.piepmeyer.gauguin.game.GameLifecycle import org.piepmeyer.gauguin.game.PlayTimeListener import org.piepmeyer.gauguin.grid.Grid import org.piepmeyer.gauguin.grid.GridCage -import org.piepmeyer.gauguin.grid.GridCell import org.piepmeyer.gauguin.preferences.ApplicationPreferences import org.piepmeyer.gauguin.ui.difficulty.MainGameDifficultyLevelBalloon import org.piepmeyer.gauguin.ui.difficulty.MainGameDifficultyLevelFragment @@ -162,15 +161,9 @@ class GameTopFragment : grid.addCage(newCage) } - game.grid.cells.forEach { - val newCell = grid.getCell(it.cellNumber) - - newCell.possibles = grid.variant.possibleDigits - newCell.value = it.value - newCell.userValue = GridCell.NO_VALUE_SET - } - - val solverResult = HumanSolver(grid).solveAndCalculateDifficulty() + val solver = HumanSolver(grid) + solver.prepareGrid() + val solverResult = solver.solveAndCalculateDifficulty() var text = binding.difficulty.text as String + " (${solverResult.difficulty}" diff --git a/gauguin-app/src/main/res/menu/bottom_app_bar.xml b/gauguin-app/src/main/res/menu/bottom_app_bar.xml index 5e9a2716..9859e421 100644 --- a/gauguin-app/src/main/res/menu/bottom_app_bar.xml +++ b/gauguin-app/src/main/res/menu/bottom_app_bar.xml @@ -1,5 +1,6 @@ - + + \ No newline at end of file diff --git a/gauguin-core/src/main/kotlin/org/piepmeyer/gauguin/difficulty/human/HumanSolver.kt b/gauguin-core/src/main/kotlin/org/piepmeyer/gauguin/difficulty/human/HumanSolver.kt index 295ca01d..fd862716 100644 --- a/gauguin-core/src/main/kotlin/org/piepmeyer/gauguin/difficulty/human/HumanSolver.kt +++ b/gauguin-core/src/main/kotlin/org/piepmeyer/gauguin/difficulty/human/HumanSolver.kt @@ -2,6 +2,7 @@ package org.piepmeyer.gauguin.difficulty.human import io.github.oshai.kotlinlogging.KotlinLogging import org.piepmeyer.gauguin.grid.Grid +import org.piepmeyer.gauguin.grid.GridCell private val logger = KotlinLogging.logger {} @@ -55,4 +56,14 @@ class HumanSolver( return HumanSolverStep(false, 0) } + + fun prepareGrid() { + grid.cells.forEach { + val newCell = grid.getCell(it.cellNumber) + + newCell.possibles = grid.variant.possibleDigits + newCell.value = it.value + newCell.userValue = GridCell.NO_VALUE_SET + } + } }