From b20b5993a00f6a9eb6039505cc18873de34a5d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Harrault?= <benoit@harrault.fr> Date: Tue, 13 Jul 2021 16:59:21 +0200 Subject: [PATCH] Show allowed values in select value bar --- android/gradle.properties | 4 +- .../metadata/android/en-US/changelogs/32.txt | 1 + .../metadata/android/fr-FR/changelogs/32.txt | 1 + lib/entities/cell.dart | 14 +++- lib/utils/board_utils.dart | 79 +++++++++++++++++++ 5 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/32.txt create mode 100644 fastlane/metadata/android/fr-FR/changelogs/32.txt diff --git a/android/gradle.properties b/android/gradle.properties index 9742e8d..4878903 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,5 +1,5 @@ org.gradle.jvmargs=-Xmx1536M android.useAndroidX=true android.enableJetifier=true -app.versionName=0.0.31 -app.versionCode=31 +app.versionName=0.0.32 +app.versionCode=32 diff --git a/fastlane/metadata/android/en-US/changelogs/32.txt b/fastlane/metadata/android/en-US/changelogs/32.txt new file mode 100644 index 0000000..51fe2dc --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/32.txt @@ -0,0 +1 @@ +Show allowed values in select value bar diff --git a/fastlane/metadata/android/fr-FR/changelogs/32.txt b/fastlane/metadata/android/fr-FR/changelogs/32.txt new file mode 100644 index 0000000..e5484ab --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/32.txt @@ -0,0 +1 @@ +Mise en évidence des valeurs autorisées dans la barre de sélection des valeurs diff --git a/lib/entities/cell.dart b/lib/entities/cell.dart index bb56ed9..2a76eb5 100644 --- a/lib/entities/cell.dart +++ b/lib/entities/cell.dart @@ -90,9 +90,21 @@ class Cell { imageAsset = 'assets/skins/' + myProvider.skin + '_' + this.value.toString() + '.png'; } + Color backgroundColor = Colors.grey[200]; + + if ( + myProvider.showConflicts + && myProvider.currentCellCol != null + && myProvider.currentCellRow != null + ) { + if (!BoardUtils.isValueAllowed(myProvider, myProvider.currentCellCol, myProvider.currentCellRow, this.value)) { + backgroundColor = Colors.pink[100]; + } + } + return Container( decoration: BoxDecoration( - color: Colors.grey[200], + color: backgroundColor, border: Border.all( color: Colors.black, width: 2, diff --git a/lib/utils/board_utils.dart b/lib/utils/board_utils.dart index 7e696d3..baa0527 100644 --- a/lib/utils/board_utils.dart +++ b/lib/utils/board_utils.dart @@ -178,6 +178,85 @@ class BoardUtils { return true; } + static bool isValueAllowed(Data myProvider, int candidateCol, int candidateRow, int candidateValue) { + if (candidateValue == 0) { + return true; + } + + List cells = myProvider.cells; + + int blockSizeHorizontal = myProvider.blockSizeHorizontal; + int blockSizeVertical = myProvider.blockSizeVertical; + + int boardSize = blockSizeHorizontal * blockSizeVertical; + + // check lines does not contains a value twice + for (var row = 0; row < boardSize; row++) { + List values = []; + for (var col = 0; col < boardSize; col++) { + int value = cells[row][col].value; + if (row == candidateRow && col == candidateCol) { + value = candidateValue; + } + if (value != 0) { + values.add(value); + } + } + List distinctValues = values.toSet().toList(); + if (values.length != distinctValues.length) { + return false; + } + } + + // check columns does not contains a value twice + for (var col = 0; col < boardSize; col++) { + List values = []; + for (var row = 0; row < boardSize; row++) { + int value = cells[row][col].value; + if (row == candidateRow && col == candidateCol) { + value = candidateValue; + } + if (value != 0) { + values.add(value); + } + } + List distinctValues = values.toSet().toList(); + if (values.length != distinctValues.length) { + return false; + } + } + + // check blocks does not contains a value twice + int horizontalBlocksCount = blockSizeVertical; + int verticalBlocksCount = blockSizeHorizontal; + for (var blockRow = 0; blockRow < verticalBlocksCount; blockRow++) { + for (var blockCol = 0; blockCol < horizontalBlocksCount; blockCol++) { + List values = []; + + for (var rowInBlock = 0; rowInBlock < blockSizeVertical; rowInBlock++) { + for (var colInBlock = 0; colInBlock < blockSizeHorizontal; colInBlock++) { + int row = (blockRow * blockSizeVertical) + rowInBlock; + int col = (blockCol * blockSizeHorizontal) + colInBlock; + int value = cells[row][col].value; + if (row == candidateRow && col == candidateCol) { + value = candidateValue; + } + if (value != 0) { + values.add(value); + } + } + } + + List distinctValues = values.toSet().toList(); + if (values.length != distinctValues.length) { + return false; + } + } + } + + return true; + } + static void computeConflictsInBoard(Data myProvider) { List cells = myProvider.cells; -- GitLab