Add Clue.removeForbiddenOptions
This commit is contained in:
@@ -10,5 +10,6 @@ class GameCell<C : ItemClass<C>>(
|
|||||||
// var selection by mutableStateOf(selection)
|
// var selection by mutableStateOf(selection)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
fun <C : ItemClass<C>> GameCell<C>?.mayBe(item: Item<C>) =
|
fun <C : ItemClass<C>> GameCell<C>?.mayBe(item: Item<C>, mayHaveSelection: Boolean = true) =
|
||||||
this != null && (selection == item || (selection == null && options.contains(item)))
|
this != null &&
|
||||||
|
((mayHaveSelection && selection == item) || (selection == null && options.contains(item)))
|
||||||
|
|||||||
@@ -114,9 +114,9 @@ class OrderClue<L : ItemClass<L>, R : ItemClass<R>>(val left: Item<L>, val right
|
|||||||
|
|
||||||
var removed = false
|
var removed = false
|
||||||
try {
|
try {
|
||||||
rowL.takeLast(rowL.size - lastR + 1)
|
rowL.takeLast(rowL.size - lastR)
|
||||||
.forEach { removed = it.options.remove(left) || removed }
|
.forEach { removed = it.options.remove(left) || removed }
|
||||||
rowR.take(firstL).forEach { removed = it.options.remove(right) || removed }
|
rowR.take(firstL + 1).forEach { removed = it.options.remove(right) || removed }
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
throw UnsolvablePuzzleException(e)
|
throw UnsolvablePuzzleException(e)
|
||||||
}
|
}
|
||||||
@@ -216,7 +216,54 @@ class TripletClue<A : ItemClass<A>, B : ItemClass<B>, C : ItemClass<C>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun removeForbiddenOptions(grid: Grid): Boolean {
|
override fun removeForbiddenOptions(grid: Grid): Boolean {
|
||||||
TODO("Not yet implemented")
|
val rowA = grid[aType.companion]
|
||||||
|
val rowB = grid[bType.companion]
|
||||||
|
val rowC = grid[cType.companion]
|
||||||
|
|
||||||
|
var removed = false
|
||||||
|
|
||||||
|
for (i in rowA.indices) {
|
||||||
|
val cellA = rowA[i]
|
||||||
|
if (cellA.mayBe(a, mayHaveSelection = false)) {
|
||||||
|
val cellBR = rowB.getOrNull(i + 1)
|
||||||
|
val cellCR = rowC.getOrNull(i + 2)
|
||||||
|
val cellBL = rowB.getOrNull(i - 1)
|
||||||
|
val cellCL = rowC.getOrNull(i - 2)
|
||||||
|
|
||||||
|
if (!(cellBR.mayBe(b) && cellCR.mayBe(c)) && !(cellBL.mayBe(b) && cellCL.mayBe(c))) {
|
||||||
|
removed = cellA.options.remove(a) || removed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i in rowB.indices) {
|
||||||
|
val cellB = rowB[i]
|
||||||
|
if (cellB.mayBe(b, mayHaveSelection = false)) {
|
||||||
|
val cellAL = rowA.getOrNull(i - 1)
|
||||||
|
val cellAR = rowA.getOrNull(i + 1)
|
||||||
|
val cellCL = rowC.getOrNull(i - 1)
|
||||||
|
val cellCR = rowC.getOrNull(i + 1)
|
||||||
|
|
||||||
|
if (!(cellAL.mayBe(a) && cellCR.mayBe(c)) && !(cellCL.mayBe(c) && cellAR.mayBe(a))) {
|
||||||
|
removed = cellB.options.remove(b) || removed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i in rowC.indices) {
|
||||||
|
val cellC = rowC[i]
|
||||||
|
if (cellC.mayBe(c, mayHaveSelection = false)) {
|
||||||
|
val cellBR = rowB.getOrNull(i + 1)
|
||||||
|
val cellAR = rowA.getOrNull(i + 2)
|
||||||
|
val cellBL = rowB.getOrNull(i - 1)
|
||||||
|
val cellAL = rowA.getOrNull(i - 2)
|
||||||
|
|
||||||
|
if (!(cellBR.mayBe(b) && cellAR.mayBe(a)) && !(cellBL.mayBe(b) && cellAL.mayBe(a))) {
|
||||||
|
removed = cellC.options.remove(c) || removed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return removed
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String =
|
override fun toString(): String =
|
||||||
|
|||||||
Reference in New Issue
Block a user