diagonalUpRight method
Color in diagonal with a direction up right from a current position defined by the movement.
Requires a list of colors
and a number n
of cells to color.
If no number n
of cells is passed all the diagonal is colored.
Return true on success.
Implementation
bool diagonalUpRight(List<int> colors, [int? n]) {
int? param = n;
int j = 0;
int offset = 0;
bool once = false;
if (param == null) {
while (move.diagonalDownLeft()) {
offset++;
}
final List<int> newColors = buildOffset(colors, offset);
while (color(newColors[j]) && move.diagonalUpRight()) {
j = (j + 1) % colors.length;
once = true;
}
if (once) {
return true;
}
return false;
} else {
param--;
}
if (param < 1 || !color(colors[j])) {
return false;
}
for (int i = 0; i < param; i++) {
j = (j + 1) % colors.length;
if (!move.diagonalUpRight() || !color(colors[j])) {
return false;
}
}
return true;
}