private static int getNeighborCount(bool[] seed, int cellNumber, int stageX, int stageY) { var directionals = new Directionals(cellNumber, stageX, stageY); var culledCells = cullOutOfBounds(directionals); var count = 0; foreach (var cell in culledCells) { if (seed[cell]) { count++; } } return(count); }
private static int[] cullOutOfBounds(Directionals directionals) { //left if (directionals.CellNumber % directionals.StageX == 0) { //top if (directionals.CellNumber == (directionals.StageY * directionals.StageX) - directionals.StageX) { return(new List <int> { directionals.Down, directionals.DownRight, directionals.Right }.ToArray()); //bottom } else if (directionals.CellNumber == 0) { return(new List <int> { directionals.Up, directionals.UpRight, directionals.Right }.ToArray()); //other left cells } else { return(new List <int> { directionals.Up, directionals.UpRight, directionals.Down, directionals.DownRight, directionals.Right }.ToArray()); } //right } else if (directionals.CellNumber % directionals.StageX == directionals.StageX - 1) { //top if (directionals.CellNumber == (directionals.StageY * directionals.StageX) - 1) { return(new List <int> { directionals.Down, directionals.DownLeft, directionals.Left, }.ToArray()); //bottom } else if (directionals.CellNumber < directionals.StageX) { return(new List <int> { directionals.Up, directionals.UpLeft, directionals.Left, }.ToArray()); //other right cells } else { return(new List <int> { directionals.Up, directionals.UpLeft, directionals.Down, directionals.DownLeft, directionals.Left, }.ToArray()); } //top } else if (directionals.CellNumber >= (directionals.StageY * directionals.StageX) - directionals.StageX) { return(new List <int> { directionals.Down, directionals.DownLeft, directionals.DownRight, directionals.Left, directionals.Right }.ToArray()); //bottom } else if (directionals.CellNumber < directionals.StageX) { return(new List <int> { directionals.Up, directionals.UpLeft, directionals.UpRight, directionals.Left, directionals.Right }.ToArray()); //other right cells } else { return(new List <int> { directionals.Up, directionals.UpLeft, directionals.UpRight, directionals.Down, directionals.DownLeft, directionals.DownRight, directionals.Left, directionals.Right }.ToArray()); } }