main static method
Implementation
static List<String> main(
List<Pair<int, int>> positions,
List<String> colors, {
bool copyCommands = false,
}) {
if (positions.length < 2 || colors.isEmpty) {
return <String>[];
}
final CommandsInspector inspector = CommandsInspector();
String direction = "";
if (inspector._right(positions)) {
direction = "right";
} else if (inspector._left(positions)) {
direction = "left";
} else if (inspector._up(positions)) {
direction = "up";
} else if (inspector._down(positions)) {
direction = "down";
} else if (inspector._diagonalDownRight(positions)) {
direction = "diagonal down right";
} else if (inspector._diagonalUpLeft(positions)) {
direction = "diagonal up left";
} else if (inspector._diagonalUpRight(positions)) {
direction = "diagonal up right";
} else if (inspector._diagonalDownLeft(positions)) {
direction = "diagonal down left";
} else if (inspector._lDownLeft(positions)) {
direction = "l down left";
} else if (inspector._lDownRight(positions)) {
direction = "l down right";
} else if (inspector._lLeftUp(positions)) {
direction = "l left up";
} else if (inspector._lLeftDown(positions)) {
direction = "l left down";
} else if (inspector._lRightUp(positions)) {
direction = "l right up";
} else if (inspector._lRightDown(positions)) {
direction = "l right down";
} else if (inspector._lUpLeft(positions)) {
direction = "l up left";
} else if (inspector._lUpRight(positions)) {
direction = "l up right";
} else if (inspector._zigzagRightDownUp(positions)) {
direction = "zigzag right down up";
} else if (inspector._zigzagRightUpDown(positions)) {
direction = "zigzag right up down";
} else if (inspector._zigzagLeftDownUp(positions)) {
direction = "zigzag left down up";
} else if (inspector._zigzagLeftUpDown(positions)) {
direction = "zigzag left up down";
} else if (inspector._zigzagDownLeftRight(positions)) {
direction = "zigzag down left right";
} else if (inspector._zigzagDownRightLeft(positions)) {
direction = "zigzag down right left";
} else if (inspector._zigzagUpLeftRight(positions)) {
direction = "zigzag up left right";
} else if (inspector._zigzagUpRightLeft(positions)) {
direction = "zigzag up right left";
} else if (inspector._squareBottomLeft(positions)) {
direction = patternsEn["square bottom left"]!;
} else if (inspector._squareBottomRight(positions)) {
direction = patternsEn["square bottom right"]!;
} else if (inspector._squareTopLeft(positions)) {
direction = patternsEn["square top left"]!;
} else if (inspector._squareTopRight(positions)) {
direction = patternsEn["square top right"]!;
} else if (inspector._squareBottomLeftReverse(positions)) {
direction = patternsEn["square bottom left reverse"]!;
} else if (inspector._squareBottomRightReverse(positions)) {
direction = patternsEn["square bottom right reverse"]!;
} else if (inspector._squareTopLeftReverse(positions)) {
direction = patternsEn["square top left reverse"]!;
} else if (inspector._squareTopRightReverse(positions)) {
direction = patternsEn["square top right reverse"]!;
} else {
final List<String> command = <String>[];
int j = 0;
for (final Pair<int, int> k in positions) {
command
..add("go(${rows[k.first]}${k.second + 1})")
..add(
"paint(${colors[j]})",
);
j = (j + 1) % colors.length;
}
return command;
}
if (copyCommands &&
(direction.startsWith("right") ||
direction.startsWith("left") ||
direction.startsWith("up") ||
direction.startsWith("down") ||
direction.startsWith("diagonal"))) {
return inspector._conversionForCopy(direction, positions, colors);
}
final List<String> command = <String>[];
if (!direction.isBlank) {
command
..add(
"go(${rows[positions.first.first]}${positions.first.second + 1})",
)
..add(
"paint({${colors.joinToString()}},${positions.length},$direction)",
);
}
return command;
}