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

Merge branch '9-fix-display-conflicts' into 'master'

Resolve "Fix display conflicts"

Closes #9

See merge request !9
parents 16afc6a2 d0dbb454
No related branches found
Tags Release_0.0.8_8
1 merge request!9Resolve "Fix display conflicts"
Pipeline #7835 passed
Fix compute/display conflicts.
Correction sur calcul/affichage des conflits.
...@@ -93,6 +93,8 @@ class ActivityCubit extends HydratedCubit<ActivityState> { ...@@ -93,6 +93,8 @@ class ActivityCubit extends HydratedCubit<ActivityState> {
refresh(); refresh();
} }
state.currentActivity.updateConflictsInBoard();
if (state.currentActivity.checkBoardIsSolved()) { if (state.currentActivity.checkBoardIsSolved()) {
BoardAnimate.startAnimation(this, 'win'); BoardAnimate.startAnimation(this, 'win');
state.currentActivity.isFinished = true; state.currentActivity.isFinished = true;
......
...@@ -137,37 +137,20 @@ class Activity { ...@@ -137,37 +137,20 @@ class Activity {
return false; return false;
} }
ConflictsCount computeConflictsInBoard() { void updateConflictsInBoard() {
final BoardCells cells = board.cells; final BoardCells cells = board.cells;
final ConflictsCount conflicts = boardConflicts;
// reset conflict states // reset conflict states
for (int row = 0; row < board.boardSizeVertical; row++) { for (CellLocation location in board.getCellLocations()) {
for (int col = 0; col < board.boardSizeHorizontal; col++) { boardConflicts[location.row][location.col] = 0;
conflicts[row][col] = 0;
}
} }
// check siblings // check siblings
for (int row = 0; row < board.boardSizeVertical; row++) { for (CellLocation location in board.getCellLocations()) {
for (int col = 0; col < board.boardSizeHorizontal; col++) { final int value = board.get(location).value;
final int value = cells[row][col].value; if (value != 0) {
if (value != 0) { if (board.cellHasSiblingWithSameValue(location)) {
for (int deltaRow = -1; deltaRow <= 1; deltaRow++) { boardConflicts[location.row][location.col]++;
for (int deltaCol = -1; deltaCol <= 1; deltaCol++) {
if (row + deltaRow >= 0 &&
row + deltaRow < board.boardSizeHorizontal &&
col + deltaCol >= 0 &&
col + deltaCol < board.boardSizeVertical &&
(deltaRow * deltaCol != 0)) {
final int siblingValue = cells[row + deltaRow][col + deltaCol].value;
if (siblingValue == value) {
conflicts[row][col]++;
}
}
}
}
} }
} }
} }
...@@ -176,33 +159,27 @@ class Activity { ...@@ -176,33 +159,27 @@ class Activity {
for (String blockId in board.getBlockIds()) { for (String blockId in board.getBlockIds()) {
List<int> values = []; List<int> values = [];
List<int> duplicateValues = []; List<int> duplicateValues = [];
for (int row = 0; row < board.boardSizeVertical; row++) { for (CellLocation location in board.getCellLocations()) {
for (int col = 0; col < board.boardSizeHorizontal; col++) { if (board.get(location).blockId == blockId) {
if (cells[row][col].blockId == blockId) { final int value = board.get(location).value;
final int value = cells[row][col].value; if (value != 0) {
if (value != 0) { if (!values.contains(value)) {
if (!values.contains(value)) { values.add(value);
values.add(value); } else {
} else { duplicateValues.add(value);
duplicateValues.add(value);
}
} }
} }
} }
} }
for (int duplicateValue in duplicateValues) { for (int duplicateValue in duplicateValues) {
for (int row = 0; row < board.boardSizeVertical; row++) { for (CellLocation location in board.getCellLocations()) {
for (int col = 0; col < board.boardSizeHorizontal; col++) { if (board.get(location).blockId == blockId &&
if (cells[row][col].blockId == blockId && board.get(location).value == duplicateValue) {
cells[row][col].value == duplicateValue) { boardConflicts[location.row][location.col]++;
conflicts[row][col]++;
}
} }
} }
} }
} }
return conflicts;
} }
void showTip(ActivityCubit activityCubit) { void showTip(ActivityCubit activityCubit) {
...@@ -277,12 +254,11 @@ class Activity { ...@@ -277,12 +254,11 @@ class Activity {
List<CellLocation> cellsWithWrongValue = []; List<CellLocation> cellsWithWrongValue = [];
for (int row = 0; row < board.boardSizeVertical; row++) { for (CellLocation location in board.getCellLocations()) {
for (int col = 0; col < board.boardSizeHorizontal; col++) { if (cells[location.row][location.col].value != 0 &&
if (cells[row][col].value != 0 && cells[location.row][location.col].value !=
cells[row][col].value != cellsSolved[row][col].value) { cellsSolved[location.row][location.col].value) {
cellsWithWrongValue.add(CellLocation.go(row, col)); cellsWithWrongValue.add(location);
}
} }
} }
...@@ -292,11 +268,9 @@ class Activity { ...@@ -292,11 +268,9 @@ class Activity {
List<CellLocation> getCellsWithConflicts() { List<CellLocation> getCellsWithConflicts() {
List<CellLocation> cellsWithConflict = []; List<CellLocation> cellsWithConflict = [];
for (int row = 0; row < board.boardSizeVertical; row++) { for (CellLocation location in board.getCellLocations()) {
for (int col = 0; col < board.boardSizeHorizontal; col++) { if (boardConflicts[location.row][location.col] != 0) {
if (boardConflicts[row][col] != 0) { cellsWithConflict.add(location);
cellsWithConflict.add(CellLocation.go(row, col));
}
} }
} }
......
...@@ -3,7 +3,7 @@ description: A suguru game application. ...@@ -3,7 +3,7 @@ description: A suguru game application.
publish_to: "none" publish_to: "none"
version: 0.0.7+7 version: 0.0.8+8
environment: environment:
sdk: "^3.0.0" sdk: "^3.0.0"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment