private static UniformGrid UnitTestCrossover(int rows) { int columns = StaticRandom.Next(2, 13); #region build parents SolidColorBrush[][] parents = UtilityWPF.GetRandomColors(rows, 96, 224). Select(o => { SolidColorBrush brush = new SolidColorBrush(o); return(Enumerable.Range(0, columns). Select(p => brush). ToArray()); }). ToArray(); #endregion int numSlices = 1 + StaticRandom.Next(columns - 1); // Crossover SolidColorBrush[][] children = UtilityAI.Crossover(parents, numSlices); #region build return UniformGrid grid = new UniformGrid() { Columns = columns, Rows = rows, }; for (int row = 0; row < rows; row++) { for (int col = 0; col < columns; col++) { Border rect = new Border() { Background = children[row][col], BorderBrush = Brushes.Black, CornerRadius = new CornerRadius(6), BorderThickness = new Thickness(1), Margin = new Thickness(3), }; if (col == 0) { Color color = UtilityWPF.ExtractColor(children[row][col]); TextBlock text = new TextBlock() { Text = string.Format("{0} {1} {2}", color.R, color.G, color.B), Foreground = new SolidColorBrush(UtilityWPF.OppositeColor(color)), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, }; //rect.Child = text; } grid.Children.Add(rect); } } #endregion return(grid); }