From 4e7580bb5737ebb70f08b54b181b037cdf2675d1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 6 Sep 2018 13:15:16 +0800 Subject: [PATCH] fix of --- .../domain/entities/Psychomatrix.kt | 66 ++++++++++++++----- .../domain/entities/PsychomatrixCeilInfo.kt | 33 ++++++++++ 2 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/PsychomatrixCeilInfo.kt diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt index ae1ca20..76f73df 100644 --- a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/Psychomatrix.kt @@ -10,33 +10,67 @@ private fun Int.toDigits(): List { return "$this".map { "$it".toByte() } } -val UPPER_DIAG_MATRIX_INDEX = 0 to 3 -val DOWN_DIAG_MATRIX_INDEX = 4 to 3 +val UPPER_DIAG_MATRIX_INDEX = 3 to 0 +val DOWN_DIAG_MATRIX_INDEX = 3 to 4 -val FIRST_ROW_SUM_MATRIX_INDEX = 1 to 3 -val SECOND_ROW_SUM_MATRIX_INDEX = 2 to 3 +val FIRST_ROW_SUM_MATRIX_INDEX = 3 to 1 +val SECOND_ROW_SUM_MATRIX_INDEX = 3 to 2 val THIRD_ROW_SUM_MATRIX_INDEX = 3 to 3 -val FIRST_COLUMN_SUM_MATRIX_INDEX = 3 to 1 -val SECOND_COLUMN_SUM_MATRIX_INDEX = 3 to 2 -val THIRD_COLUMN_SUM_MATRIX_INDEX = 3 to 3 +val FIRST_COLUMN_SUM_MATRIX_INDEX = 0 to 4 +val SECOND_COLUMN_SUM_MATRIX_INDEX = 1 to 4 +val THIRD_COLUMN_SUM_MATRIX_INDEX = 2 to 4 -val EMPTY_CEILS_OF_MATRIX = (0 until 3).map { 0 to it } +val EMPTY_CEILS_OF_MATRIX = (0 until 3).map { it to 0 } open class Psychomatrix(val date: DateTime) { protected open val numbers: ByteArray = ByteArray(10) /** - * Always array 4*5 of values. In rows was put columns ( + * Always array 4*5 of values. In rows was put columns + * */ - val asMatrix: Array> + val asMatrix: Array> get() = arrayOf( - arrayOf(-1, -1, -1, getUpperDiagSum()), - arrayOf(numbers[1], numbers[4], numbers[7], getRowSum(0)), - arrayOf(numbers[2], numbers[5], numbers[8], getRowSum(1)), - arrayOf(numbers[3], numbers[6], numbers[9], getRowSum(2)), - arrayOf(getColumnSum(0), getColumnSum(1), getColumnSum(2), getDownDiagSum()) - ) + arrayOf( + null, + numbers[0], + numbers[1], + numbers[2], + getColumnSum(0) + ), + arrayOf( + null, + numbers[3], + numbers[4], + numbers[5], + getColumnSum(1) + ), + arrayOf( + null, + numbers[6], + numbers[7], + numbers[8], + getColumnSum(2) + ), + arrayOf( + getUpperDiagSum(), + getRowSum(0), + getRowSum(1), + getRowSum(2), + getDownDiagSum() + ) + ).mapIndexed { + x, yArray -> + yArray.mapIndexed { + y, value -> + PsychomatrixCeilInfo( + x, + y, + value ?.toInt() + ) + }.toTypedArray() + }.toTypedArray() init { val dateDigits = dateFormat.print(date).map { "$it".toByte() }.toMutableList() diff --git a/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/PsychomatrixCeilInfo.kt b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/PsychomatrixCeilInfo.kt new file mode 100644 index 0000000..ca10fa7 --- /dev/null +++ b/src/main/kotlin/com/github/insanusmokrassar/PsychomatrixBase/domain/entities/PsychomatrixCeilInfo.kt @@ -0,0 +1,33 @@ +package com.github.insanusmokrassar.PsychomatrixBase.domain.entities + +data class PsychomatrixCeilInfo( + val x: Int, + val y: Int, + val count: Int? +) { + val ceilCoordsAsPair = x to y + val isUpperDiag = ceilCoordsAsPair == UPPER_DIAG_MATRIX_INDEX + val isDownDiag = ceilCoordsAsPair == DOWN_DIAG_MATRIX_INDEX + + val isFirstRowSum = ceilCoordsAsPair == FIRST_ROW_SUM_MATRIX_INDEX + val isSecondRowSum = ceilCoordsAsPair == SECOND_ROW_SUM_MATRIX_INDEX + val isThirdRowSum = ceilCoordsAsPair == THIRD_ROW_SUM_MATRIX_INDEX + + val isFirstColumnSum = ceilCoordsAsPair == FIRST_COLUMN_SUM_MATRIX_INDEX + val isSecondColumnSum = ceilCoordsAsPair == SECOND_COLUMN_SUM_MATRIX_INDEX + val isThirdColumnSum = ceilCoordsAsPair == THIRD_COLUMN_SUM_MATRIX_INDEX + + val isCalculated = + ceilCoordsAsPair in EMPTY_CEILS_OF_MATRIX + || isUpperDiag || isDownDiag + || isFirstRowSum || isSecondRowSum || isThirdRowSum + || isFirstColumnSum || isSecondColumnSum || isThirdColumnSum + + val numberOfCharacteristic: Byte? = if ( + isCalculated + ) { + null + } else { + (x * 3 + y).toByte() + } +}