Skip to content

Commit 3e34455

Browse files
committed
added square from different starting angles
1 parent 0b6299f commit 3e34455

File tree

4 files changed

+155
-22
lines changed

4 files changed

+155
-22
lines changed

lib/src/coloring/advanced_coloring.dart

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,91 @@ class Coloring extends BasicColoring {
196196
/// Color with a square shape from the current position.
197197
///
198198
/// Requires a list of [colors].
199-
bool square(List<int> colors, [int? n]) {
200-
if (super.getCross.validatePosition(move.row, move.column + 1) &&
201-
super.getCross.validatePosition(move.row - 1, move.column) &&
202-
super.getCross.validatePosition(move.row, move.column)) {
203-
final int row = move.row;
204-
final int column = move.column;
199+
bool squareBottomLeft(List<int> colors, [int? n]) {
200+
final int originalRow = move.row;
201+
final int originalColumn = move.column;
202+
if (move.right() && move.up() && move.left()) {
203+
move.toPosition(originalRow, originalColumn);
205204
color(colors[0 % colors.length]);
206-
move.toPosition(row, column + 1);
205+
move.right();
207206
color(colors[1 % colors.length]);
208-
move.toPosition(row - 1, column + 1);
207+
move.up();
209208
color(colors[2 % colors.length]);
210-
move.toPosition(row - 1, column);
209+
move.left();
211210
color(colors[3 % colors.length]);
212211

213212
return true;
214213
}
214+
move.toPosition(originalRow, originalColumn);
215+
216+
return false;
217+
}
218+
219+
/// Color with a square shape from the current position.
220+
///
221+
/// Requires a list of [colors].
222+
bool squareBottomRight(List<int> colors, [int? n]) {
223+
final int originalRow = move.row;
224+
final int originalColumn = move.column;
225+
if (move.up() && move.left() && move.down()) {
226+
move.toPosition(originalRow, originalColumn);
227+
color(colors[0 % colors.length]);
228+
move.up();
229+
color(colors[1 % colors.length]);
230+
move.left();
231+
color(colors[2 % colors.length]);
232+
move.down();
233+
color(colors[3 % colors.length]);
234+
235+
return true;
236+
}
237+
move.toPosition(originalRow, originalColumn);
238+
239+
return false;
240+
}
241+
242+
/// Color with a square shape from the current position.
243+
///
244+
/// Requires a list of [colors].
245+
bool squareTopLeft(List<int> colors, [int? n]) {
246+
final int originalRow = move.row;
247+
final int originalColumn = move.column;
248+
if (move.down() && move.right() && move.up()) {
249+
move.toPosition(originalRow, originalColumn);
250+
color(colors[0 % colors.length]);
251+
move.down();
252+
color(colors[1 % colors.length]);
253+
move.right();
254+
color(colors[2 % colors.length]);
255+
move.up();
256+
color(colors[3 % colors.length]);
257+
258+
return true;
259+
}
260+
move.toPosition(originalRow, originalColumn);
261+
262+
return false;
263+
}
264+
265+
/// Color with a square shape from the current position.
266+
///
267+
/// Requires a list of [colors].
268+
bool squareTopRight(List<int> colors, [int? n]) {
269+
final int originalRow = move.row;
270+
final int originalColumn = move.column;
271+
if (move.left() && move.down() && move.right()) {
272+
move.toPosition(originalRow, originalColumn);
273+
color(colors[0 % colors.length]);
274+
move.left();
275+
color(colors[1 % colors.length]);
276+
move.down();
277+
color(colors[2 % colors.length]);
278+
move.right();
279+
color(colors[3 % colors.length]);
280+
281+
return true;
282+
}
283+
move.toPosition(originalRow, originalColumn);
215284

216285
return false;
217286
}

lib/src/command_caller.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ class CommandCaller {
3131
"down": board.down,
3232
"left": board.left,
3333
"right": board.right,
34-
"square": board.square,
34+
"squareBottomLeft": board.squareBottomLeft,
35+
"squareBottomRight": board.squareBottomRight,
36+
"squareTopLeft": board.squareTopLeft,
37+
"squareTopRight": board.squareTopRight,
3538
"diagonalUpLeft": board.diagonalUpLeft,
3639
"diagonalUpRight": board.diagonalUpRight,
3740
"diagonalDownLeft": board.diagonalDownLeft,

test/interpreter_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void schema_2() {
116116
expect(
117117
interpreter
118118
.validateOnScheme(
119-
"PAINT({blue}, 4, square), GO(A3), PAINT({blue}, :, up), GO(right), PAINT({yellow}, :, up), GO(C5), PAINT({yellow}, 4, square)",
119+
"PAINT({blue}, 4, square bottom left), GO(A3), PAINT({blue}, :, up), GO(right), PAINT({yellow}, :, up), GO(C5), PAINT({yellow}, 4, square bottom left)",
120120
2)
121121
.first
122122
.completed,
@@ -142,7 +142,7 @@ void schema_2() {
142142
expect(
143143
interpreter
144144
.validateOnScheme(
145-
"PAINT({blue}, 4, square), GO(A3), PAINT({blue}, :, up), FILL_EMPTY(yellow)",
145+
"PAINT({blue}, 4, square bottom left), GO(A3), PAINT({blue}, :, up), FILL_EMPTY(yellow)",
146146
2)
147147
.first
148148
.completed,
@@ -529,15 +529,15 @@ void valid_patters() {
529529
test("", () {
530530
interpreter.reset();
531531
var response = interpreter.validateOnScheme(
532-
"paint({green},1,square),mirror(vertical),go(c4),paint({blue},1,square),mirror(vertical)",
532+
"paint({green},1,square bottom left),mirror(vertical),go(c4),paint({blue},1,square bottom left),mirror(vertical)",
533533
1);
534534
expect(response.first.completed, isFalse);
535535
expect(response.second, equals(CatError.none));
536536
});
537537
test("", () {
538538
interpreter.reset();
539539
var response = interpreter.validateOnScheme(
540-
"mirror({paint({green},1,square)},vertical),go(c4),mirror({paint({blue},1,square)},vertical)",
540+
"mirror({paint({green},1,square bottom left)},vertical),go(c4),mirror({paint({blue},1,square bottom left)},vertical)",
541541
1);
542542
expect(response.first.completed, isFalse);
543543
expect(response.second, equals(CatError.none));
@@ -560,7 +560,7 @@ void valid_patters() {
560560
test("", () {
561561
interpreter.reset();
562562
var response = interpreter.validateOnScheme(
563-
"paint({red},1,square),mirror({c1,d1},vertical)", 1);
563+
"paint({red},1,square bottom left),mirror({c1,d1},vertical)", 1);
564564
expect(response.first.completed, isFalse);
565565
expect(response.second, equals(CatError.none));
566566
});
@@ -607,7 +607,7 @@ void valid_patters() {
607607
test("", () {
608608
interpreter.reset();
609609
var response = interpreter.validateOnScheme(
610-
"go(a4),mirror({mirror({paint({red,blue,yellow},3,up)},horizontal)},vertical),go(c1),mirror({paint({blue},1,square)},vertical)",
610+
"go(a4),mirror({mirror({paint({red,blue,yellow},3,up)},horizontal)},vertical),go(c1),mirror({paint({blue},1,square bottom left)},vertical)",
611611
1);
612612
expect(response.first.completed, isFalse);
613613
expect(response.second, equals(CatError.none));
@@ -631,7 +631,7 @@ void valid_patters() {
631631
test("", () {
632632
interpreter.reset();
633633
var response = interpreter.validateOnScheme(
634-
"paint({yellow,red,yellow},:,right),go(up),paint({red,yellow,yellow},:,right),go(a3),paint({yellow,yellow,red},1,square),go(e3),paint({yellow,red,yellow,red},1,square)",
634+
"paint({yellow,red,yellow},:,right),go(up),paint({red,yellow,yellow},:,right),go(a3),paint({yellow,yellow,red},1,square bottom left),go(e3),paint({yellow,red,yellow,red},1,square bottom left)",
635635
1);
636636
expect(response.first.completed, isFalse);
637637
expect(response.second, equals(CatError.none));

test/simple_coloring_test.dart

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ void fillEmpty() {
299299
void square() {
300300
test("Color square from starting position", () {
301301
Coloring board = Coloring(Shape.cross.build);
302-
expect(board.square([1]), isTrue);
302+
expect(board.squareBottomLeft([1]), isTrue);
303303
expect(
304304
board.getBoard,
305305
equals([
@@ -316,7 +316,7 @@ void square() {
316316
});
317317
test("Color square from starting position alternate", () {
318318
Coloring board = Coloring(Shape.cross.build);
319-
expect(board.square([1, 2]), isTrue);
319+
expect(board.squareBottomLeft([1, 2]), isTrue);
320320
expect(
321321
board.getBoard,
322322
equals([
@@ -333,7 +333,7 @@ void square() {
333333
});
334334
test("Color square from starting position alternate", () {
335335
Coloring board = Coloring(Shape.cross.build);
336-
expect(board.square([1, 2, 3]), isTrue);
336+
expect(board.squareBottomLeft([1, 2, 3]), isTrue);
337337
expect(
338338
board.getBoard,
339339
equals([
@@ -350,7 +350,7 @@ void square() {
350350
});
351351
test("Color square from starting position alternate", () {
352352
Coloring board = Coloring(Shape.cross.build);
353-
expect(board.square([1, 2, 3, 4]), isTrue);
353+
expect(board.squareBottomLeft([1, 2, 3, 4]), isTrue);
354354
expect(
355355
board.getBoard,
356356
equals([
@@ -365,10 +365,71 @@ void square() {
365365
expect(board.move.column, equals(0));
366366
expect(board.move.row, equals(2));
367367
});
368+
test("Color square from starting position alternate", () {
369+
Coloring board = Coloring(Shape.cross.build);
370+
expect(board.move.up(), isTrue);
371+
expect(board.squareBottomLeft([1, 2, 3, 4]), isFalse);
372+
expect(board.move.column, equals(0));
373+
expect(board.move.row, equals(2));
374+
});
375+
test("Color square from starting position alternate", () {
376+
Coloring board = Coloring(Shape.cross.build);
377+
expect(board.move.up(), isTrue);
378+
expect(board.squareTopLeft([1, 2, 3, 4]), isTrue);
379+
expect(
380+
board.getBoard,
381+
equals([
382+
[0, 0, 0, 0, 0, 0],
383+
[0, 0, 0, 0, 0, 0],
384+
[1, 4, 0, 0, 0, 0],
385+
[2, 3, 0, 0, 0, 0],
386+
[0, 0, 0, 0, 0, 0],
387+
[0, 0, 0, 0, 0, 0],
388+
]),
389+
);
390+
expect(board.move.column, equals(1));
391+
expect(board.move.row, equals(2));
392+
});
393+
test("Color square from starting position alternate", () {
394+
Coloring board = Coloring(Shape.cross.build);
395+
expect(board.move.right(), isTrue);
396+
expect(board.squareBottomRight([1, 2, 3, 4]), isTrue);
397+
expect(
398+
board.getBoard,
399+
equals([
400+
[0, 0, 0, 0, 0, 0],
401+
[0, 0, 0, 0, 0, 0],
402+
[3, 2, 0, 0, 0, 0],
403+
[4, 1, 0, 0, 0, 0],
404+
[0, 0, 0, 0, 0, 0],
405+
[0, 0, 0, 0, 0, 0],
406+
]),
407+
);
408+
expect(board.move.column, equals(0));
409+
expect(board.move.row, equals(3));
410+
});
411+
test("Color square from starting position alternate", () {
412+
Coloring board = Coloring(Shape.cross.build);
413+
expect(board.move.diagonalUpRight(), isTrue);
414+
expect(board.squareTopRight([1, 2, 3, 4]), isTrue);
415+
expect(
416+
board.getBoard,
417+
equals([
418+
[0, 0, 0, 0, 0, 0],
419+
[0, 0, 0, 0, 0, 0],
420+
[2, 1, 0, 0, 0, 0],
421+
[3, 4, 0, 0, 0, 0],
422+
[0, 0, 0, 0, 0, 0],
423+
[0, 0, 0, 0, 0, 0],
424+
]),
425+
);
426+
expect(board.move.column, equals(1));
427+
expect(board.move.row, equals(3));
428+
});
368429
test("Color square from starting position alternate", () {
369430
Coloring board = Coloring(Shape.cross.build);
370431
expect(board.move.diagonalUpRight(), isTrue);
371-
expect(board.square([1, 2, 3, 4]), isFalse);
432+
expect(board.squareBottomLeft([1, 2, 3, 4]), isFalse);
372433
expect(
373434
board.getBoard,
374435
equals([

0 commit comments

Comments
 (0)