Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
meikpiep committed Nov 21, 2024
1 parent 0987ac6 commit 3f8167e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.piepmeyer.gauguin.difficulty.human.strategy

import org.piepmeyer.gauguin.difficulty.human.GridLineType
import org.piepmeyer.gauguin.difficulty.human.GridLines
import org.piepmeyer.gauguin.difficulty.human.HumanSolverStrategy
import org.piepmeyer.gauguin.difficulty.human.PossiblesCache
Expand All @@ -17,34 +18,47 @@ class DetectPossibleUsedInLinesByOtherCagesDualLines : HumanSolverStrategy {
val cellsOfLines =
dualLines.map { it.cells() }.flatten()

val cagesContainedInBothLines =
val cagesIntersectingWithLines =
dualLines
.asSequence()
.map { it.cages() }
.flatten()
.filter { it.cells.all { it.isUserValueSet || cellsOfLines.contains(it) } }
.filter { it.cells.any { !it.isUserValueSet } }
.filter { it.cells.any { !it.isUserValueSet && cellsOfLines.contains(it) } }
.toSet()

cagesContainedInBothLines.forEach { cage ->
val possiblesForFirstCage =
val possiblesInLines =
cagesIntersectingWithLines.associateWith { cage ->
cache
.possibles(cage)
.map { it.filterIndexed { index, _ -> dualLines.any { it.contains(cage.getCell(index)) } } }
.map {
it.filterIndexed {
index,
_,
->
!cage.cells[index].isUserValueSet && cellsOfLines.contains(cage.cells[index])
}
}.toSet()
}

if (dualLines.all { it.type == GridLineType.ROW } && dualLines.all { it.lineNumber == 6 || it.lineNumber == 7 }) {
println("hau!")
}

cagesIntersectingWithLines.forEach { cage ->
val possiblesForFirstCage = possiblesInLines[cage]!!

val possibleInEachFirstCageCombination =
grid.variant.possibleDigits.filter { possible ->
possiblesForFirstCage.all { it.contains(possible) }
}

if (possibleInEachFirstCageCombination.isNotEmpty()) {
cagesContainedInBothLines
cagesIntersectingWithLines
.filter { it.id > cage.id }
.forEach { otherCage ->
val possiblesForOtherCage =
cache
.possibles(otherCage)
.map { it.filterIndexed { index, _ -> dualLines.any { it.contains(otherCage.getCell(index)) } } }
if (cage.id == 3 && otherCage.id == 15) {
println("Hau2")
}
val possiblesForOtherCage = possiblesInLines[otherCage]!!

val possibleInEachOtherCageCombination =
grid.variant.possibleDigits.filter { possible ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class HumanDifficultySolverTest :
// 10_000 of 4x4, merge: 19 left unsolved
// 10_000 of 5x5, merge: 134 left unsolved
// 10_000 of 2x4, merge: no (!) left unsolved
// 1_000 of 3x6, merge: 120 left unsolved
// 1_000 of 3x6, merge: 119 left unsolved
// 100 of 9x9, merge: 51 left unsolved
withClue("seed $seed") {
test("seed random grid should be solved") {
Expand Down

0 comments on commit 3f8167e

Please sign in to comment.