Add minor improvements

This commit is contained in:
2024-07-02 23:11:53 +02:00
parent d33d80e875
commit 5b97b789a5
7 changed files with 32 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
plugins { plugins {
alias(libs.plugins.androidApplication) alias(libs.plugins.android.application)
alias(libs.plugins.jetbrainsKotlinCompose) alias(libs.plugins.kotlin.compose)
alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.compose)
} }
android { android {

View File

@@ -4,9 +4,10 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
plugins { plugins {
// this is necessary to avoid the plugins to be loaded multiple times // this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader // in each subproject's classloader
alias(libs.plugins.androidApplication) apply false alias(libs.plugins.android.application) apply false
alias(libs.plugins.androidLibrary) apply false alias(libs.plugins.android.library) apply false
alias(libs.plugins.jetbrainsCompose) 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.multiplatform) apply false
alias(libs.plugins.kotlin.jvm) apply false alias(libs.plugins.kotlin.jvm) apply false
} }

View File

@@ -1,7 +1,7 @@
plugins { plugins {
alias(libs.plugins.kotlin.jvm) alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.jetbrainsKotlinCompose) alias(libs.plugins.kotlin.compose)
alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.compose)
} }
kotlin { kotlin {

View File

@@ -2,8 +2,8 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat
plugins { plugins {
alias(libs.plugins.kotlin.jvm) alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.jetbrainsKotlinCompose) alias(libs.plugins.kotlin.compose)
alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.compose)
} }
kotlin { kotlin {

View File

@@ -41,6 +41,8 @@ class NeighbourClue<A : ItemClass<A>, B : ItemClass<B>>(val a: Item<A>, val b: I
} }
return true 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>) : 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) } 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>>( 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 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() { 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 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() { class PositionClue<C : ItemClass<C>>(val item: Item<C>, val index: Int) : Clue() {
val itemType = item.itemType
override fun isRuleViolated(grid: Grid): Boolean { override fun isRuleViolated(grid: Grid): Boolean {
val i = grid.indexOf(item.itemType) val i = grid.indexOf(item.itemType)
if (i != -1) return i != index if (i != -1) return i != index
return grid[item].mayBe(item) return grid[item].mayBe(item)
} }
override fun toString() = "$itemType is at position $index"
} }

View File

@@ -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 // (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 // 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.) // 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 var i = 0
@@ -47,9 +47,9 @@ private fun solve(
// First, set the positions of the items that are already known. // First, set the positions of the items that are already known.
clues.filterIsInstance<PositionClue<ItemClass<*>>>().forEach { position -> clues.filterIsInstance<PositionClue<ItemClass<*>>>().forEach { position ->
val row = grid[position.item.itemType.companion] val row = grid[position.itemType.companion]
val cell = row[position.index] val cell = row[position.index]
cell.options.retainAll { it == cell.selection } cell.options.retainAll { it == position.item }
row.cleanupOptions(cell) row.cleanupOptions(cell)
} }

View File

@@ -4,7 +4,6 @@ android-compileSdk = "34"
android-minSdk = "24" android-minSdk = "24"
android-targetSdk = "34" android-targetSdk = "34"
androidx-activityCompose = "1.9.0" androidx-activityCompose = "1.9.0"
compose = "1.6.8"
compose-plugin = "1.6.11" compose-plugin = "1.6.11"
kotlin = "2.0.0" 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" } atrium = { module = "ch.tutteli.atrium:atrium-fluent", version = "1.2.0" }
[plugins] [plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" } android-application = { id = "com.android.application", version.ref = "agp" }
androidLibrary = { id = "com.android.library", version.ref = "agp" } android-library = { 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" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", 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" }