using System.Linq; namespace Life.Automaton { public static class GameOfLife { public static Rule Rule(string born, string survive) { bool WillSurvive(int neighbours) => survive.Contains(neighbours.ToString()); bool WillBorn(int neighbours) => born.Contains(neighbours.ToString()); return field => { var @new = new Cell[field.Size.Width, field.Size.Height]; for (int i = 0; i < field.Size.Width; i++) { for (int j = 0; j < field.Size.Height; j++) { var neighbours = field.Neighbours(i, j).Count(c => c.IsAlive); @new[i,j] = new Cell { IsAlive = field[i,j].IsAlive ? WillSurvive(neighbours) : WillBorn(neighbours) }; } } return @new; }; } } }