Add minor improvements
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
alias(libs.plugins.androidApplication)
|
||||
alias(libs.plugins.jetbrainsKotlinCompose)
|
||||
alias(libs.plugins.jetbrainsCompose)
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
alias(libs.plugins.compose)
|
||||
}
|
||||
|
||||
android {
|
||||
|
||||
@@ -4,9 +4,10 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
|
||||
plugins {
|
||||
// this is necessary to avoid the plugins to be loaded multiple times
|
||||
// in each subproject's classloader
|
||||
alias(libs.plugins.androidApplication) apply false
|
||||
alias(libs.plugins.androidLibrary) apply false
|
||||
alias(libs.plugins.jetbrainsCompose) apply false
|
||||
alias(libs.plugins.android.application) apply false
|
||||
alias(libs.plugins.android.library) apply false
|
||||
alias(libs.plugins.compose) apply false
|
||||
alias(libs.plugins.kotlin.compose) apply false
|
||||
alias(libs.plugins.kotlin.multiplatform) apply false
|
||||
alias(libs.plugins.kotlin.jvm) apply false
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
alias(libs.plugins.kotlin.jvm)
|
||||
alias(libs.plugins.jetbrainsKotlinCompose)
|
||||
alias(libs.plugins.jetbrainsCompose)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
alias(libs.plugins.compose)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
||||
@@ -2,8 +2,8 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.kotlin.jvm)
|
||||
alias(libs.plugins.jetbrainsKotlinCompose)
|
||||
alias(libs.plugins.jetbrainsCompose)
|
||||
alias(libs.plugins.kotlin.compose)
|
||||
alias(libs.plugins.compose)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
|
||||
@@ -41,6 +41,8 @@ class NeighbourClue<A : ItemClass<A>, B : ItemClass<B>>(val a: Item<A>, val b: I
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun toString() = "$aType is next to $bType"
|
||||
}
|
||||
|
||||
class OrderClue<L : ItemClass<L>, R : ItemClass<R>>(val left: Item<L>, val right: Item<R>) :
|
||||
@@ -66,6 +68,8 @@ class OrderClue<L : ItemClass<L>, R : ItemClass<R>>(val left: Item<L>, val right
|
||||
|
||||
return rowLeft.indexOfFirst { it.mayBe(left) } >= rowRight.indexOfLast { it.mayBe(right) }
|
||||
}
|
||||
|
||||
override fun toString() = "$leftType is left of $rightType"
|
||||
}
|
||||
|
||||
class TripletClue<A : ItemClass<A>, B : ItemClass<B>, C : ItemClass<C>>(
|
||||
@@ -152,6 +156,9 @@ class TripletClue<A : ItemClass<A>, B : ItemClass<B>, C : ItemClass<C>>(
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun toString(): String =
|
||||
"$bType is between the neighbours $aType and $cType to both sides"
|
||||
}
|
||||
|
||||
class SameColumnClue<A : ItemClass<A>, B : ItemClass<B>>(val a: Item<A>, val b: Item<B>) : Clue() {
|
||||
@@ -184,13 +191,19 @@ class SameColumnClue<A : ItemClass<A>, B : ItemClass<B>>(val a: Item<A>, val b:
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun toString(): String = "$aType and $bType are in the same column"
|
||||
}
|
||||
|
||||
class PositionClue<C : ItemClass<C>>(val item: Item<C>, val index: Int) : Clue() {
|
||||
val itemType = item.itemType
|
||||
|
||||
override fun isRuleViolated(grid: Grid): Boolean {
|
||||
val i = grid.indexOf(item.itemType)
|
||||
if (i != -1) return i != index
|
||||
|
||||
return grid[item].mayBe(item)
|
||||
}
|
||||
|
||||
override fun toString() = "$itemType is at position $index"
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ fun generateGame(size: Int = 6): Game {
|
||||
// (There are a finite and in fact quite small number of possible clues: for example
|
||||
// if there are 5 houses, there are 5 possible clues of the form "Person A lives in
|
||||
// house B", 8 possible clues of the form "Person A lives next to house B", and so on.)
|
||||
var clues = getAllClues(grid).toList() //.shuffled()
|
||||
var clues = getAllClues(grid).sortedBy { it.toString() } //.shuffled()
|
||||
|
||||
var i = 0
|
||||
|
||||
@@ -47,9 +47,9 @@ private fun solve(
|
||||
|
||||
// First, set the positions of the items that are already known.
|
||||
clues.filterIsInstance<PositionClue<ItemClass<*>>>().forEach { position ->
|
||||
val row = grid[position.item.itemType.companion]
|
||||
val row = grid[position.itemType.companion]
|
||||
val cell = row[position.index]
|
||||
cell.options.retainAll { it == cell.selection }
|
||||
cell.options.retainAll { it == position.item }
|
||||
row.cleanupOptions(cell)
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ android-compileSdk = "34"
|
||||
android-minSdk = "24"
|
||||
android-targetSdk = "34"
|
||||
androidx-activityCompose = "1.9.0"
|
||||
compose = "1.6.8"
|
||||
compose-plugin = "1.6.11"
|
||||
kotlin = "2.0.0"
|
||||
|
||||
@@ -14,9 +13,9 @@ kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotl
|
||||
atrium = { module = "ch.tutteli.atrium:atrium-fluent", version = "1.2.0" }
|
||||
|
||||
[plugins]
|
||||
androidApplication = { id = "com.android.application", version.ref = "agp" }
|
||||
androidLibrary = { id = "com.android.library", version.ref = "agp" }
|
||||
jetbrainsKotlinCompose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
android-library = { id = "com.android.library", version.ref = "agp" }
|
||||
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||
compose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
|
||||
|
||||
Reference in New Issue
Block a user