diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/operations/Operation.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/operations/Operation.kt index d4c767f..d08c1b5 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/operations/Operation.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/operations/Operation.kt @@ -24,7 +24,10 @@ private val operations = listOf( SixGrowSeven, SevenGrowSix, FiveGrowNine, - NineGrowFive + NineGrowFive, + (1 .. 9).map { + GrowCustom(it.toByte()) + } ) suspend fun availableConverts(numbers: MutableList, operations: List): List { @@ -237,4 +240,22 @@ object NineGrowFive : Operation() { } } -class GrowCustom() +private class GrowCustom(private val number: Byte) : Operation() { + override suspend fun canConvert(numbers: MutableList, changesHistory: List): Boolean { + return changesHistory.canGrowSimpleWay + && changesHistory.firstOrNull { it is GrowCustom && it.number == number } == null + } + + override suspend fun canInvert(numbers: MutableList, changesHistory: List): Boolean { + return changesHistory.firstOrNull { it is GrowCustom && it.number == number } != null + && numbers.contains(number) + } + + override suspend fun doConvert(numbers: MutableList, changesHistory: MutableList?) { + numbers.add(number) + } + + override suspend fun doInvert(numbers: MutableList, changesHistory: MutableList?) { + numbers.remove(number) + } +}