Skip to content

Commit

Permalink
wip debug solve
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Nov 1, 2024
1 parent 894336c commit 3b13c8e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"

Expand Down
9 changes: 8 additions & 1 deletion gauguin-app/src/main/res/menu/bottom_app_bar.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
Expand Down Expand Up @@ -35,4 +36,10 @@
android:title="@string/main_activity_application_bar_item_reveal_all_cells"
app:showAsAction="never" />

<item
android:id="@+id/menu_debug_solve_by_human_solver"
android:title="Solve via human solver"
app:showAsAction="never"
tools:ignore="HardcodedText" />

</menu>
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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
}
}
}

0 comments on commit 3b13c8e

Please sign in to comment.