Fix issue where solution is in perfect order
This commit is contained in:
@@ -110,7 +110,7 @@ class Game(
|
||||
return Game(
|
||||
grid = Grid(
|
||||
rows = options.values
|
||||
.map { createRow<ItemClass<*>>(it) }
|
||||
.map { createRow<ItemClass<*>>(it.sorted()) }
|
||||
.toList()
|
||||
),
|
||||
clues = clues
|
||||
|
||||
@@ -19,7 +19,7 @@ class GameCell<C : ItemClass<C>>(
|
||||
selectionChangedListeners.forEach { listener -> listener(value) }
|
||||
}
|
||||
}
|
||||
val options: ObservableSet<Item<C>> = ObservableSet(options.toMutableSet()) { before, after ->
|
||||
val options: ObservableSet<Item<C>> = ObservableSet(options) { before, after ->
|
||||
optionsChangedListeners.forEach { listener ->
|
||||
listener(after)
|
||||
}
|
||||
@@ -40,12 +40,13 @@ class GameCell<C : ItemClass<C>>(
|
||||
}
|
||||
}
|
||||
|
||||
fun <C : ItemClass<C>> GameCell<C>?.mayBe(item: Item<C>, mayHaveSelection: Boolean = true) =
|
||||
fun <C : ItemClass<C>> GameCell<C>?.mayBe(item: Item<C>, mayHaveSelection: Boolean = true): Boolean =
|
||||
this != null &&
|
||||
((mayHaveSelection && selection == item) || (selection == null && options.contains(item)))
|
||||
|
||||
fun <C : ItemClass<C>> GameCell<C>?.isA(item: Item<C>) =
|
||||
fun <C : ItemClass<C>> GameCell<C>?.isA(item: Item<C>): Boolean =
|
||||
this != null && selection == item
|
||||
|
||||
fun <C : ItemClass<C>> GameCell<C>?.hasNoSelection(): Boolean = this != null && this.selection == null
|
||||
fun <C : ItemClass<C>> GameCell<C>?.hasNoSelection(): Boolean =
|
||||
this != null && this.selection == null
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ fun List<List<Item<ItemClass<*>>>>.toGrid() = Grid(
|
||||
map { row ->
|
||||
GameRow(
|
||||
category = row.first().itemType.companion,
|
||||
options = row,
|
||||
options = row.sorted(),
|
||||
cells = row.map {
|
||||
GameCell(
|
||||
selection = null,
|
||||
|
||||
@@ -4,7 +4,7 @@ package ch.dissem.yaep.domain
|
||||
class Item<C : ItemClass<C>>(
|
||||
val itemType: C,
|
||||
val symbol: String = itemType.symbols.random()
|
||||
) {
|
||||
) : Comparable<Item<C>> {
|
||||
constructor(itemType: C) : this(itemType, itemType.symbols.random())
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
@@ -20,4 +20,6 @@ class Item<C : ItemClass<C>>(
|
||||
override fun toString(): String {
|
||||
return itemType.toString() + symbol
|
||||
}
|
||||
|
||||
override fun compareTo(other: Item<C>): Int = itemType.compareTo(other.itemType)
|
||||
}
|
||||
|
||||
@@ -138,6 +138,7 @@ enum class Transportation(symbol: String) : ItemClass<Transportation> {
|
||||
companion object : ItemClassCompanion<Transportation> {
|
||||
override val items: List<Transportation> = entries
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private val GENDERS = arrayOf("\uD83E\uDDD1", "\uD83D\uDC68", "\uD83D\uDC69")
|
||||
@@ -150,13 +151,17 @@ private fun idic(symbol: String): Array<String> = Array(GENDERS.size * SKIN_TONE
|
||||
g + t + symbol
|
||||
}
|
||||
|
||||
sealed interface ItemClass<out SELF : ItemClass<SELF>> {
|
||||
sealed interface ItemClass<out SELF : ItemClass<SELF>>: Comparable<ItemClass<*>> {
|
||||
val symbols: Array<String>
|
||||
|
||||
val name: String
|
||||
|
||||
val companion: ItemClassCompanion<SELF>
|
||||
|
||||
val ordinal: Int
|
||||
|
||||
override fun compareTo(other: ItemClass<*>): Int = ordinal.compareTo(other.ordinal)
|
||||
|
||||
companion object {
|
||||
val classes: List<ItemClassCompanion<*>> = listOf(
|
||||
Nationality,
|
||||
|
||||
Reference in New Issue
Block a user