internal void Iterate() { var next = new AcreType[acres.GetLength(0), acres.GetLength(1)]; for (var i = 0; i < acres.GetLength(0); ++i) { for (var j = 0; j < acres.GetLength(1); ++j) { next[i, j] = GetNext(i, j); } } Array.Copy(next, acres, next.Length); }
private int Count(int i, int j, AcreType acreType) { var count = 0; var hasRowAbove = j > 0; var hasRowBelow = j < acres.GetLength(1) - 1; if (i > 0) { if (hasRowAbove && acres[i - 1, j - 1] == acreType) { count++; } if (acres[i - 1, j] == acreType) { count++; } if (hasRowBelow && acres[i - 1, j + 1] == acreType) { count++; } } if (hasRowAbove && acres[i, j - 1] == acreType) { count++; } if (hasRowBelow && acres[i, j + 1] == acreType) { count++; } if (i < acres.GetLength(0) - 1) { if (hasRowAbove && acres[i + 1, j - 1] == acreType) { count++; } if (acres[i + 1, j] == acreType) { count++; } if (hasRowBelow && acres[i + 1, j + 1] == acreType) { count++; } } return(count); }
internal int Count(AcreType type) { var count = 0; for (var i = 0; i < acres.GetLength(0); ++i) { for (var j = 0; j < acres.GetLength(1); ++j) { if (acres[i, j] == type) { count++; } } } return(count); }