Add and improve domain (WIP)

This commit is contained in:
2024-06-11 11:04:02 +02:00
parent 1b9c8633c9
commit f891dea885
11 changed files with 232 additions and 29 deletions

View File

@@ -0,0 +1,21 @@
package domain
class Game(
val categories: List<ItemCategory>,
val grid: Grid,
val horizontalRules: List<HorizontalRule>,
val verticalRules: List<VerticalRule>
) {
fun areCategoriesValid(): Boolean = categories.mapIndexed { index, category ->
category.any { item ->
categories.filterIndexed { i, _ -> i > index }.any { it.contains(item) }
}
}.none { it }
fun areRulesViolated(): Boolean = horizontalRules
.map { it.isRuleViolated(grid) }
.reduce { a, b -> a || b }
|| verticalRules
.map { it.isRuleViolated(grid) }
.reduce { a, b -> a || b }
}