zigzagDownRightLeft method

bool zigzagDownRightLeft(
  1. List<int> colors,
  2. [int? n]
)

Color with an zig-zag pattern with direction down right left from a starting position

Requires a list of colors and a number n of cells to color. If no number n of cells is passed all the cells that fits in the patter are colored. Return true on success.

Implementation

bool zigzagDownRightLeft(List<int> colors, [int? n]) {
  int? param = n;
  final int column = move.column;
  final int row = move.row;
  param ??= 6 - row;
  if (column != 2) {
    return false;
  }
  if (colors.isEmpty) {
    return false;
  }
  final List<int> newColors = buildOffset(colors, param);
  if (param.isOdd && n == null) {
    move.toPosition(0, 3);

    return zigzagDownLeftRight(newColors, 6);
  }
  if (n == null) {
    move.toPosition(0, 2);

    return zigzagDownRightLeft(newColors, 6);
  }
  if (param < 3) {
    return false;
  }

  return _zigzagHelper(
    param,
    colors,
    move.diagonalDownRight,
    move.diagonalDownLeft,
  );
}