package domain import androidx.compose.ui.util.fastAny class Game( val grid: Grid, val clues: List ) { val horizontalClues = clues.filterIsInstance() val verticalClues = clues.filterIsInstance>>() val positionalClues = clues.filterIsInstance>>() init { for (position in positionalClues) { val row = grid[position.item.itemType.companion] row.forEachIndexed { index, gameCell -> if (index == position.index) { gameCell.selection = position.item } else { gameCell.options.remove(position.item) } } } } fun areCategoriesValid(): Boolean { val usedCategories = mutableSetOf>() for (row in grid.rows) { if (usedCategories.contains(row.category)) { return false } usedCategories.add(row.category) } return true } fun areRulesViolated(): Boolean = clues .any { it.isRuleViolated(grid) } }