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

Merge branch '34-fix-compute-display-conflicts-on-cell-update' into 'master'

Resolve "Fix compute/display conflicts on cell update"

Closes #34

See merge request !29
parents d2f8eb7b 648f7a96
Branches
Tags Release_0.0.27_27
1 merge request!29Resolve "Fix compute/display conflicts on cell update"
Pipeline #1689 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.26
app.versionCode=26
app.versionName=0.0.27
app.versionCode=27
Fix display conflicts in board
Correction de l'affichage des conflits sur la grille
import 'package:flutter/material.dart';
import '../provider/data.dart';
import '../utils/board_utils.dart';
class Cell {
int value;
......@@ -103,6 +104,7 @@ class Cell {
myProvider.updateCellValue(myProvider.currentCellCol, myProvider.currentCellRow, this.value);
}
myProvider.selectCell(null, null);
BoardUtils.computeConflictsInBoard(myProvider);
},
)
);
......
......@@ -156,19 +156,36 @@ class BoardUtils {
bool isSolved = true;
// reset conflict states
// (re)compute conflicts
BoardUtils.computeConflictsInBoard(myProvider);
// check grid is fully completed and does not contain conflict
for (var row = 0; row < boardSize; row++) {
for (var col = 0; col < boardSize; col++) {
cells[row][col].conflictsCount = 0;
if (cells[row][col].value == 0 || cells[row][col].conflictsCount != 0) {
return false;
}
}
}
print('-> ok sudoku solved!');
return true;
}
// check grid is fully completed
static void computeConflictsInBoard(Data myProvider) {
List cells = myProvider.cells;
int blockSizeHorizontal = myProvider.blockSizeHorizontal;
int blockSizeVertical = myProvider.blockSizeVertical;
int boardSize = blockSizeHorizontal * blockSizeVertical;
// reset conflict states
for (var row = 0; row < boardSize; row++) {
for (var col = 0; col < boardSize; col++) {
if (cells[row][col].value == 0) {
isSolved = false;
}
cells[row][col].conflictsCount = 0;
}
}
......@@ -188,7 +205,6 @@ class BoardUtils {
for (var col = 0; col < boardSize; col++) {
cells[row][col].conflictsCount++;
}
isSolved = false;
}
}
......@@ -208,7 +224,6 @@ class BoardUtils {
for (var row = 0; row < boardSize; row++) {
cells[row][col].conflictsCount++;
}
isSolved = false;
}
}
......@@ -241,16 +256,9 @@ class BoardUtils {
cells[row][col].conflictsCount++;
}
}
isSolved = false;
}
}
}
if (isSolved) {
print('-> ok sudoku solved!');
}
return isSolved;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment