-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip PossibleMustBeContainedInSingleCageInLineDeleteFromOtherCages
- Loading branch information
Showing
8 changed files
with
123 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...pmeyer/gauguin/difficulty/human/strategy/NumberOfCagesWithPossibleForcesPossibleInCage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.piepmeyer.gauguin.difficulty.human.strategy | ||
|
||
import org.piepmeyer.gauguin.difficulty.human.HumanSolverStrategy | ||
import org.piepmeyer.gauguin.difficulty.human.PossiblesCache | ||
import org.piepmeyer.gauguin.difficulty.human.PossiblesReducer | ||
import org.piepmeyer.gauguin.grid.Grid | ||
|
||
class NumberOfCagesWithPossibleForcesPossibleInCage : HumanSolverStrategy { | ||
override fun fillCells( | ||
grid: Grid, | ||
cache: PossiblesCache, | ||
): Boolean { | ||
grid.variant.possibleDigits.forEach { possible -> | ||
val numberOfPossiblesLeft = grid.variant.gridSize.smallestSide() - grid.cells.count { it.userValue == possible } | ||
|
||
val cagesWithPossible = | ||
grid.cages | ||
.filter { it.cells.any { !it.isUserValueSet } } | ||
.filter { it.cells.any { it.possibles.contains(possible) } } | ||
|
||
val cagesWithStaticNumberOfPossible = | ||
cagesWithPossible.filter { | ||
val firstAmountOfPossible = | ||
cache | ||
.calculatePossibles(it) | ||
.first() | ||
.filterIndexed { index, _ -> !it.cells[index].isUserValueSet } | ||
.count { it == possible } | ||
|
||
cache.calculatePossibles(it).all { it.count { it == possible } == firstAmountOfPossible } | ||
} | ||
|
||
val staticNumberOfPossibles = | ||
cagesWithStaticNumberOfPossible.sumOf { | ||
cache | ||
.calculatePossibles(it) | ||
.first() | ||
.filterIndexed { index, _ -> !it.cells[index].isUserValueSet } | ||
.count { it == possible } | ||
} | ||
|
||
val cagesWithDynamicNumberOfPossible = cagesWithPossible - cagesWithStaticNumberOfPossible | ||
|
||
if (staticNumberOfPossibles == numberOfPossiblesLeft) { | ||
/* | ||
* All possibles are already contained in the static cages, so we delete | ||
* the possible from all other cages. | ||
*/ | ||
cagesWithDynamicNumberOfPossible.forEach { dynamicCage -> | ||
val reduced = | ||
PossiblesReducer(dynamicCage).reduceToPossibleCombinations( | ||
cache | ||
.calculatePossibles(dynamicCage) | ||
.filter { | ||
it | ||
.filterIndexed { index, value -> | ||
!dynamicCage.cells[index].isUserValueSet && value == possible | ||
}.isEmpty() | ||
}, | ||
) | ||
|
||
if (reduced) { | ||
return true | ||
} | ||
} | ||
} else if (cagesWithDynamicNumberOfPossible.size == 1 && staticNumberOfPossibles == numberOfPossiblesLeft - 1) { | ||
val dynamicCage = cagesWithDynamicNumberOfPossible.first() | ||
|
||
val reduced = | ||
PossiblesReducer(dynamicCage).reduceToPossibleCombinations( | ||
cache | ||
.calculatePossibles(dynamicCage) | ||
.filter { | ||
it | ||
.filterIndexed { index, _ -> !dynamicCage.cells[index].isUserValueSet } | ||
.count { it == possible } == 1 | ||
}, | ||
) | ||
|
||
if (reduced) { | ||
return true | ||
} | ||
} | ||
} | ||
|
||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
.../kotlin/org/piepmeyer/gauguin/difficulty/human/strategy/TwoCellsPossiblesSumThreeLines.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.piepmeyer.gauguin.difficulty.human.strategy | ||
|
||
/** | ||
* Scans three lines to find that each part of cage contained in this lines has a static sum | ||
* excluding one part of cage. The sum of this part of cages is calculated all enforced by deleting | ||
* deviant possibles. | ||
*/ | ||
class TwoCellsPossiblesSumThreeLines : AbstractTwoCellsPossiblesSum(3) |
8 changes: 8 additions & 0 deletions
8
...in/kotlin/org/piepmeyer/gauguin/difficulty/human/strategy/TwoCellsPossiblesSumTwoLines.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.piepmeyer.gauguin.difficulty.human.strategy | ||
|
||
/** | ||
* Scans two lines to find that each part of cage contained in this lines has a static sum | ||
* excluding one part of cage. The sum of this part of cages is calculated all enforced by deleting | ||
* deviant possibles. | ||
*/ | ||
class TwoCellsPossiblesSumTwoLines : AbstractTwoCellsPossiblesSum(2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters