Skip to content

Commit 410855b

Browse files
committed
Modified fill empty command, modified comparison between elements
1 parent 0061faa commit 410855b

File tree

2 files changed

+17
-26
lines changed

2 files changed

+17
-26
lines changed

lib/src/coloring/basic_coloring.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import "package:interpreter/src/models/basic_shape.dart";
44

55
/// It's a class that allows you to color a shape
66
class BasicColoring {
7-
87
/// Creating a constructor for the class BasicColoring.
98
BasicColoring(BasicShape shape) : _shape = shape;
109

@@ -263,9 +262,12 @@ class BasicColoring {
263262
/// Returns:
264263
/// A boolean value.
265264
bool fillEmpty(int color) {
266-
for (final List<int> line in _shape.grid) {
267-
for (int i = 0; i < 6; i++) {
268-
line[i] = line[i] == _defaultColor ? color : line[i];
265+
for (int i = 0; i < _shape.grid.length; i++) {
266+
for (int j = 0; j < _shape.grid[i].length; j++) {
267+
if (_shape.validatePosition(i, j)) {
268+
_shape.grid[i][j] =
269+
_shape.grid[i][j] == _defaultColor ? color : _shape.grid[i][j];
270+
}
269271
}
270272
}
271273

@@ -403,7 +405,7 @@ class BasicColoring {
403405
bool mirrorHorizontalUpDown() {
404406
for (final int i in 0.rangeTo(2)) {
405407
for (final int j in 0.rangeTo(5)) {
406-
if(_shape.grid[i][j] != 0 && _shape.grid[5 - i][j] == 0){
408+
if (_shape.grid[i][j] != 0 && _shape.grid[5 - i][j] == 0) {
407409
_shape.grid[5 - i][j] = _shape.grid[i][j];
408410
}
409411
}
@@ -419,7 +421,7 @@ class BasicColoring {
419421
bool mirrorHorizontalDownUp() {
420422
for (final int i in 3.rangeTo(5)) {
421423
for (final int j in 0.rangeTo(5)) {
422-
if(_shape.grid[i][j] != 0 && _shape.grid[5 - i][j] == 0) {
424+
if (_shape.grid[i][j] != 0 && _shape.grid[5 - i][j] == 0) {
423425
_shape.grid[5 - i][j] = _shape.grid[i][j];
424426
}
425427
}
@@ -436,7 +438,7 @@ class BasicColoring {
436438
bool mirrorVerticalLeftRight() {
437439
for (final int i in 0.rangeTo(2)) {
438440
for (final int j in 0.rangeTo(5)) {
439-
if(_shape.grid[j][i] != 0 && _shape.grid[j][5 - i] == 0) {
441+
if (_shape.grid[j][i] != 0 && _shape.grid[j][5 - i] == 0) {
440442
_shape.grid[j][5 - i] = _shape.grid[j][i];
441443
}
442444
}
@@ -453,7 +455,7 @@ class BasicColoring {
453455
bool mirrorVerticalRightLeft() {
454456
for (final int i in 3.rangeTo(5)) {
455457
for (final int j in 0.rangeTo(5)) {
456-
if(_shape.grid[j][i] != 0 && _shape.grid[j][5 - i] == 0) {
458+
if (_shape.grid[j][i] != 0 && _shape.grid[j][5 - i] == 0) {
457459
_shape.grid[j][5 - i] = _shape.grid[j][i];
458460
}
459461
}

lib/src/models/cross.dart

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,17 @@ class Cross implements BasicShape {
4141
/// Overriding the `==` operator.
4242
@override
4343
bool operator ==(Object other) {
44-
if (other is Cross) {
45-
if (grid[0][2] != other.grid[0][2] || grid[0][3] != other.grid[0][3]) {
46-
return false;
47-
}
48-
if (grid[1][2] != other.grid[1][2] || grid[1][3] != other.grid[1][3]) {
49-
return false;
50-
}
51-
for (int i = 2; i < 4; i++) {
52-
for (int j = 0; j < 6; j++) {
53-
if (grid[i][j] != other.grid[i][j]) {
44+
if(other is! Cross){
45+
return false;
46+
}
47+
for(int i =0; i< grid.length; i++){
48+
for(int j = 0; i<grid[i].length; j++){
49+
if(validatePosition(i, j)){
50+
if(other.grid[i][j] != grid[i][j]){
5451
return false;
5552
}
5653
}
5754
}
58-
if (grid[4][2] != other.grid[4][2] || grid[4][3] != other.grid[4][3]) {
59-
return false;
60-
}
61-
if (grid[5][2] != other.grid[5][2] || grid[5][3] != other.grid[5][3]) {
62-
return false;
63-
}
64-
} else {
65-
return false;
6655
}
6756

6857
return true;

0 commit comments

Comments
 (0)