//Any live cell with fewer than two live neighbours dies, as if caused by under population public void TestRule1() { //test with 0 live neighbors GeneticLife test = new GeneticLife(2); test.GetCell(0, 0).IsAlive = true; test.GetCell(0, 1).IsAlive = false; test.GetCell(1, 0).IsAlive = false; test.GetCell(1, 1).IsAlive = false; test.Iterate(); Assert.IsFalse(test.GetCell(0, 0).IsAlive); Assert.IsFalse(test.GetCell(0, 1).IsAlive); Assert.IsFalse(test.GetCell(1, 0).IsAlive); Assert.IsFalse(test.GetCell(1, 1).IsAlive); //test with 1 live neighbors test = new GeneticLife(2); test.GetCell(0, 0).IsAlive = true; test.GetCell(0, 1).IsAlive = true; test.GetCell(1, 0).IsAlive = false; test.GetCell(1, 1).IsAlive = false; test.Iterate(); Assert.IsFalse(test.GetCell(0, 0).IsAlive); Assert.IsFalse(test.GetCell(0, 1).IsAlive); Assert.IsFalse(test.GetCell(1, 0).IsAlive); Assert.IsFalse(test.GetCell(1, 1).IsAlive); }
public void testRule2() { //test with 2 neighbors GeneticLife test = new GeneticLife(2); ColorCell testCell = test.GetCell(0, 0); testCell.IsAlive = true; testCell.red = Byte.MaxValue / 2; testCell.green = Byte.MaxValue / 2; testCell.blue = Byte.MaxValue / 2; test.GetCell(0, 1).IsAlive = true; test.GetCell(0, 1).red = Byte.MaxValue; test.GetCell(1, 0).IsAlive = true; test.GetCell(1, 0).blue = Byte.MaxValue; test.GetCell(1, 1).IsAlive = false; test.Iterate(); Assert.IsTrue(test.GetCell(0, 0).IsAlive); Assert.AreEqual(Byte.MaxValue / 2, testCell.red); Assert.AreEqual(Byte.MaxValue / 2, testCell.green); Assert.AreEqual(Byte.MaxValue / 2, testCell.blue); //test with 3 neighbors test = new GeneticLife(2); testCell = test.GetCell(0, 0); testCell.IsAlive = true; testCell.red = Byte.MaxValue / 2; testCell.green = Byte.MaxValue / 2; testCell.blue = Byte.MaxValue / 2; test.GetCell(0, 1).IsAlive = true; test.GetCell(0, 1).red = Byte.MaxValue; test.GetCell(1, 0).IsAlive = true; test.GetCell(1, 0).blue = Byte.MaxValue; test.GetCell(1, 1).IsAlive = true; test.Iterate(); Assert.IsTrue(test.GetCell(0, 0).IsAlive); Assert.AreEqual(Byte.MaxValue / 2, testCell.red); Assert.AreEqual(Byte.MaxValue / 2, testCell.green); Assert.AreEqual(Byte.MaxValue / 2, testCell.blue); }
public void testRule3() { //test with 4 neighbors GeneticLife test = new GeneticLife(3); test.GetCell(0, 0).IsAlive = false; test.GetCell(0, 1).IsAlive = true; test.GetCell(0, 2).IsAlive = false; test.GetCell(1, 0).IsAlive = true; test.GetCell(1, 1).IsAlive = true; test.GetCell(1, 2).IsAlive = true; test.GetCell(2, 0).IsAlive = false; test.GetCell(2, 1).IsAlive = true; test.GetCell(2, 2).IsAlive = false; test.Iterate(); Assert.IsFalse(test.GetCell(1, 1).IsAlive); }
public void testRule4() { GeneticLife test = new GeneticLife(2); ColorCell testCell = test.GetCell(0, 0); testCell.IsAlive = false; test.GetCell(0, 1).IsAlive = true; initializeSimpleColors(test.GetCell(0, 1)); test.GetCell(0, 1).IsAlive = true; initializeSimpleColors(test.GetCell(1, 0)); test.GetCell(1, 0).IsAlive = true; initializeSimpleColors(test.GetCell(1, 1)); test.GetCell(1, 1).IsAlive = true; test.Iterate(); testCell = test.GetCell(0, 0); Assert.IsTrue(testCell.IsAlive); Assert.AreEqual(testCell.red, 1); Assert.AreEqual(testCell.green, 2); Assert.AreEqual(testCell.blue, 3); }
private void Window_Loaded(object sender, RoutedEventArgs e) { _lifeMatrices = new ObservableCollection<LifeMatrix>(); LifeMatrix matrix1 = new StandardLife(20); matrix1.Randomize(); _lifeMatrices.Add(matrix1); LifeMatrix matrix2 = new RedBlueLife(20); _lifeMatrices.Add(matrix2); matrix2.Randomize(); LifeMatrix matrix3 = new GeneticLife(20); matrix3.Randomize(); _lifeMatrices.Add(matrix3); activeLifeMatrix = matrix2; typesBox.DataContext = _lifeMatrices; matrix.RowDefinitions.Clear(); for (int rowIndex = 0; rowIndex < activeLifeMatrix.Size; rowIndex++) { RowDefinition rowDef = new RowDefinition(); rowDef.Height = new GridLength((int)(matrix.ActualHeight / activeLifeMatrix.Size)); matrix.RowDefinitions.Add(rowDef); } matrix.ColumnDefinitions.Clear(); for (int columnIndex = 0; columnIndex < activeLifeMatrix.Size; columnIndex++) { ColumnDefinition colDef = null; colDef = new ColumnDefinition(); colDef.Width = new GridLength(matrix.ActualWidth / activeLifeMatrix.Size); matrix.ColumnDefinitions.Add(colDef); } activeLifeMatrix.Iterate(); updateDisplay(); }