Skip to content
Snippets Groups Projects
Commit b20b5993 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Show allowed values in select value bar

parent fd74f958
No related branches found
No related tags found
1 merge request!34Resolve "Show allowed values in select value bar"
Pipeline #1726 passed
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
Show allowed values in select value bar
Mise en évidence des valeurs autorisées dans la barre de sélection des valeurs
......@@ -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,
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment