isNeighbour method

bool isNeighbour(
  1. (int, int) other, {
  2. bool withDiagonal = true,
})

Implementation

bool isNeighbour((int, int) other, {bool withDiagonal = true}) {
  if (this == other) {
    return false;
  }

  if (withDiagonal) {
    return (x - other.x).abs() <= 1 && (y - other.y).abs() <= 1;
  }

  return (x - other.x).abs() <= 1 && y == other.y ||
      x == other.x && (y - other.y).abs() <= 1;
}