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.1.0_9
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> {
refresh();
}
state.currentActivity.updateConflictsInBoard();
if (state.currentActivity.checkBoardIsSolved()) {
BoardAnimate.startAnimation(this, 'win');
state.currentActivity.isFinished = true;
......
......@@ -137,37 +137,20 @@ class Activity {
return false;
}
ConflictsCount computeConflictsInBoard() {
void updateConflictsInBoard() {
final BoardCells cells = board.cells;
final ConflictsCount conflicts = boardConflicts;
// reset conflict states
for (int row = 0; row < board.boardSizeVertical; row++) {
for (int col = 0; col < board.boardSizeHorizontal; col++) {
conflicts[row][col] = 0;
}
for (CellLocation location in board.getCellLocations()) {
boardConflicts[location.row][location.col] = 0;
}
// check siblings
for (int row = 0; row < board.boardSizeVertical; row++) {
for (int col = 0; col < board.boardSizeHorizontal; col++) {
final int value = cells[row][col].value;
if (value != 0) {
for (int deltaRow = -1; deltaRow <= 1; deltaRow++) {
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]++;
}
}
}
}
for (CellLocation location in board.getCellLocations()) {
final int value = board.get(location).value;
if (value != 0) {
if (board.cellHasSiblingWithSameValue(location)) {
boardConflicts[location.row][location.col]++;
}
}
}
......@@ -176,33 +159,27 @@ class Activity {
for (String blockId in board.getBlockIds()) {
List<int> values = [];
List<int> duplicateValues = [];
for (int row = 0; row < board.boardSizeVertical; row++) {
for (int col = 0; col < board.boardSizeHorizontal; col++) {
if (cells[row][col].blockId == blockId) {
final int value = cells[row][col].value;
if (value != 0) {
if (!values.contains(value)) {
values.add(value);
} else {
duplicateValues.add(value);
}
for (CellLocation location in board.getCellLocations()) {
if (board.get(location).blockId == blockId) {
final int value = board.get(location).value;
if (value != 0) {
if (!values.contains(value)) {
values.add(value);
} else {
duplicateValues.add(value);
}
}
}
}
for (int duplicateValue in duplicateValues) {
for (int row = 0; row < board.boardSizeVertical; row++) {
for (int col = 0; col < board.boardSizeHorizontal; col++) {
if (cells[row][col].blockId == blockId &&
cells[row][col].value == duplicateValue) {
conflicts[row][col]++;
}
for (CellLocation location in board.getCellLocations()) {
if (board.get(location).blockId == blockId &&
board.get(location).value == duplicateValue) {
boardConflicts[location.row][location.col]++;
}
}
}
}
return conflicts;
}
void showTip(ActivityCubit activityCubit) {
......@@ -277,12 +254,11 @@ class Activity {
List<CellLocation> cellsWithWrongValue = [];
for (int row = 0; row < board.boardSizeVertical; row++) {
for (int col = 0; col < board.boardSizeHorizontal; col++) {
if (cells[row][col].value != 0 &&
cells[row][col].value != cellsSolved[row][col].value) {
cellsWithWrongValue.add(CellLocation.go(row, col));
}
for (CellLocation location in board.getCellLocations()) {
if (cells[location.row][location.col].value != 0 &&
cells[location.row][location.col].value !=
cellsSolved[location.row][location.col].value) {
cellsWithWrongValue.add(location);
}
}
......@@ -292,11 +268,9 @@ class Activity {
List<CellLocation> getCellsWithConflicts() {
List<CellLocation> cellsWithConflict = [];
for (int row = 0; row < board.boardSizeVertical; row++) {
for (int col = 0; col < board.boardSizeHorizontal; col++) {
if (boardConflicts[row][col] != 0) {
cellsWithConflict.add(CellLocation.go(row, col));
}
for (CellLocation location in board.getCellLocations()) {
if (boardConflicts[location.row][location.col] != 0) {
cellsWithConflict.add(location);
}
}
......
......@@ -3,7 +3,7 @@ description: A suguru game application.
publish_to: "none"
version: 0.0.7+7
version: 0.0.8+8
environment:
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