Skip to content

Commit 093cc0e

Browse files
committed
Prevent empty cells from mirror.
1 parent d72459e commit 093cc0e

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

lib/src/coloring/basic_coloring.dart

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,9 @@ class BasicColoring {
403403
bool mirrorHorizontalUpDown() {
404404
for (final int i in 0.rangeTo(2)) {
405405
for (final int j in 0.rangeTo(5)) {
406-
_shape.grid[5 - i][j] = _shape.grid[i][j];
406+
if(_shape.grid[i][j] != 0){
407+
_shape.grid[5 - i][j] = _shape.grid[i][j];
408+
}
407409
}
408410
}
409411

@@ -417,7 +419,9 @@ class BasicColoring {
417419
bool mirrorHorizontalDownUp() {
418420
for (final int i in 3.rangeTo(5)) {
419421
for (final int j in 0.rangeTo(5)) {
420-
_shape.grid[5 - i][j] = _shape.grid[i][j];
422+
if(_shape.grid[i][j] != 0) {
423+
_shape.grid[5 - i][j] = _shape.grid[i][j];
424+
}
421425
}
422426
}
423427

@@ -432,7 +436,9 @@ class BasicColoring {
432436
bool mirrorVerticalLeftRight() {
433437
for (final int i in 0.rangeTo(2)) {
434438
for (final int j in 0.rangeTo(5)) {
435-
_shape.grid[j][5 - i] = _shape.grid[j][i];
439+
if(_shape.grid[i][j] != 0) {
440+
_shape.grid[j][5 - i] = _shape.grid[j][i];
441+
}
436442
}
437443
}
438444

@@ -447,7 +453,9 @@ class BasicColoring {
447453
bool mirrorVerticalRightLeft() {
448454
for (final int i in 3.rangeTo(5)) {
449455
for (final int j in 0.rangeTo(5)) {
450-
_shape.grid[j][5 - i] = _shape.grid[j][i];
456+
if(_shape.grid[i][j] != 0) {
457+
_shape.grid[j][5 - i] = _shape.grid[j][i];
458+
}
451459
}
452460
}
453461

test/interpreter_test.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,50 @@ void other_schemas() {
487487
.completed,
488488
isTrue);
489489
});
490+
test("3", () {
491+
const json =
492+
'{"data":[{"index":1,"array":[[0, 0, 3, 3, 0, 0], [0, 0, 3, 3, 0, 0], [4, 2, 3, 3, 2, 4], [4, 2, 3, 3, 2, 4], [0, 0, 3, 3, 0, 0], [0, 0, 3, 3, 0, 0]]}]}';
493+
final CATInterpreter interpreter = CATInterpreter(json, Shape.cross);
494+
interpreter.reset();
495+
expect(interpreter.getResults.getStates.length, equals(1));
496+
expect(interpreter.getResults.getCommands.length, equals(1));
497+
expect(interpreter.getResults.completed, isFalse);
498+
expect(interpreter.board.move.column, equals(0));
499+
expect(interpreter.board.move.row, equals(3));
500+
expect(
501+
interpreter.board.getCross.getGrid,
502+
equals([
503+
[0, 0, 0, 0, 0, 0],
504+
[0, 0, 0, 0, 0, 0],
505+
[0, 0, 0, 0, 0, 0],
506+
[0, 0, 0, 0, 0, 0],
507+
[0, 0, 0, 0, 0, 0],
508+
[0, 0, 0, 0, 0, 0],
509+
]));
510+
BasicShape start = Cross.fromList([
511+
[0, 0, 1, 1, 0, 0],
512+
[0, 0, 0, 0, 0, 0],
513+
[0, 0, 0, 0, 0, 0],
514+
[0, 0, 0, 0, 0, 0],
515+
[0, 0, 1, 0, 0, 0],
516+
[0, 0, 0, 0, 0, 0],
517+
]);
518+
interpreter.board.joinBoards(start);
519+
Pair<Results, CatError> response = interpreter
520+
.validateOnScheme(
521+
"go(F3), MIRROR(horizontal)",
522+
1);
523+
BasicShape expected = Cross.fromList([
524+
[0, 0, 1, 1, 0, 0],
525+
[0, 0, 0, 0, 0, 0],
526+
[0, 0, 0, 0, 0, 0],
527+
[0, 0, 0, 0, 0, 0],
528+
[0, 0, 1, 0, 0, 0],
529+
[0, 0, 1, 1, 0, 0],
530+
]);
531+
expect(response.second, equals(CatError.none));
532+
expect(response.first.getStates.last, equals(expected));
533+
});
490534
});
491535
}
492536

0 commit comments

Comments
 (0)