Fix tests & clues (WIP)
This commit is contained in:
@@ -57,11 +57,11 @@ class OrderClue<L : ItemClass<L>, R : ItemClass<R>>(val left: Item<L>, val right
|
||||
if (iLeft != -1) {
|
||||
if (iRight != -1) return iRight <= iLeft
|
||||
|
||||
return rowRight.indexOfLast { it.mayBe(right) } > iLeft
|
||||
return rowRight.indexOfLast { it.mayBe(right) } in 0..iLeft
|
||||
}
|
||||
|
||||
if (iRight != -1) {
|
||||
return rowLeft.indexOfFirst { it.mayBe(left) } in 0 until iRight
|
||||
return rowLeft.indexOfFirst { it.mayBe(left) } >= iRight
|
||||
}
|
||||
|
||||
return rowLeft.indexOfFirst { it.mayBe(left) } >= rowRight.indexOfLast { it.mayBe(right) }
|
||||
@@ -79,7 +79,7 @@ class TripletClue<A : ItemClass<A>, B : ItemClass<B>, C : ItemClass<C>>(
|
||||
private val cType = c.itemType
|
||||
|
||||
override fun isRuleViolated(grid: Grid): Boolean {
|
||||
val rowA by lazy { grid[aType.companion] }
|
||||
val rowA = grid[aType.companion]
|
||||
val rowB by lazy { grid[bType.companion] }
|
||||
val rowC by lazy { grid[cType.companion] }
|
||||
|
||||
@@ -178,7 +178,7 @@ class SameColumnClue<A : ItemClass<A>, B : ItemClass<B>>(val a: Item<A>, val b:
|
||||
}
|
||||
|
||||
for (i in 0 until grid.size) {
|
||||
if (!rowA[i].mayBe(a) && !rowB[i].mayBe(b)) {
|
||||
if (rowA[i].mayBe(a) && rowB[i].mayBe(b)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ fun generateGame(size: Int = 6): Game {
|
||||
// (You can speed this up by removing clues in batches rather than one at a time, but it makes the algorithm more complicated to describe.)
|
||||
}
|
||||
|
||||
// FIXME: I need to better include the options into the solver (rule violations checks)
|
||||
private fun solve(
|
||||
grid: Grid,
|
||||
clues: Collection<Clue>
|
||||
@@ -124,8 +123,8 @@ private fun getAllClues(rows: List<List<Item<ItemClass<*>>>>): MutableSet<Clue>
|
||||
// }
|
||||
// }
|
||||
|
||||
rows.forEach { columns ->
|
||||
columns.forEachIndexed { j, item ->
|
||||
rows.forEach { row ->
|
||||
row.forEachIndexed { j, item ->
|
||||
// Clue: Neighbours
|
||||
if (j > 0) {
|
||||
rows.map { it[j - 1] }.forEach {
|
||||
@@ -141,7 +140,7 @@ private fun getAllClues(rows: List<List<Item<ItemClass<*>>>>): MutableSet<Clue>
|
||||
|
||||
// Clue: Order
|
||||
if (j > 0) {
|
||||
rows.flatMap { it.take(j - 1) }.forEach {
|
||||
rows.flatMap { it.take(j) }.forEach {
|
||||
clues.add(OrderClue(it, item))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user