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 (iLeft != -1) {
|
||||||
if (iRight != -1) return iRight <= iLeft
|
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) {
|
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) }
|
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
|
private val cType = c.itemType
|
||||||
|
|
||||||
override fun isRuleViolated(grid: Grid): Boolean {
|
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 rowB by lazy { grid[bType.companion] }
|
||||||
val rowC by lazy { grid[cType.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) {
|
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
|
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.)
|
// (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(
|
private fun solve(
|
||||||
grid: Grid,
|
grid: Grid,
|
||||||
clues: Collection<Clue>
|
clues: Collection<Clue>
|
||||||
@@ -124,8 +123,8 @@ private fun getAllClues(rows: List<List<Item<ItemClass<*>>>>): MutableSet<Clue>
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
rows.forEach { columns ->
|
rows.forEach { row ->
|
||||||
columns.forEachIndexed { j, item ->
|
row.forEachIndexed { j, item ->
|
||||||
// Clue: Neighbours
|
// Clue: Neighbours
|
||||||
if (j > 0) {
|
if (j > 0) {
|
||||||
rows.map { it[j - 1] }.forEach {
|
rows.map { it[j - 1] }.forEach {
|
||||||
@@ -141,7 +140,7 @@ private fun getAllClues(rows: List<List<Item<ItemClass<*>>>>): MutableSet<Clue>
|
|||||||
|
|
||||||
// Clue: Order
|
// Clue: Order
|
||||||
if (j > 0) {
|
if (j > 0) {
|
||||||
rows.flatMap { it.take(j - 1) }.forEach {
|
rows.flatMap { it.take(j) }.forEach {
|
||||||
clues.add(OrderClue(it, item))
|
clues.add(OrderClue(it, item))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user