public bool WouldStayAlive(Point cell) { var aliveNeighbourCount = GetAliveNeighbourCount(cell); return aliveNeighbourCount == 2 || aliveNeighbourCount == 3; }
public IEnumerable<Point> GetNeighbours(Point cell) { int[] d = {-1, 0, 1}; return d.SelectMany(x => d.Select(y => new Point(cell.X + x, cell.Y + y))) .Where(point => (cell.X != point.X) || (cell.Y != point.Y)); }
public bool WouldRevive(Point cell) { return GetAliveNeighbourCount(cell) == 3; }
public int GetAliveNeighbourCount(Point cell) { return GetNeighbours(cell).Count(point => Cells.Contains(point)); }